Vercel AI SDK

Route the Vercel AI SDK through ToyGate as a custom provider.

Integrations

The Vercel AI SDK ships a configurable provider. Override baseURL to your gateway and pass a gw_ key. generateText and streamText work through this provider; structured-output helpers are not currently supported.

Config

ts
import { createOpenAI as createStandardClient } from "@ai-sdk/openai";// Or import from any other standard-compatible SDKexport const gateway = createStandardClient({apiKey: process.env.GATEWAY_KEY,baseURL: "https://api.toygate.store/v1",});

generateText

import { generateText } from "ai";

const { text } = await generateText({
  model: gateway("gpt-5.5"),
  prompt: "Say hi",
});

console.log(text);

streamText

import { streamText } from "ai";

const stream = streamText({
  model: gateway("gpt-5.5"),
  prompt: "Stream me a sentence.",
});

for await (const chunk of stream.textStream) {
  process.stdout.write(chunk);
}

Structured output

generateObject and other structured-output paths send response_format. ToyGate does not support that field yet and returns HTTP 400 with error.code = "response_format_not_supported". Do not ship a generateObject integration through the gateway until that contract changes.

Tool calls

import { tool } from "ai";

const time = tool({
  description: "Returns the current local time in the given timezone.",
  parameters: z.object({ timezone: z.string() }),
  execute: async ({ timezone }) =>
    new Date().toLocaleTimeString("en-US", { timeZone: timezone }),
});

const { text } = await generateText({
  model: gateway("gpt-5.5"),
  tools: { time },
  prompt: "What time is it in Tokyo?",
});

Troubleshooting

  • APICallError: Unauthorized — the SDK couldn't validate against the gateway. Make sure process.env.GATEWAY_KEY is set in the runtime (Node, edge, lambda).
  • InvalidJSONResponseError — the upstream sent something the SDK couldn't parse as JSON; the gateway wraps this as upstream_invalid_response (502).
  • Edge runtimes — the gateway works fine over fetch; pass globalThis.fetch explicitly if your edge environment has an exotic global setup.

Gateway URL: https://api.toygate.store