Vercel AI SDK
The AI SDK’s OpenAI and Anthropic providers take a custom base URL, key and headers, so you create one provider instance per OpenPike format and use OpenPike model names.
@ai-sdk/openai |
@ai-sdk/anthropic |
|
|---|---|---|
| Create | createOpenAI({...}) |
createAnthropic({...}) |
| Base URL | baseURL: "https://api.openpike.dev/v1" |
baseURL: "https://api.openpike.dev/v1" |
| Key | apiKey: a virtual key |
apiKey: a virtual key |
| Tags | headers: { "x-openpike-tags": ... } |
headers: { "x-openpike-tags": ... } |
| Models | provider.chat("deepseek/deepseek-flash") |
provider("anthropic/claude-haiku-5-5") |
Note the Anthropic provider’s base URL includes /v1, unlike Anthropic’s own SDK: the AI SDK’s default is https://api.anthropic.com/v1.
Install
Section titled “Install”npm install ai @ai-sdk/openai @ai-sdk/anthropicExample
Section titled “Example”import { createAnthropic } from "@ai-sdk/anthropic";import { createOpenAI } from "@ai-sdk/openai";import { generateText, streamText } from "ai";
const headers = { "x-openpike-tags": "agent=docs-example,env=dev" };
// OpenAI format: OpenPike serves Chat Completions, so use openpike.chat(...), not openpike(...).const openpike = createOpenAI({ baseURL: "https://api.openpike.dev/v1", apiKey: process.env.OPENPIKE_API_KEY, headers,});
const { text } = await generateText({ model: openpike.chat("deepseek/deepseek-flash"), prompt: "Name one river in Europe.",});console.log(text);
// Anthropic format, for Claude models.const openpikeClaude = createAnthropic({ baseURL: "https://api.openpike.dev/v1", apiKey: process.env.OPENPIKE_API_KEY, headers,});
const result = streamText({ model: openpikeClaude("anthropic/claude-haiku-5-5"), prompt: "Count from one to five.",});for await (const delta of result.textStream) process.stdout.write(delta);process.stdout.write("\n");Use .chat() with the OpenAI provider
Section titled “Use .chat() with the OpenAI provider”The OpenAI provider’s default, openai("model"), calls OpenAI’s Responses API. OpenPike serves that endpoint only for providers that serve it themselves (OpenAI, xAI, Groq and OpenRouter), because it does not translate between formats, so openai("openai/gpt-5.4-mini") works but openai("deepseek/deepseek-flash") does not. Use .chat("model"), which the AI SDK’s docs recommend when a base URL only supports Chat Completions, to reach every provider.
A run ID per task
Section titled “A run ID per task”To cap one agent run with a run budget, pass the run in headers on the call, for example generateText({ model, prompt, headers: { "x-openpike-run": task.id } }), or create the provider per task with it in headers. Keep the default retries: OpenPike refuses a blocked request before any provider call, so they cost nothing. On 429 run_limit_exceeded, stop the task and tell the user instead of retrying.
What works
Section titled “What works”generateText, streamText, generateObject, streamObject and tool calls, with any model on the matching endpoint. Embeddings and images do not work through OpenPike.
Example
Section titled “Example”A runnable copy of this setup, with a .env.example, is in the OpenPike examples repo.