Interfaze

logo

Beta

pricing

docs

blog

sign in

Get Started

Introduction

Examples

Vision

Concepts

Resources

Projects

Integrations

Vercel AI SDK Integration

copy markdown

Interfaze supports the Chat Completion API standard, so you can use it out of the box with the Vercel AI SDK by pointing it to Interfaze's base URL and API key.

Installation

npm / yarn

npm install ai @ai-sdk/openai
# or
yarn add ai @ai-sdk/openai

Official Documentation

  • Vercel AI SDK Documentation
  • Vercel OpenAI Integration
  • Vercel Stream

Note: Interfaze supports the Chat Completion API standard and not the Response API standard.

Basic Setup

Vercel AI SDK

import { createOpenAI } from "@ai-sdk/openai";

const interfaze = createOpenAI({
  baseURL: "https://api.interfaze.ai/v1",
  apiKey: "<your-api-key>",
});

Examples

Text Generation

Vercel AI SDK

import { generateText } from "ai";

const { text } = await generateText({
  model: interfaze.chat("interfaze-beta"),
  prompt: "Write a short story about a robot learning to paint",
});

console.log(text);

Structured Output

Learn more about structured output.

Vercel AI SDK

import { generateObject } from "ai";
import { z } from "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 { object } = await generateObject({
  model: interfaze.chat("interfaze-beta"),
  schema: weatherSchema,
  prompt: "What is the current weather in Tokyo?",
});

console.log(object);

Image / File Input

Vercel AI SDK

import { generateText } from "ai";

const { text } = await generateText({
  model: interfaze.chat("interfaze-beta"),
  messages: [
    {
      role: "user",
      content: [
        { type: "text", text: "What is in this image?" },
        {
          type: "image",
          image: new URL("https://r2public.jigsawstack.com/interfaze/examples/construction.png"),
        },
      ],
    },
  ],
});

console.log(text);

Streaming

Learn more about streaming.

Vercel AI SDK

import { streamText } from "ai";

const { textStream } = await streamText({
  model: interfaze.chat("interfaze-beta"),
  prompt: "Write a short story about a robot learning to paint",
});

for await (const delta of textStream) {
  process.stdout.write(delta);
}

Function Calling

Learn more about function calling.

Vercel AI SDK

import { generateText, tool, stepCountIs } from "ai";
import { z } from "zod";

const { text } = await generateText({
  model: interfaze.chat("interfaze-beta"),
  prompt: "What's the weather like in San Francisco?",
  tools: {
    weather: tool({
      description: "Get the weather in a location",
      inputSchema: z.object({
        location: z.string().describe("The location to get the weather for"),
      }),
      execute: async ({ location }) => ({
        location,
        temperature: 72 + Math.floor(Math.random() * 21) - 10,
      }),
    }),
  },
  stopWhen: stepCountIs(5),
  toolChoice: "auto",
});

console.log(text);