Call models from an action. The gateway authenticates
with a short-lived token from getServiceToken("ai-gateway"). Model names use the provider/model form in
Models.
OpenAI SDK
The gateway is OpenAI-compatible. Set baseURL to the gateway and pass
getServiceToken as the API key:
Agent component
Pass bijectionGateway as languageModel on
@bijection-dev/agent. It obtains the token for you:
Workflows that call agent.generateText use that same
model. For the RAG component, use
bijectionGateway.embeddingModel(...) as its embedding model.
Vercel AI SDK
bijectionGateway works with generateText, streamText, embed, and
embedMany from the Vercel AI SDK. Use
@bijection/ai-sdk-provider with AI SDK 7.0.105 or later. The provider works in the default runtime and
Node.js actions.
For a Node.js action, set
node.nodeVersion to
"22" or "24" in bijection.json. The default Bijection runtime doesn’t need this
setting.
Stream with streamText:
Choose a model interface
For text generation, start with bijectionGateway(model), which uses Chat
Completions across model providers. Use the native Messages or Responses
interface when you need endpoint-specific provider features:
The Responses endpoint is stateless. The provider sets store: false; it does
not support store: true or previous_response_id.
Decisions with Jev
Decisions is in alphabijectionGateway.evaluationModel() uses /alpha/decisions. The endpoint and AI
SDK’s experimental evaluation interface may change during alpha.
Use AI SDK’s evaluate to classify or score data with Jev from an action:
Questions can use choice, score, or boolean. Boolean answers contain a
probability between 0 and 1. The provider translates this to the HTTP API’s
noul question type and authenticates with getServiceToken("ai-gateway").
Pass abortSignal to evaluate to cancel a request.
Embeddings
Create embeddings with embedMany. The AI SDK automatically splits batches
larger than the gateway’s 512-input limit:
Images and videos
Use bijectionGateway.imageModel() with generateImage, or
bijectionGateway.videoModel() with experimental_generateVideo and
experimental_startVideo. Image and video generation are in alpha. See
Images and videos for examples and callback
handling.
Manual fetch
Use fetch when you want the HTTP API without an SDK. Mint a token, then send
it as Authorization: Bearer <token>:
For Decisions requests with fetch, see the
HTTP API example.
See HTTP API for request and response shapes.
Local development
Local development requires an up-to-date bijection package and local backend,
and a deployment linked to a project whose team has AI Gateway access. From your
project directory, run:
Restart bijection dev after signing in if it was already running, and accept
the backend upgrade if prompted. The examples above, including
getServiceToken("ai-gateway"), work unchanged. See
Local deployments for more setup options.
Inference runs in the cloud and is charged to the linked project’s team.
Anonymous local deployments cannot use the gateway.
Token and timeouts
Call getServiceToken("ai-gateway") inside an action whenever a gateway request
needs a credential. It returns a short-lived token scoped to your deployment;
the action runtime caches and refreshes it as needed. Keep the token private.
Don’t return it to clients, store it in environment variables, or cache it
yourself.
The request runs inside your action, so a long completion can hit the
action timeout (30
minutes in the Bijection runtime, 10 minutes in Node) and fail as an action error
rather than a gateway error.
If getting a token fails with AiGatewayDisabled or AiGatewayUnavailable, see
Who can use it.