Vercel AI SDK
The Vercel AI SDK is the standard way to call models from TypeScript, React and Next.js. Use the openai-compatible provider, not the OpenAI one.
Code
Setup guide: this config comes from the Vercel AI SDK's official documentation and has not been run end to end against the gateway. Corrections to support@hyphen-solution.com.
The provider
Code
Do not reach for @ai-sdk/openai first
@ai-sdk/openai is built for OpenAI's own service, and since AI SDK 5 its
default openai('model-id') call targets the Responses API. Hyphen serves
Chat Completions at /v1/chat/completions, so the default call shape can miss.
If you must use that package, .chat() is mandatory:
Code
createOpenAICompatible avoids the whole question. Use it.
Generate text
Code
It is maxOutputTokens, not maxTokens
The rename landed in AI SDK 5 and stuck. Snippets older than that use
maxTokens, which is silently ignored on current versions, so you get the
default budget and occasionally an empty string.
Stream text
Code
Note streamText is not awaited. It returns immediately and you consume the
stream.
Tool calling
Code
Two names that changed and will bite anyone copying older snippets:
inputSchema, notparameters, ontool().isStepCount(n)in AI SDK 7. It wasstepCountIs(n)in versions 5 and 6.
stopWhen is what turns a single call into an agent loop. Without it the SDK
stops after the first tool call instead of feeding the result back.
Structured output
generateObject asks the provider for a JSON schema by default, which the
M-series do not support. Pass output: 'tool', or use tool calling directly.
Code
If mode: "tool" is rejected by your version, fall back to the explicit
generateText plus tool() pattern above, which is the stable one. See
Structured JSON output.
In a Next.js route handler
Code
Keep HYPHEN_API_KEY server-side. Never expose it to the browser, and never
prefix it with NEXT_PUBLIC_.
Gotchas
maxOutputTokens, notmaxTokens. 2000 for chat, 4000 for tools. See Choosing a model.inputSchema, notparameters.isStepCount, notstepCountIs, on AI SDK 7.@ai-sdk/openaidefaults to the Responses API. UsecreateOpenAICompatible, or.chat().- No embedding models.
embedandembedManyneed another provider. 429means the monthly budget is spent. See Handling the 429 cap.
Related
- OpenAI-compatible provider docs
- Tool calling docs
- Mastra: agents and workflows on top of this.
- OpenAI Node SDK: no framework at all.