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, either /v1/chat/completions or /v1/messages. 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 SHOW AI GATEWAYS 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 two industry-standard API specifications. Pick the one your client requires:
| Chat Completions API | Messages API | |
|---|---|---|
| Compatibility | OpenAI Chat Completions API | Anthropic Messages API |
| Path | /v1/chat/completions | /v1/messages |
| Supported models | All models except Claude (OpenAI, Grok, Llama, Mistral, DeepSeek, Snowflake) | Claude models only |
| SDK support | OpenAI Python and JavaScript SDKs | Anthropic Python SDK |
| Best for | Most clients and use cases | Existing Anthropic integrations |
Note
The OpenAI Responses API (/v1/responses) is coming soon to the gateway and not supported yet. If a client offers a choice of API
format, choose Chat Completions or Messages.
Prerequisites¶
Before you begin, you need:
- Your gateway endpoint, from
SHOW AI GATEWAYS. See Gateway endpoint. - The USAGE privilege on the gateway. See Access control.
- A programmatic access token (PAT) for authentication. See Using programmatic access tokens for 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 expects the token as a bearer token:
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 and Messages 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.
Instrument a coding agent¶
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 fromSHOW AI GATEWAYSwith/v1appended.accountis the host part of that endpoint, without the path.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 either the Chat Completions API or Messages 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 PAT as the bearer token.
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.