Connect the Vercel AI SDK to Gonka Broker
The Vercel AI SDK works with Gonka Broker through its OpenAI-compatible interface, so generateText, streamText, tool calling and the React hooks all work unchanged — you only choose how to point the SDK at Gonka Broker.
Prerequisites
Section titled “Prerequisites”- A Gonka API key (starts with
gnk-prx-). See Create a Gonka API Key. - Node.js 18+.
Use the dedicated provider (recommended)
The @gonkabroker/ai-sdk-provider package is a thin wrapper that points the AI SDK at Gonka Broker for you — no base URL to configure.
npm i ai @gonkabroker/ai-sdk-providerimport { gonkabroker } from "@gonkabroker/ai-sdk-provider";import { generateText } from "ai";
// Reads the API key from the GONKABROKER_API_KEY environment variable.const { text } = await generateText({ model: gonkabroker("MiniMaxAI/MiniMax-M2.7"), prompt: "Hello!",});
console.log(text);Custom setup
The default gonkabroker instance reads the key from GONKABROKER_API_KEY. If you need to supply the key from somewhere else (a secrets manager, a per-request key in a multi-tenant app) or point at a different endpoint, import createGonkaBroker and pass options explicitly:
import { createGonkaBroker } from "@gonkabroker/ai-sdk-provider";
const gonkabroker = createGonkaBroker({ apiKey: process.env.MY_KEY, // any source; defaults to GONKABROKER_API_KEY // baseURL: "https://proxy.gonkabroker.com/v1", // override only if you need a different endpoint // headers: { "X-My-Header": "…" },});Everything else — model ids, streaming, tool calling — works exactly as with the default instance.
Use the OpenAI-compatible provider
Section titled “Use the OpenAI-compatible provider”This works with any setup — no extra package beyond the SDK’s own OpenAI-compatible provider. Point baseURL at your Gonka endpoint and pass your key.
npm i ai @ai-sdk/openai-compatibleimport { createOpenAICompatible } from "@ai-sdk/openai-compatible";import { generateText } from "ai";
const provider = createOpenAICompatible({ name: "Gonka", baseURL: "https://proxy.gonkabroker.com/v1", apiKey: process.env.API_KEY, // your Gonka key (gnk-prx-…)});
const { text } = await generateText({ model: provider("MiniMaxAI/MiniMax-M2.7"), prompt: "Hello!",});
console.log(text);Use any Gonka-supported model id (see Supported Models). Keep the key in an environment variable rather than hardcoding it.
Streaming and tool calling
Section titled “Streaming and tool calling”Both work the same regardless of which provider above you use — swap generateText for streamText to stream tokens, and pass tools for tool calling. The SDK handles the rest through the OpenAI-compatible transport.
Verify
Section titled “Verify”Run a snippet with your key set in the environment. Printed text confirms the connection.
Troubleshooting
Section titled “Troubleshooting”- 401 / unauthorized — wrong or paused API key, or the key environment variable is not set.
- Model not found — the model id must match a supported model.
- Streaming — use
streamTextinstead ofgenerateTextfor token streaming.