Skip to main content
The AI SDK is a TypeScript toolkit for building AI apps and agents. It reaches the Fortytwo API through its OpenAI-compatible provider, @ai-sdk/openai-compatible.
Before you start: create a Fortytwo API key and buy credits — see Quickstart, step 1. Keep the key on your server: the API cannot be called from a web page in the browser.

Install

zod is needed only for tools and structured output. Put your key in an environment variable:

Create the provider

fortytwo.ts
  • includeUsage adds token counts to streamed responses.
  • supportsStructuredOutputs sends JSON schemas in strict mode, which the Fortytwo API supports.
  • fortytwo("qwen/qwen3.8-27b") takes any model ID from Models.

Generate text

reasoningText holds the model’s reasoning. reasoningEffort is sent as reasoning_effort; the accepted values and the default are in Models.

Stream

Call tools

stopWhen lets the model call a tool, read the result and answer in the same call.

Get structured output

Send an image

Supported formats and limits are in Images.

Limits

  • Chat Completions only: the AI SDK’s OpenAI Responses provider (@ai-sdk/openai with openai.responses(...)) does not work with the Fortytwo API. Use @ai-sdk/openai-compatible as above.
  • Requests go out with the AI SDK’s own User-Agent; add a headers setting to createOpenAICompatible if you want to tag your traffic.
More options: OpenAI-compatible providers .
Something not working with your agent, or using one we have not listed? Tell us in the platform: Feedback for ideas and small bugs, Contact support if it blocks your work, or Report a security issue.
Last modified on November 13, 2026