Cortex Agent SDK reference¶
Use this reference when you need details about SDK response objects, thread message helpers, transport wrappers, error classes, retry behavior, and per-request options. For workflow examples, see Conversations and Use the direct Cortex Agent API. For authentication examples, see Authenticate Cortex Agent SDK requests.
Response views¶
Response views wrap the typed message content union so you can use getters such as text, tool_uses or toolUses,
tables, and charts without switching on content discriminators yourself.
| Class | Wraps |
|---|---|
AgentResponseView | An assistant response from a direct run. |
AgentResponse | The high-level response returned by a conversation Turn. |
ThreadMessageView | A persisted thread message returned by the direct threads resource. |
Content getters¶
Each getter filters the content array down to one kind of item.
Common members include:
view.text: all text values concatenated in orderview.content: full content arrayview.texts: text blocksview.thinkings: reasoning blocksview.toolUses: tool calls made by the modelview.toolResults: tool resultsview.toolResultsAggregated: aggregated tool-result rollupsview.tables: tabular resultsview.charts: chart artifactsview.assets: asset referencesview.suggestedQueries: suggested follow-up queriesview.images: inline imagesview.documents: document referencesview.artifacts: persisted artifactsview.permissionDecisions: permission decisions emitted by the agentview.actualUserMessages: user-facing messages emitted by the agent
Common members include:
view.text: all text values concatenated in orderview.content: full content arrayview.texts: text blocksview.thinkings: reasoning blocksview.tool_uses: tool calls made by the modelview.tool_results: tool resultsview.tool_results_aggregated: aggregated tool-result rollupsview.tables: tabular resultsview.charts: chart artifactsview.assets: asset referencesview.suggested_queries: suggested follow-up queriesview.images: inline imagesview.documents: document referencesview.artifacts: persisted artifactsview.permission_decisions: permission decisions emitted by the agentview.actual_user_messages: user-facing messages emitted by the agent
Finder methods¶
Search response content by tool name.
The single-item finders return undefined when nothing matches.
The single-item finders return None when nothing matches.
AgentResponseView¶
AgentResponseView represents a completed assistant response from the direct API.
Important members include:
view.role:"assistant", alwaysview.metadata:ResponseMetadata, includingrun_id,thread_id, message IDs, and usageview.events:ServerSentEvent[] | undefined, populated when the view was built from a streamview.requestId: Snowflake request ID, when presentview.responseBody: full parsed response bodyview.response: underlying HTTP response, available for headers and status only
You can create an AgentResponseView by calling a direct run method with stream: false, by calling
AgentResponseView.fromStream(stream) after draining an AgentRunStream, or by calling
AgentResponseView.fromThreadMessage(message) when reading a persisted assistant reply from thread history.
Important members include:
view.role:"assistant", alwaysview.metadata: response metadata, includingrun_id,thread_id, message IDs, and usageview.events: ordered raw events, populated when the view was built from a streamview.request_id: Snowflake request ID, when presentview.response_body: full parsed response body
ThreadMessageView¶
ThreadMessageView wraps a raw thread message returned by the direct threads resource.
Thread-specific members include messageId, parentId, role, createdOn, requestId, messageType, status,
schemaVersion, tags, and raw.
Thread-specific members include message_id, parent_id, role, created_on, request_id, message_type,
status, schema_version, tags, and raw.
Snowflake thread and message identifiers are preserved as strings so int64 IDs remain exact.
Thread pagination¶
Use pagination helpers when listing threads through the direct API.
api.threads.list() returns a response wrapper whose .page field is a ThreadsPage.
You can also page manually:
Transport wrappers¶
Direct API resource methods can expose parsed response bodies together with transport metadata. Use these wrappers when you need request IDs, response headers, or status details from the underlying HTTP call.
APIResponse<T>¶
APIResponse<T> is returned by methods such as api.threads.create(), api.agent.create(), and
api.requestWithResponse():
Use these members:
responseBody: parsed JSON bodyresponse: raw HTTPResponserequestId:x-snowflake-request-id, when present
The body has already been consumed to populate responseBody. Do not call res.response.json() or
res.response.text().
The Python direct API returns parsed response objects for most resources. Response view and background-run objects carry the request ID and parsed body when the server returns them.
ResponseCarrier<T>¶
ResponseCarrier<T> is not a class that application code usually constructs directly. It is the shared TypeScript
base behind raw wrapper objects such as AsyncRun and AgentResponseView, which is why those objects expose the same
transport fields as APIResponse<T>: responseBody, response, and requestId.
The following example reads the fields that those wrappers inherit from ResponseCarrier<T>:
The equivalent Python classes expose snake_case members such as response_body and request_id.
api.requestWithResponse¶
Use requestWithResponse() when you need the TypeScript direct API client’s request primitive and the
APIResponse<T> transport wrapper.
It rejects stream: true. For streaming requests, use api.agent.stream(), api.agent.run(), api.runs.stream(), or
api.runs.resume().
Use the Python direct resource methods for the same endpoints. The public Python API does not require a separate
requestWithResponse() wrapper for normal SDK usage.
Error hierarchy¶
The SDK raises typed errors for API and client-side failures.
Every CortexAgentError can expose name, status, requestId, and body.
Every CortexAgentError can expose name, status, request_id, and body.
If an auth-refresh callback fails, the SDK raises the original API error and attaches safe refresh metadata. In
TypeScript, read err.authRefresh.provider, err.authRefresh.attempt, err.authRefresh.requestId, and err.cause.
In Python, read err.auth_refresh.provider, err.auth_refresh.attempt, err.auth_refresh.request_id, and
err.__cause__.
Retries¶
The SDK can retry transient transport failures:
4084094295xx
Client-level retry defaults apply automatically only to retry-safe methods: GET, HEAD, and OPTIONS. For
mutating requests, including agent runs and resource creation, pass a per-request retry policy to opt in to replaying
the request after a transient failure.
TypeScript retries use exponential backoff with Retry-After support and these defaults:
- Initial delay:
500ms - Multiplier:
2x - Maximum nominal delay:
30_000ms - Additive jitter: up to
500ms - Default
maxRetries:2 - Default
retryStreaming:false
Configure retries on the client for retry-safe methods:
Or per request:
Mutating requests require a per-request retry policy:
Streaming requests are not retried by default, including pre-response network failures. Opt in explicitly when reconnecting to a run stream:
Python retries use exponential backoff with Retry-After support and these defaults:
- Initial delay:
0.5seconds - Multiplier:
2x - Maximum delay:
8seconds - Multiplicative jitter: shortens the computed delay by up to 25%
- Default
max_retries:2 - Default
retry_streaming:False
Configure retries on the client for retry-safe methods:
Or per request:
Mutating requests require a per-request retry policy:
Streaming requests are not retried by default, including pre-response network failures. Opt in explicitly when reconnecting to a run stream.
Mid-stream retry remains a caller concern.
Request options¶
Raw resource request methods accept per-request options.
The TypeScript RequestOpts type includes:
Use these fields for:
signal: abort a requesttimeout: non-streaming request timeout in millisecondsretryPolicy: per-request retry overrideheaders: custom headers merged into the requestquery: extra query parametersstreamReadTimeoutMs: dead-socket timeout for streaming requests
On methods that also take query parameters, opts is the last argument:
Pass transport overrides through the options argument on resource methods. Python timeout values are in seconds.
Legal notices¶
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.
| Input data classification | Output data classification | Designation |
|---|---|---|
| Usage Data | Customer Data | Covered AI Features [1] |
For additional information, refer to Snowflake AI and ML.