Skip to main content
Version: 2.0.0

Configure API Tool

The API Tool in Ejento AI is designed to enhance the assistant’s ability to fetch real-time information from external APIs based on user queries. Instead of hardcoding API URLs, the assistant dynamically constructs the correct endpoint URL using predefined system instructions and retrieves relevant data.

How It Works

  1. User Query Analysis: The assistant detects whether a user query requires fetching external data.

  2. URL Construction: The assistant constructs the API request URL based on the query and available parameters.

  3. Fetching Data: The assistant queries the API and retrieves relevant information.

  4. Response Optimization: The assistant structures and presents the response in a user-friendly manner.

How to Write a Prompt for API Requests

When constructing system prompts for API requests, certain elements must always be included, while others are optional and can be added based on endpoint requirements.

Must-Have Elements:

These elements are mandatory for ensuring proper API integration:

  1. API Name and Version: Clearly specify which API and version the assistant should use to ensure compatibility.

These elements enhance API calls but are not strictly necessary for every request:

  1. Base URL: If a static base URL is used for multiple API calls, including it in the prompt ensures consistency.

  2. Input for Headers: If the API requires authentication or special headers, the prompt should define how they are structured.

  3. API-Specific Parameters to Construct URL: If certain parameters are crucial for retrieving relevant data, they should be included in the prompt dynamically, depending on user input.

By structuring system prompts this way, API calls remain efficient, flexible, and aligned with endpoint requirements.

Example: Clinical Trials API

For Clinical Trials API integration, the system prompt instructs the assistant on how to structure URLs and fetch data. Here is a simplified excerpt from the system prompt:

"You are using the Clinical Trials open API spec version 2.0.3 with the base URL https://clinicaltrials.gov/api/v2. Your task is to generate request URLs based on user queries and fetch the required data. Always limit results to 10 unless specified otherwise. Use relevant parameters such as query.cond for conditions, query.locn for locations, and filter.overallStatus for recruitment status."

This excerpt ensures that:

  • The assistant knows the correct API version and base URL.

  • It applies proper query parameters to retrieve only necessary data.


Configuring the API Tool

1. Go to the Tools section from the sidebar

Step 1 screenshot

2. Click on Add Tool

Step 2 screenshot

3. Type a name for your tool in the configure tool drawer

Step 3 screenshot

4. Select API from the Tool Type dropdown

Step 4 screenshot

5. Add the description for the tool here

Step 5 screenshot

6. Select "Other" Under API Selection

Step 6 screenshot

7. Add the system prompt here

Step 7 screenshot

8. Click on Create tool

Step 8 screenshot

9. The new API Tool has been created.

Next, Lets also add Authorization information for the Tool to be able to send authorized requests to the API

Step 9 screenshot

10. Click on Authorization in the Configure Tool Drawer

Step 10 screenshot

11. Add the Authorizatio Key Here i.e "Ocp-Apim-Subscription-Key"

Step 11 screenshot

12. Add the value for the key in authorization header

Step 12 screenshot

13. Click on Update tool

Step 13 screenshot

Enabling the API Tool for Assistant

1. Navigate to the assistants section from the sidebar

Step 1 screenshot

2. Search for your assistant from the list

Step 2 screenshot

3. Make sure "Advanced Reasoning" is turned on in the assistant drawer

Step 3 screenshot

4. Click on the three dots on your assistant from the list

Step 4 screenshot

5. Go to Tools from the dropdown

Step 5 screenshot

6. Search for the newly created tool here

Step 6 screenshot

7. Enable the tool for this assistant

Step 7 screenshot

8. Navigate back to your assistant and click on it to open the assistant drawer

Step 8 screenshot

9. Notice the API Tool being enabled for the assistant here

Step 9 screenshot

Best Practices for Writing System Prompts

  1. Define Clear Query Parameters: Specify which API parameters the assistant should use to refine responses efficiently.

  2. Limit Data Fetching: Implement constraints like pageSize=10 to prevent excessive data retrieval.

  3. Specify Essential Fields in the Prompt: Ensure that system prompts instruct the assistant to request only the necessary fields from the API, improving performance.

  4. Use Context-Sensitive Instructions: Adapt system instructions based on API capabilities, ensuring appropriate query modifications.

  5. Ensure API Compatibility: Keep track of API version changes and update system instructions accordingly.