Connect Vercel AI SDK to byesu API
Use the Vercel AI SDK (ai in TypeScript / Next.js / Node.js) with byesu to stream text, extract Zod-validated structured objects, and run tool-calling agents across Claude, GPT, Gemini, DeepSeek, and Grok using a single pay-as-you-go API key.
Quick configuration
@ai-sdk/openaibaseURL:https://byesu.com/v1(calls any vendor model with one provider instance)@ai-sdk/anthropicbaseURL:https://byesu.com/v1(include/v1—@ai-sdk/anthropicappends/messages, unlike Claude Code CLI!)- Environment variable:
BYESU_API_KEY=sk-...(created in the defaultautogroup) - Recommended models:
claude-sonnet-5-5,claude-opus-5-5,gpt-6.2-sol,deepseek-v4-pro,gemini-4-argon
Prerequisites
- Create an
sk-...token in the byesu Console under the defaultautogroup (see Choosing a Group). - Install the core AI SDK, provider packages, and Zod:
npm install ai @ai-sdk/openai @ai-sdk/anthropic zod- Add your key to
.env.local(Next.js) or export it in your shell:
BYESU_API_KEY="sk-your-byesu-token"Option 1: @ai-sdk/openai (Multi-Vendor streamText & generateObject)
Point createOpenAI at https://byesu.com/v1 to call Claude, GPT, DeepSeek, Gemini, and Grok models without creator/ model slug prefixes.
Use byesu.chat(modelId) when routing non-OpenAI models (claude-sonnet-5-5, deepseek-v4-pro, gemini-4-argon) through /v1/chat/completions, or byesu('gpt-6.2-sol') when targeting OpenAI /v1/responses in AI SDK v5+:
import { createOpenAI } from '@ai-sdk/openai';
import { streamText, generateObject } from 'ai';
import { z } from 'zod';
const byesu = createOpenAI({
baseURL: 'https://byesu.com/v1',
apiKey: process.env.BYESU_API_KEY,
});
// 1. Stream tokens from Claude, GPT, DeepSeek, or Gemini
export async function streamReleaseNotes(diff: string) {
const result = streamText({
model: byesu.chat('claude-sonnet-5-5'), // swap to 'gpt-6.2-sol', 'deepseek-v4-pro', 'gemini-4-argon'
prompt: `Write concise engineering release notes for this diff:\n\n${diff}`,
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
}
// 2. Type-safe structured extraction with Zod
export async function auditPullRequest(diff: string) {
const { object } = await generateObject({
model: byesu.chat('gpt-6.2-sol'),
schema: z.object({
riskLevel: z.enum(['low', 'medium', 'high']),
summary: z.string(),
blockingIssues: z.array(z.string()),
}),
prompt: `Audit this pull request diff for production risks:\n\n${diff}`,
});
return object;
}In a Next.js App Router endpoint (app/api/chat/route.ts), raise maxDuration so deep-reasoning models (gpt-6.2-sol, claude-opus-5-5, deepseek-v4-pro) never get cut off mid-thought:
import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';
export const maxDuration = 120;
const byesu = createOpenAI({
baseURL: 'https://byesu.com/v1',
apiKey: process.env.BYESU_API_KEY,
});
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: byesu.chat('claude-sonnet-5-5'),
messages,
});
return result.toDataStreamResponse();
}Option 2: @ai-sdk/anthropic (Native /v1/messages & 0.1x Prompt Caching)
When building Claude-first agents with large system instructions, repository context, or native thinking blocks, use @ai-sdk/anthropic:
Critical baseURL rule for @ai-sdk/anthropic
@ai-sdk/anthropic's default baseURL is https://api.anthropic.com/v1 because the package only appends /messages (not /v1/messages). Unlike Claude Code CLI or Python anthropic.Anthropic — which take https://byesu.com — @ai-sdk/anthropic expects https://byesu.com/v1. Omitting /v1 sends requests to https://byesu.com/messages and returns 404.
byesu forwards Anthropic cache_control breakpoints unchanged, so repeated prefixes (~1,024+ tokens) bill cache reads as low as 0.1x (see Prompt Caching):
import { createAnthropic } from '@ai-sdk/anthropic';
import { streamText } from 'ai';
const anthropic = createAnthropic({
baseURL: 'https://byesu.com/v1', // @ai-sdk/anthropic appends /messages -> /v1/messages
apiKey: process.env.BYESU_API_KEY,
});
export async function askWithCachedContext(repoSpec: string, userQuestion: string) {
const result = streamText({
model: anthropic('claude-opus-5-5'),
messages: [
{
role: 'system',
content: repoSpec, // Static 1,024+ token prefix kept byte-identical across turns
providerOptions: {
anthropic: { cacheControl: { type: 'ephemeral' } },
},
},
{
role: 'user',
content: userQuestion,
},
],
});
const text = await result.text;
const meta = await result.providerMetadata;
console.log('Anthropic cache usage:', meta?.anthropic);
// { cacheCreationInputTokens: ..., cacheReadInputTokens: ... }
return text;
}Production Engineering Notes
- Omit legacy sampling overrides on Claude 5.5 & GPT-6.2: Anthropic API version
2026-10-21rejectstemperature,topP, andtopKwith HTTP400, and GPT-6.2 reasoning models also reject fixed sampling overrides. LeavetemperatureandtopPunset instreamText/generateObject(Claude 400 sampling fix). - Dedicated token groups: The default
autogroup covers Claude, GPT, Gemini, DeepSeek, and Grok. To callglm-5.3,kimi-k3, or image generation models (gpt-image-2,gemini-3.1-flash-image-ultra), create dedicated tokens in theGlm,Kimi, ormediagroup. - Pay-as-you-go billing: Text and code usage is metered per token with no monthly subscription; check live per-model rates in the byesu Console after sign-in.
Troubleshooting & Benchmarks
404 Not Foundwith@ai-sdk/anthropic: confirmbaseURLishttps://byesu.com/v1(with/v1), and verify the exact model ID in the console (Claude 404 fix, no available channel).401 Unauthorized/invalid_api_key: verifyprocess.env.BYESU_API_KEYis loaded in your server runtime (OpenAI 401 fix, Claude 401 fix).- Dropped streams or serverless timeouts: set
export const maxDuration = 120(or higher) on Next.js routes (Anthropic timeout, streaming connection dropped). 429& live latency data: see OpenAI 429 rate limit vs quota and weekly production benchmarks.