Docs

Vercel AI SDK

Use Odin v1 from the Vercel AI SDK with the OpenAI-compatible provider.

The AI SDK connects through its OpenAI-compatible provider, which uses Chat Completions. See Not supported for what the OpenAI-compatible API doesn't accept. File attachments in AI SDK messages are rejected with 400 unsupported_content.

Don't use createOpenAI for InterOdin. In AI SDK 5 and later it defaults to the Responses API. Use createOpenAICompatible, as shown below.

Install

npm install ai @ai-sdk/openai-compatible zod

Configure the provider

import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { generateText } from 'ai'

export const interodin = createOpenAICompatible({
  name: 'interodin',
  baseURL: 'https://api.interodin.com/v1',
  apiKey: process.env.INTERODIN_API_KEY,
  includeUsage: true,
})

const { text, usage } = await generateText({
  model: interodin('odin-v1'),
  prompt: 'Name three Norse gods.',
})
console.log(text, usage)

includeUsage: true makes streamed calls report token usage.

Streaming

import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { streamText } from 'ai'

const interodin = createOpenAICompatible({
  name: 'interodin',
  baseURL: 'https://api.interodin.com/v1',
  apiKey: process.env.INTERODIN_API_KEY,
  includeUsage: true,
})

const result = streamText({
  model: interodin('odin-v1'),
  system: 'You are a concise assistant.',
  prompt: 'Write a haiku about Odin.',
})

for await (const delta of result.textStream) process.stdout.write(delta)
console.log('\n', await result.usage)

In a Next.js route handler, return result.toUIMessageStreamResponse() to stream into the AI SDK's useChat hook.

Tools

import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { generateText, stepCountIs, tool } from 'ai'
import { z } from 'zod'

const interodin = createOpenAICompatible({
  name: 'interodin',
  baseURL: 'https://api.interodin.com/v1',
  apiKey: process.env.INTERODIN_API_KEY,
})

const { text } = await generateText({
  model: interodin('odin-v1'),
  prompt: 'What is the weather in Cluj?',
  tools: {
    getWeather: tool({
      description: 'Get the current weather for a city',
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, celsius: 14 }),
    }),
  },
  stopWhen: stepCountIs(3),
})
console.log(text)

Using the Anthropic provider instead

If your app already uses @ai-sdk/anthropic, point it at the Messages endpoint. This provider expects the base URL with /v1:

import { createAnthropic } from '@ai-sdk/anthropic'
import { generateText } from 'ai'

const anthropic = createAnthropic({
  baseURL: 'https://api.interodin.com/v1',
  apiKey: process.env.INTERODIN_API_KEY,
})

const { text } = await generateText({ model: anthropic('odin-v1'), prompt: 'Name three Norse gods.' })
console.log(text)

On this page