Set it up
You need a Nerdly key (it starts with sk-nerd-): sign in on the API page to get one, and add credit in Billing.
- Install the SDK and the OpenAI-compatible provider; zod is for the tool example.shell1
pnpm add ai @ai-sdk/openai-compatible zod - Put the key in an environment variable.shell1
export NERDLY_API_KEY="sk-nerd-…" - Create the provider in provider.ts; includeUsage puts token counts on streamed answers too.ts1
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';23export const nerdly = createOpenAICompatible({4name: 'nerdly',5baseURL: 'https://api.nerdly.us/v1',6apiKey: process.env.NERDLY_API_KEY,7includeUsage: true,8}); - Call generateText; usage carries the tokens the request was billed on.ts1
import { generateText } from 'ai';2import { nerdly } from './provider';34const { text, usage, finishReason } = await generateText({5model: nerdly('deepseek-v4-flash-0731'),6prompt: 'Write a Python function that checks if a string is a palindrome.',7});89console.log(text);10console.log(usage.inputTokens, usage.outputTokens, usage.totalTokens, finishReason); - Or stream it; result.usage resolves when the stream ends.ts1
import { streamText } from 'ai';2import { nerdly } from './provider';34const result = streamText({5model: nerdly('deepseek-v4-flash-0731'),6prompt: 'Write a Python function that checks if a string is a palindrome.',7});89for await (const piece of result.textStream) process.stdout.write(piece);1011const usage = await result.usage;12console.log(usage.inputTokens, usage.outputTokens); - In a Next.js route handler, return result.toTextStreamResponse() for plain text, or result.toUIMessageStreamResponse() for the useChat hook.ts1
// app/api/chat/route.ts2import { streamText } from 'ai';3import { nerdly } from '@/lib/provider';45export async function POST(req: Request) {6const { prompt } = (await req.json()) as { prompt: string };7const result = streamText({8model: nerdly('deepseek-v4-flash-0731'),9prompt,10});11return result.toTextStreamResponse();12} - Tool calls: tool() takes a description, an inputSchema and an execute function, and stopWhen: isStepCount(5) lets the SDK run up to five steps.ts1
import { generateText, isStepCount, tool } from 'ai';2import { z } from 'zod';3import { nerdly } from './provider';45const { text, steps } = await generateText({6model: nerdly('deepseek-v4-flash-0731'),7tools: {8weather: tool({9description: 'Get the weather in a location',10inputSchema: z.object({11location: z.string().describe('The location to get the weather for'),12}),13execute: async ({ location }) => ({ location, temperature: 72 }),14}),15},16stopWhen: isStepCount(5),17prompt: 'What is the weather in San Francisco?',18});1920const toolCalls = steps.flatMap((step) => step.toolCalls);21console.log(toolCalls.length, text);
The examples use deepseek-v4-flash-0731, the most used coding model on Nerdly today; put any id from the models page in its place.
Which model to pick
- Qwen4 35B A3B Uncensored (
qwen4-35b-a3b-uncensored): $0.48 in, $2.40 out per million tokens, 1M context, about 1.4¢ an agent step. - Ergo Uncensored (
ergo-uncensored): $4.40 in, $13.32 out per million tokens, 1M context, about $0.11 an agent step. - GLM-5.3 Abliterated (
glm-5.3-abliterated): $2.33 in, $4.66 out per million tokens, 131K context, about 5.6¢ an agent step. - DeepSeek V4 Flash 0731 (
deepseek-v4-flash-0731): $0.08 in, $0.12 out per million tokens, 1M context, about 0.19¢ an agent step. - DeepSeek V4.1 Flash 1017 (
deepseek-v4.1-flash-1017): $0.25 in, $1.20 out per million tokens, 1M context, about 0.74¢ an agent step. - Claude Opus 5.5 (
claude-opus-5-5): $2.80 in, $10 out per million tokens, 1M context, about 7.6¢ an agent step.
What a session costs
50 chat turns (about 2,000 tokens in and 500 out each) on DeepSeek V4 Flash 0731 cost about 1.1¢, paid from your balance. Every request Vercel AI SDK sends is priced by its tokens at the model’s rate; a cheaper model costs less, a larger one more.
Things that trip people up
- baseURL ends in /v1 and nothing after it; the SDK adds /chat/completions.
- Without includeUsage on the provider, streamed answers carry no token counts.
- @ai-sdk/openai-compatible sends Chat Completions; with the @ai-sdk/openai package, openai(id) uses the Responses API and openai.chat(id) stays on Chat Completions.
- Tool calls need a model trained for them; pick one whose /models row says it takes tools.
Vercel AI SDK’s own documentation: ai-sdk.dev/providers/openai-compatible-providers.
More guides
Questions.
Something else? Email hello@nerdly.us
Run Vercel AI SDK on any model.
Get a key, add credit from $10, and point the tool at Nerdly.
Get a key