The AI SDK reaches Inferbase through its OpenAI-compatible provider. No Inferbase package is needed: createOpenAICompatible with the Inferbase base URL is the whole setup. Every example on this page was run against https://api.inferbase.ai/v1 with ai 7.0.185 and @ai-sdk/openai-compatible 3.0.97.
Install
npm install ai @ai-sdk/openai-compatible zodCreate a key at Gateway › API keys and set it as INFERBASE_API_KEY.
Create the provider
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
export const inferbase = createOpenAICompatible({
name: 'inferbase',
baseURL: 'https://api.inferbase.ai/v1',
apiKey: process.env.INFERBASE_API_KEY,
includeUsage: true,
supportsStructuredOutputs: true,
})includeUsage asks for token usage at the end of a stream. supportsStructuredOutputs sends a JSON schema as response_format: json_schema, which Inferbase forwards to the serving model.
Choose a model
| Model id | What it does |
|---|---|
auto | Inferbase classifies each request and picks the model, on the objective of the key's routing policy. |
A catalog id, such as deepseek-v4-flash | Pins that model. GET /v1/models lists the ids the key can use, with auto first. |
config:<slug> | Runs the request with a configuration: its routing policy, guardrails and request settings. |
Generate and stream text
import { generateText, streamText } from 'ai'
import { inferbase } from './inferbase'
const { text } = await generateText({
model: inferbase('auto'),
prompt: 'Say hello in one short sentence.',
})
const result = streamText({
model: inferbase('auto'),
prompt: 'Count from 1 to 5, comma separated.',
})
for await (const delta of result.textStream) process.stdout.write(delta)The response's model names the model that served the request, never auto.
Tools
Tool calling and multi-step tool use work on auto and on any model that supports tools. A request that carries tools is routed only to models that support them.
import { generateText, tool, stepCountIs } from 'ai'
import { z } from 'zod'
const { text } = await generateText({
model: inferbase('auto'),
tools: {
weather: tool({
description: 'Current temperature in a city, in Celsius',
inputSchema: z.object({ city: z.string() }),
execute: async ({ city }) => ({ city, celsius: 21 }),
}),
},
stopWhen: stepCountIs(3),
prompt: 'Use the weather tool to get the temperature in Paris, then answer in one sentence.',
})Structured output
import { generateText, Output } from 'ai'
import { z } from 'zod'
const { output } = await generateText({
model: inferbase('auto'),
output: Output.object({ schema: z.object({ city: z.string(), country: z.string() }) }),
prompt: 'Name the capital of Japan and its country.',
})Reasoning
A reasoning model's thinking arrives as reasoning parts, and its tokens are counted in usage.outputTokenDetails.reasoningTokens. reasoningEffort is read as a thinking switch: low and above ask for thinking where the model has it, none and minimal suppress it.
const { text, reasoningText } = await generateText({
model: inferbase('deepseek-v4-flash'),
prompt: 'What is 17 * 23? Answer with the number.',
providerOptions: { inferbase: { reasoningEffort: 'low' } },
})On auto, Inferbase decides whether the chosen model thinks; see Chat completions.
Embeddings
import { embed } from 'ai'
const { embedding } = await embed({
model: inferbase.embeddingModel('auto'),
value: 'routing a request to the right model',
})auto on embeddings takes the first embedding model in the routing policy's pool. Name a model to keep vectors comparable across an index; see Embeddings and rerank.
Read the routing decision
A non-streamed response carries the decision as a routing field, and a stream sends it as the first event. A metadata extractor puts it on providerMetadata:
import type { MetadataExtractor } from '@ai-sdk/openai-compatible'
const routingExtractor: MetadataExtractor = {
extractMetadata: async ({ parsedBody }) => ({
inferbase: { routing: parsedBody.routing ?? null },
}),
createStreamExtractor: () => {
let routing: unknown = null
return {
processChunk: (chunk) => {
if (chunk?.object === 'routing') routing = chunk
},
buildMetadata: () => ({ inferbase: { routing } }),
}
},
}
const inferbase = createOpenAICompatible({
name: 'inferbase',
baseURL: 'https://api.inferbase.ai/v1',
apiKey: process.env.INFERBASE_API_KEY,
includeUsage: true,
metadataExtractor: routingExtractor,
})
const { providerMetadata } = await generateText({ model: inferbase('auto'), prompt: 'Hello' })
console.log(providerMetadata?.inferbase?.routing)The decision names the task, the chosen model and the reasons. The response id reads the full record back from Routing decisions.
Last updated December 1, 2026.