Guides
Tutorials
AI Currency Converter

AI Currency Converter

This guide will help you build an AI Currency Converter that fetches real-time INR to USD exchange rates. The system processes user input, retrieves live exchange rate data, and provides an accurate conversion. By implementing this tool in Lamatic, you'll learn how to integrate AI with external APIs for seamless and up-to-date currency conversion.

What You'll Build

A simple API that processes user input, fetches real-time INR to USD exchange rates, and provides accurate currency conversion. This API ensures seamless and up-to-date exchange rate retrieval, enabling efficient and precise currency conversion for various financial applications.

Getting Started

1. Tool Creation

  1. Sign up at Lamatic.ai (opens in a new tab) and log in.
  2. Navigate to Models > Tools section.
  3. Click on Create a New Tool.

Define Tool Details

  1. Add Tool name: convertINRtoUSD flow.png
  2. Add Description: Convert amount from Indian Rupees (INR) to US Dollars (USD)

Configure Parameters

  1. Add Parameter name 'amount' and define the datatype as a string
This is a JSON Schema object that describes the parameters that the tool accepts and are the ones that will be passed to the model.
{
"amount": {
"type": "number",
"required": true,
"description": "Amount in INR to convert"}
}
  1. In the Code section
const response = await fetch('https://api.exchangerate-api.com/v4/latest/INR');
const data = await response.json();

const usdRate = data.rates.USD;
const result = input.amount * usdRate;

console.log('result', result)

output = result
  • 'input' and 'output' are reserved variables. Avoid overwriting them.

  • To access variables defined in the schema, use 'input.variableName'.

  • Assign the return value to 'output' pass data from the function.

  1. You can test the JavaScript Code by providing parameters and clicking on the Test button. flow.png
  2. Finally, Click on the Create Button.

2. Project Setup

  1. Navigate to the dashboard and click Create New Flow.
  2. You'll see different sections like Flows, Data, and Models. flow.png

3. Creating a New Flow

  1. Navigate to Flows, select New Flow, and choose Create from Scratch as your starting point.
  2. Click "New Flow". Flow selection
  3. Select "Create from Scratch". Flow Start

4. Setting Up Your API

  1. Click "Choose a Trigger".
  2. Select "API Request" under the interface options. Flow API
  3. Configure your API:
    • Add your Input Schema
    • Set amount as parameter in input schema
    • Set response type to "Real-time" Flow API Schema

5. Adding AI Text Generation

  1. Click the + icon to add a new node.
  2. Choose "Text LLM". Node Text Gen
  3. Configure the AI model:
    • Select your "OpenAI" credentials
    • Choose "gpt-4o-mini" as your Model
  4. Set up your prompt:

Convert {{triggerNode_1.output.Amount}} INR to USD.
Give the output in decimals.
  • You can add variables using the "Add Variable" button Node Text Gen Config
  1. Navigate to Additional Properties.
  2. Select the desired tools. You can add multiple tools as needed.

6. Configuring the reponse

  1. Click the API response node. Flow Deploy
  2. Add Output Variables by clicking the + icon.
  3. Select variable from your Code Node.

7. Test the flow

  1. Click on 'API Request' trigger node.
  2. Click on Configure test. Flow Deploy
  3. Fill sample value in 'Amount' and click on test.

8. Deployment

  1. Click the Deploy button. Flow Deploy
  2. Your API is now ready to be integrated into Node.js or Python applications.
  3. Your flow will run on Lamatic's global edge network for fast, scalable performance.

9. What's Next?

  • Experiment with different prompts
  • Try other AI models
  • Add more processing steps to your flow
  • Integrate the API into your applications

10. Tips

  • Save your tests for reuse across different scenarios
  • Use consistent JSON structures for better maintainability
  • Test thoroughly before deployment

Now you have a working AI-powered API! You can expand on this foundation to build more complex applications using Lamatic.ai's features.

Was this page useful?

Questions? We're here to help

Subscribe to updates