Get Started
Examples
Concepts
Resources
Projects
Integrations
copy markdown
Interfaze supports the OpenAI Chat Completion API standard, so you can use it out of the box by easily adding Interfaze's base URL and API key to your code.
npm / yarn
npm install openai
# or
yarn add openaiNote: Interfaze support the OpenAI Chat Completion API standard and not the Response API standard.
OpenAI SDK
import OpenAI from "openai";
const interfaze = new OpenAI({
baseURL: "https://api.interfaze.ai/v1",
apiKey: "<your-api-key>",
});OpenAI SDK
const completion = await interfaze.chat.completions.create({
model: "interfaze-beta",
messages: [
{ role: "user", content: "Write a short story about a robot learning to paint" }
]
});
console.log(completion.choices[0].message.content);Learn more about structured output.
OpenAI SDK
import { z } from "zod";
import { zodResponseFormat } from "openai/helpers/zod";
const weatherSchema = z.object({
city: z.string().describe("The name of the city"),
temperature_celsius: z.number().describe("Current temperature in Celsius"),
condition: z.string().describe("Weather condition, e.g. sunny, rainy, cloudy"),
});
const response = await interfaze.chat.completions.create({
model: "interfaze-beta",
messages: [
{
role: "user",
content: "What is the current weather in Tokyo?",
},
],
response_format: zodResponseFormat(weatherSchema, "weather_schema"),
});
console.log(response.choices[0].message.content);OpenAI SDK
const response = await interfaze.chat.completions.create({
model: "interfaze-beta",
messages: [
{
role: "user",
content: [
{ type: "text", text: "What is in this image?" },
{
type: "image_url",
image_url: {
url: "https://r2public.jigsawstack.com/interfaze/examples/construction.png",
},
},
],
},
],
});
console.log(response.choices[0].message.content);Learn more about streaming.
OpenAI SDK
const stream = await interfaze.chat.completions.create({
model: "interfaze-beta",
messages: [
{ role: "user", content: "Write a short story about a robot learning to paint" }
],
stream: true
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}Learn more about function calling.
OpenAI 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);
}