Inference with Cortex AI Gateway¶
The Cortex AI Gateway exposes an inference endpoint that accepts requests in industry-standard API formats. Any client that lets you override its base URL can send requests through the gateway, including coding agents, agent frameworks, and the official OpenAI and Anthropic SDKs.
All inference runs within the Snowflake perimeter, and usage is attributed to the Snowflake user whose token made the request, so gateway traffic appears in your existing cost and access reporting.
Note
The gateway is a different endpoint from Cortex Inference,
which is served on the account under /api/v2/cortex. Both accept the same requests, but only traffic
through the gateway picks up its access control, traces, and cost attribution.
Gateway endpoint¶
The gateway endpoint takes this form:
Append the path for the API you’re calling: /v1/chat/completions, /v1/messages, or /v1/responses. See
Choose your API.
To get the endpoint for your account, use:
Note
Accounts that use private connectivity reach the gateway on a
different host, so the endpoint won’t match the form above. Use DESCRIBE AI GATEWAY SNOWFLAKE to get the endpoint in
that case: it returns the correct value either way.
Pricing¶
Inference through the gateway is billed the same way as the Cortex Inference: on the number of tokens processed, at each model’s rate. Refer to the Snowflake Service Consumption Table for each model’s cost.
For attributing that spend to teams and users, and for capping it, see Cost management for Cortex AI Gateway.
Choose your API¶
The gateway supports three industry-standard API specifications. Pick the one your client requires:
| Chat Completions API | Messages API | Responses API (preview) | |
|---|---|---|---|
| Compatibility | OpenAI Chat Completions API | Anthropic Messages API | OpenAI Responses API |
| Path | /v1/chat/completions | /v1/messages | /v1/responses |
| Supported models | All models except Claude (OpenAI, Grok, Llama, Mistral, DeepSeek, Snowflake) | Claude models only | OpenAI models only |
| SDK support | OpenAI Python and JavaScript SDKs | Anthropic Python SDK | OpenAI Python and JavaScript SDKs |
| Best for | Most clients and use cases | Existing Anthropic integrations | Clients that only speak the Responses API |
Note
The Responses API is in public preview. It doesn’t keep conversation state, so clients must send the full conversation with each request. For other limitations, see Limitations.
Prerequisites¶
Before you begin, you need:
- Your gateway endpoint, from
DESCRIBE AI GATEWAY SNOWFLAKE. See Gateway endpoint. - The USAGE privilege on the gateway. See Access control.
- A token for authentication: an OAuth access token, a key-pair JSON Web Token (JWT), or a programmatic access token (PAT). See Setting up authentication.
- A model name to use in requests. See Model availability.
- Access to the model itself. The gateway respects model access control: a request still needs
whatever access the underlying model requires, such as the
SNOWFLAKE.CORTEX_USERdatabase role or the controls described in Privileges and model access for Cortex AI Functions. USAGE on the gateway doesn’t widen the set of models a user is entitled to, so sending traffic through it doesn’t expand your security perimeter.
Setting up authentication¶
The gateway accepts the same tokens as other Snowflake REST APIs, using the methods described in Authenticating Snowflake REST APIs with Snowflake: OAuth, key-pair authentication with a JWT, or a programmatic access token. It’s recommended to use a short-lived token, such as an OAuth access token, rather than a PAT, which stays valid until it expires or is revoked.
Send the token as a bearer token in the Authorization header:
Quickstart¶
The Anthropic SDK sends credentials in an x-api-key header by default, but the gateway expects a
Bearer token. Use an httpx client to set the correct header.
The base URL omits the trailing /v1, because the Anthropic SDK appends /v1/messages itself.
Supported features¶
The gateway exposes the same Chat Completions, Messages, and Responses surfaces as Cortex Inference, so request and response fields, and the features built on them, behave the same way. See the Cortex Inference documentation for instructions on:
- Streaming responses over server-sent events for both APIs. See Streaming.
- Tool calling. See Tool calling.
- Structured output. See Structured output.
- Prompt caching. See Prompt caching.
- Image input. See Image input.
- Thinking and reasoning. See Thinking and reasoning.
For the complete field-level request and response reference, see Cortex Inference. For the fields and features the Responses API supports, see Responses API reference.
Instrument a coding agent¶
You can launch the agent with Snowflake CLI or configure it yourself:
- Snowflake CLI launches a coding agent, such as OpenCode, with its traffic already routed, using the endpoint and credential from a Snowflake CLI connection.
- Manual setup means configuring the base URL and the credential in the agent yourself. Use it for an agent Snowflake CLI doesn’t launch, or when the configuration needs to persist outside the CLI.
Snowflake CLI¶
The snow ai commands launch a coding agent that’s already installed on your machine, with its model
requests routed through the gateway. The Snowflake CLI connection can authenticate with OAuth or with a PAT:
To pass arguments to the agent, put them after --agent-args:
For how snow ai works, the supported authenticators, and what each command configures in its agent,
see snow ai commands.
Manual setup¶
Agents differ in which API format they use, where their configuration lives, and how they send credentials. Use the section for your agent.
OpenCode¶
To point OpenCode at the gateway, define a custom provider in your
~/.config/opencode/opencode.json file. OpenCode uses the Chat Completions API through the
OpenAI-compatible adapter:
Where:
baseURLis the gateway endpoint fromDESCRIBE AI GATEWAY SNOWFLAKEwith/v1appended.accountis the host part of that endpoint, without the path.apiKeyuses OpenCode’s{env:...}substitution to read the token from theSNOWFLAKE_TOKENenvironment variable, so the token isn’t stored in the file.modelandsmall_modelare both qualified by the provider name, so they readsnowflake-cortex/<model>. Settingsmall_modelas well keeps OpenCode’s lightweight calls on the gateway rather than falling back to its default.- The
snow-agent-nameheader identifies the client on each request. - The
pluginentry loads the OpenTelemetry plugin and lists the providers it propagates trace context to. Namingsnowflake-cortexintracePropagationProvidersmakes OpenCode send atraceparentheader on its gateway requests.
Other clients¶
Any client that lets you set a custom base URL and bearer token, and connects using the Chat Completions API, Messages API, or Responses API can use the gateway. Set the base URL according to the API format the client uses, as described in Gateway endpoint, and supply your token as the bearer token. See Setting up authentication.
Monitor gateway inference¶
Requests sent through the gateway are recorded in two places:
- Traces, for what each request did: models called, timing, tokens, and errors. See Observability for Cortex AI Gateway.
- Usage history, for credits consumed. See AI_GATEWAY_USAGE_HISTORY view.
For cost attribution, budgets, and per-user quotas, see Cost management for Cortex AI Gateway.
Legal notices¶
Where your configuration of Cortex AI Gateway uses a model provided on the Model and Service Pass-Through Terms, your use of that model is further subject to the terms for that model on that page.
The data classification of inputs and outputs is as set forth in the following table.
| Input data classification | Output data classification | Designation |
|---|---|---|
| Customer Data | Customer Data | Preview AI Features [1] |
For additional information, refer to Snowflake AI and ML.