LanguageModel backed by the Convex AI gateway. The provider obtains a short-lived credential from the running Convex action, so you do not need to configure or rotate an upstream model-provider API key.
The AI gateway is available from actions running on paid Convex Cloud deployments. It is not available on local or self-hosted backends.
Generate text
Provide three layers to an Effect AI operation:AiGatewayLanguageModel.model(...)selects a gateway model using itsprovider/modelidentifier.AiGatewayClient.layerauthenticates requests with the current Convex deployment.FetchHttpClient.layersends requests through the Fetch API available in both Convex action runtimes.
confect/assistant.impl.ts
Configure requests
Pass OpenAI-compatible request options as the second argument tomodel:
AiGatewayLanguageModel.withConfigOverride when configuration should apply only within part of a larger Effect.
Stream responses
LanguageModel.streamText consumes the gateway’s server-sent event stream inside the action. A normal Convex action still returns one value to its caller; use a Convex HTTP action or persist partial output when a client must observe tokens as they arrive.
Handle errors
AiGatewayClient.layer exposes the two documented service-token failures as tagged errors:
AiGatewayClient.AiGatewayDisabledmeans your team is on the free plan or the gateway has been disabled for your team. Upgrade to a paid plan, or email support@convex.dev if this looks wrong.AiGatewayClient.AiGatewayUnavailablemeans the action is running on a local or self-hosted deployment. Call the model provider directly with your own API key stored in a Convex environment variable.
getServiceToken failures are defects. Gateway HTTP and model failures remain in Effect AI’s AiError channel. Handle those errors before calling Effect.orDie when your action declares a recoverable error schema. See AI gateway availability for the supported deployment types.