Get Started
Examples
Concepts
Resources
Projects
Integrations
copy markdown
Function Calling (also known as Tool Calling) lets Interfaze invoke external tools and APIs giving access to new functionality and data.
Interfaze supports OpenAI-compatible function schemas so you can use all existing MCPs, tools the same way with any AI SDK.
OpenAI SDK
LangChain SDK
Vercel AI SDK
// STEP 1. Define a list of callable tools for the model
const tools = [
{
type: "function" as const,
function: {
name: "get_horoscope",
description: "Get today's horoscope for an astrological sign.",
parameters: {
type: "object",
properties: {
sign: {
type: "string",
description: "An astrological sign like Taurus or Aquarius",
},
},
required: ["sign"],
},
},
},
];
let messages: any[] = [
{
role: "user" as const,
content: "Get my horoscope for Taurus",
},
];
// Step 2: Get tool call from model
const response = await interfaze.chat.completions.create({
model: "interfaze-beta",
messages,
tools,
tool_choice: "auto",
});
// Step 3: Extract tool call and execute function
const assistantMessage = response.choices[0].message;
messages.push({
role: "assistant",
content: "",
tool_calls: response.choices[0].message.tool_calls,
});
if (assistantMessage.tool_calls && assistantMessage.tool_calls.length > 0) {
const toolCall = assistantMessage.tool_calls[0] as any;
const args = JSON.parse(toolCall.function.arguments);
const result = `Today's horoscope for ${args.sign}: You will have a great day!`;
messages.push({
role: "tool" as const,
tool_call_id: toolCall.id,
content: result,
});
const finalResponse = await interfaze.chat.completions.create({
model: "interfaze-beta",
messages,
tools,
tool_choice: "auto",
});
console.log(finalResponse.choices[0].message.content);
}