Integrations

Vercel AI SDK

Use your stack as the model behind generateText, streamText and tools in the Vercel AI SDK, through the OpenAI-compatible provider.

The Vercel AI SDK is a TypeScript toolkit for calling language models from Node.js, Next.js and other frameworks. Its @ai-sdk/openai-compatible provider talks to any OpenAI-compatible endpoint, so it points at your stack with a base URL and a key.

Prerequisites

  • A key from your stack's API keys page, exported as STAC_API_KEY. See Authentication.
  • The id of the model you want to call — see Models. The examples below use qwen/qwen3.5-9b.
bash
export STAC_API_KEY="your-stac-api-key"

Set up the provider

  1. Install the packages

    ai is the SDK itself; @ai-sdk/openai-compatible is the provider.

    bash
    npm install ai @ai-sdk/openai-compatible
  2. Create the provider

    name only identifies the provider inside the SDK (for example under providerOptions). apiKey is sent as Authorization: Bearer <key>.

    stac.tstypescript
    import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
     
    export const stac = createOpenAICompatible({
      name: "stac",
      baseURL: "https://api.trystac.com/v1",
      apiKey: process.env.STAC_API_KEY,
    });
  3. Call the model

    stac("qwen/qwen3.5-9b") returns a chat model you can pass to any SDK function.

Example

index.tstypescript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
 
const stac = createOpenAICompatible({
  name: "stac",
  baseURL: "https://api.trystac.com/v1",
  apiKey: process.env.STAC_API_KEY,
});
 
const { text } = await generateText({
  model: stac("qwen/qwen3.5-9b"),
  prompt: "Name three primary colors.",
});
 
console.log(text);

Expected output (the wording varies from run to run):

Red, blue, and yellow.

For long answers, prefer streamText — see the note on timeouts below:

typescript
import { streamText } from "ai";
 
const result = streamText({
  model: stac("qwen/qwen3.5-9b"),
  prompt: "Write a short paragraph about primary colors.",
});
 
for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Limitations

  • The model id must be on your plan. Pass the exact value from Models to stac(...); a model your key's plan doesn't include returns 403.
  • Tools depend on the model. tools in generateText and streamText only work with a model that supports tool calling.
  • Structured output uses JSON mode. The provider only sends a JSON schema when supportsStructuredOutputs: true is set; without it, generateObject falls back to response_format: { type: "json_object" }, which Stac supports.
  • Non-streaming calls have a time window. generateText waits for the whole answer in one response; a generation that runs past roughly 90 seconds fails with 503. Use streamText for long outputs.
  • One completion per request, logit_bias is dropped, and rate limits are per key. See Differences that matter.

Next steps