Quick Start - TypeScript
A quick example of using Interlify in TypeScript.
Register
You can register for free by going to the Interlify register page. You can skip this step if you already have an account for Interlify.
Login to the page, then you will be redirected to the dashboard.
Create Tools
In Interlify, tools are function definitions. A tool represents a single interaction (API call) with your internal service. Each tool represents a single API call.
Interlify's cutting‐edge AI can understand your API specification (as OpenAPI-style) and generate the tools for you. You just need to import the OpenAPI specifications in yml or json format.
To create tools, follow these steps:
-
On the Dashboard page, go to the Tools section.
-
In the Create Tools section, click the "Select File" button to import your OpenAPI file, then click the "Generate Tools", and Your tools will be ready in seconds!
You may need to refresh the page to see the created tools.
You can check each tool's details by clicking the tool. You can update the tool details or delete the tool.
Create a Project
A project contains a group of tools that can be fetched by the client and provided to Large Language Models.
To create a project, follow these steps:
-
On the Dashboard page, go to the Projects section.
-
Click the "New Project +" button to create a new project. Enter a project name, select the tools you want to group under this project. Then click the "Save" button.
The project setup is done!
Create an API Key
An API key is associated with your account. It is required to use Interlify in your code and is used to verify your account.
To create an API key, follow these steps:
-
In the Dashbaord page, go to the API Keys section.
-
In the "Generate new API Key section", enter you API Key Name, then click the "Create +" button. An API key will be generated for your account.
An API key can be used across multiple projects.
Add Interlify to your code
Install Interlify
Install the Interlify client in your project:
npm install interlify
Then use the Interlify client with a few lines of code:
import { OpenAI } from "openai";
import { Interlify } from "Interlify";
const client = new OpenAI();
const MODEL = YOUR_LLM_MODEL;
// Your steps of getting ACCESS_TOKEN_FOR_YOUR_TOOLS
// ...
// Initilize the client
const interlify = new Interlify({
apiKey: YOUR_INTERLIFY_API_KEY,
projectId: YOUR_INTERLIFY_PROJECT_ID,
authHeaders: [
{ Authorization: ACCESS_TOKEN_FOR_YOUR_TOOLS }
]
});
const chat = async () => {
// prepare tools
const tools = await interlify.tools();
// porivde tools to the LLM
const response = await client.chat.completions.create({
model: MODEL,
messages: message_list as any,
//@ts-ignore
tools: tools,
tool_choice: 'auto',
});
const responseMessage = response.choices[0].message;
const toolCalls = responseMessage.tool_calls;
if (toolCalls) {
message_list.push(responseMessage);
for (const toolCall of toolCalls) {
// call the tool using interlify
const functionResponse = await interlify.callTool(toolCall.function);
message_list.push({
// @ts-ignore
tool_call_id: toolCall.id,
role: 'tool',
name: toolCall.function.name,
content: JSON.stringify(functionResponse.data),
});
}
const secondResponse = await client.chat.completions.create({
model: MODEL,
messages: message_list as any,
});
return secondResponse.choices[0].message.content;
}
return responseMessage.content;
}
const message = await chat();
console.log(message)
Explanation
In the above code, Interlify did the following things:
- Instantiate the client
const interlify = new Interlify({
apiKey: YOUR_INTERLIFY_API_KEY,
projectId: YOUR_INTERLIFY_PROJECT_ID,
authHeaders: [
{ Authorization: ACCESS_TOKEN_FOR_YOUR_TOOLS }
]
});
The ACCESS_TOKEN_FOR_YOUR_TOOLS
is the entire string value of the authorization header. The string will be used by your service to authorize LLM to access protected resources.
For the Bearer token format: Authorization: Bearer <YOUR_TOKEN>
The ACCESS_TOKEN_FOR_YOUR_TOOLS
should be "Bearer <YOUR_TOKEN>"
.
For the Basic token format: Authorization: Basic <base64(username:password)>
The ACCESS_TOKEN_FOR_YOUR_TOOLS
should be "Basic <YOUR_ENCODED_CREDENTIALS>"
.
If your API does not require a token, you can remove the authHeaders
, so the code would be:
const interlify = new Interlify({
apiKey: YOUR_INTERLIFY_API_KEY,
projectId: YOUR_INTERLIFY_PROJECT_ID
});
- Prepare the tools
const tools = await interlify.tools();
- Provide tools to LLM
const response = await client.chat.completions.create({
model: MODEL,
messages: message_list as any,
//@ts-ignore
tools: tools,
tool_choice: 'auto',
});
- Call the tool
const functionResponse = await interlify.callTool(toolCall.function);
That's it!
GL & HF!
Currently, Interlify works for OpenAI compatible client/models, such as OpenAI, DeepSeek, Groq Client, etc.
If you have any questions, ideas, requests, or feedback, we highly recommend visiting our Build Together page to share them with us. We are eager to hear from you!