Interfaze

logo

Beta

pricing

help

docs

blog

sign in

Get Started

Introduction

Examples

Vision

Concepts

Resources

Projects

Integrations

API Reference

Function / Tool Calling

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.

Examples

Interfaze SDK

LangChain SDK

Vercel AI SDK

import type { ChatCompletionMessageParam, ChatCompletionTool } from "interfaze";

// STEP 1. Define a list of callable tools for the model
const tools: ChatCompletionTool[] = [
	{
		type: "function",
		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"],
			},
		},
	},
];

const messages: ChatCompletionMessageParam[] = [
	{
		role: "user",
		content: "Get my horoscope for Taurus",
	},
];

// Step 2: Get tool call from model
const response = await interfaze.chat.completions.create({
	messages,
	tools,
	tool_choice: "auto",
});

// Step 3: Extract tool call and execute function
const assistantMessage = response.choices[0]?.message;
if (assistantMessage) messages.push(assistantMessage); // the assistant turn, carrying any tool_calls

for (const toolCall of assistantMessage?.tool_calls ?? []) {
	if (toolCall.type !== "function") continue;
	const args = JSON.parse(toolCall.function.arguments);

	messages.push({
		role: "tool",
		tool_call_id: toolCall.id,
		content: `Today's horoscope for ${args.sign}: You will have a great day!`,
	});
}

// Step 4: Send the tool results back for the final answer
const finalResponse = await interfaze.chat.completions.create({
	messages,
	tools,
	tool_choice: "auto",
});

console.log(finalResponse.choices[0]?.message.content);

Previous

Streaming

Next

Handling Files

Interfaze

logo

Product

Playground

OCR

Models

Leaderboards

Pricing