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.
export STAC_API_KEY="your-stac-api-key"Set up the provider
Install the packages
aiis the SDK itself;@ai-sdk/openai-compatibleis the provider.bashnpm install ai @ai-sdk/openai-compatibleCreate the provider
nameonly identifies the provider inside the SDK (for example underproviderOptions).apiKeyis sent asAuthorization: Bearer <key>.stac.tstypescriptimport { createOpenAICompatible } from "@ai-sdk/openai-compatible"; export const stac = createOpenAICompatible({ name: "stac", baseURL: "https://api.trystac.com/v1", apiKey: process.env.STAC_API_KEY, });Call the model
stac("qwen/qwen3.5-9b")returns a chat model you can pass to any SDK function.
Example
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:
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 returns403. - Tools depend on the model.
toolsingenerateTextandstreamTextonly work with a model that supports tool calling. - Structured output uses JSON mode. The provider only sends a JSON schema
when
supportsStructuredOutputs: trueis set; without it,generateObjectfalls back toresponse_format: { type: "json_object" }, which Stac supports. - Non-streaming calls have a time window.
generateTextwaits for the whole answer in one response; a generation that runs past roughly 90 seconds fails with503. UsestreamTextfor long outputs. - One completion per request,
logit_biasis dropped, and rate limits are per key. See Differences that matter.
Next steps
- OpenAI compatibility — what the provider is talking to, and what differs from OpenAI.
- Streaming responses — the SSE format behind
streamText. - Errors & rate limits — which status codes to retry.