The Cortex Agent SDK authenticates Cortex Agent REST API requests by asking an authenticator for HTTP headers. The SDK
calls the authenticator before every request attempt, including transport retries and auth-refresh replays, so callable
authenticators can pick up rotated credentials without recreating the client.
Keep Programmatic Access Tokens (PATs), private keys, OAuth refresh tokens, client secrets, and Snowflake session
tokens in trusted server-side code. Don’t ship these credentials to browser code.
If the account identifier contains an underscore (_), the SDK uses Snowflake’s canonical hyphenated host form for
the derived URL. For example, myorg_myaccount derives https://myorg-myaccount.snowflakecomputing.cn.
Pass baseUrl instead of account when you need a full regional, PrivateLink, pre-production, or proxy endpoint:
Use key-pair JWT authentication when a server-to-server application can protect a private key and mint short-lived
JWTs. The application owns signing and renewal. The SDK calls the JWT provider before request attempts and sends the
returned token.
The TypeScript example below mints an RS256 JWT from the private key, Snowflake account identifier, username, and
public-key fingerprint.
The Python SDK doesn’t sign the JWT for you. Pass a callable that returns a currently valid signed JWT, for example
from your own signer or from Snowflake connector key-pair authentication code.
import os
from cortex_agent_sdk import CortexAgentClient, KeyPairJwtAuth
defmint_jwt() -> str:
# Sign a short-lived JWT with your protected private key.return os.environ["SNOWFLAKE_KEYPAIR_JWT"]
client = CortexAgentClient(
account=os.environ["SNOWFLAKE_ACCOUNT"],
auth=KeyPairJwtAuth(mint_jwt),
refresh_auth=lambda_context: None,
)
Use OAuth when your service receives Snowflake OAuth or External OAuth access tokens and can refresh them on the
server. Store the OAuth client secret and refresh token in an encrypted server-side secret store.
Use a Snowflake session token when your application already has an authenticated Snowflake SQL driver session and
wants Cortex Agent API requests to run with that session.
The Node.js snowflake-sdk driver doesn’t currently expose stable public methods to read both the current session
token and resolved access URL from a connection. The example below uses the driver’s serialized connection state to
extract the session token. This works with the current driver shape, but if this integration breaks, use PAT, OAuth, or
key-pair JWT authentication instead.
Pass refreshAuth in TypeScript or refresh_auth in Python when the credential source needs an explicit refresh
signal after Snowflake returns an expired-token or expired-session response.
When the SDK detects an expired credential response:
It calls the refresh callback with request context, including the HTTP method, path, request ID when present, and
refresh attempt number.
If the callback succeeds, the SDK asks the authenticator for headers again and immediately replays the same
request.
By default, the SDK performs one auth refresh and one replay per request.
If the refresh callback fails, the SDK raises the original typed API error, such as AuthenticationError, and attaches
safe refresh diagnostics. The error metadata doesn’t include authorization headers or token values.
from cortex_agent_sdk import AuthenticationError
try:
conversation.send("Analyze Q1 revenue.")
except AuthenticationError as error:
print(error.auth_refresh.provider if error.auth_refresh elseNone)
print(error.auth_refresh.attempt if error.auth_refresh elseNone)
print(error.auth_refresh.request_id if error.auth_refresh elseNone)
print(error.__cause__)
Where your configuration of Cortex Code 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 are as set forth in the following table.