For one-off, stateless queries just use
Normally, the model starts responding after you send a user message. New messages sent before the response finishes are handled at the time specified by
While the model is responding, you can keep sending new messages into the same session:
Messages with equal priority are processed in send order.
Setting
Calling
Give messages you need to track a session-unique UUID (TypeScript: the
Returns
Suited to sessions whose lifecycle is tied to a function or code block. TypeScript puts
Suited to closing the session on external conditions (timeout, user cancellation, app exit, etc.). TypeScript creates an
After the session is closed, no more messages can be sent.
query(); see Quick Start. To send multiple user messages within the same session, the two SDKs differ:
- TypeScript: pass
query()an async message stream that yields user messages in order; the session closes automatically when the input stream ends. - Python: use
QoderSDKClient—it maintains a long-lived connection and lets you decide the next message based on the model's replies.
Multi-message session
priority. In TypeScript, the session closes automatically when the input message stream ends; message field definitions are in SDKUserMessage. In Python, each client.query(...) call appends one turn of input, then consume client.receive_response() until the turn's response completes.
Steering a response
While the model is responding, you can keep sending new messages into the same session:
priority controls when a message is delivered:
| Value | Behavior |
|---|---|
now | Stop the current response and handle this message immediately |
next | Default; handle this message at the next suitable point |
later | Wait until the current response finishes |
priority now suits changing direction immediately; to stop the current response without sending a new message, use Interrupting the current response.
Add context without starting a response
Setting shouldQuery: false (TypeScript) / should_query=False (Python) adds the message to the conversation without triggering a response on its own. Its processing time is still governed by priority.
Interrupting the current response
Calling interrupt() stops the current response without closing the session, so the conversation can continue afterwards. In TypeScript, call it on the object returned by query(); in Python, only QoderSDKClient offers runtime interruption—the one-shot query() iterator does not.
interrupt() does not clear queued messages; you can still send the next turn afterwards. If a queued message should not proceed, cancel it instead. For ending the whole session, see Managing the session lifecycle.
Cancel a queued message
Give messages you need to track a session-unique UUID (TypeScript: the uuid field on the message; Python: the message_uuid parameter), then call the cancel method to cancel messages that have not started executing:
true on success; returns false if the message does not exist or can no longer be cancelled. Messages without a UUID cannot be cancelled this way. Do not reuse UUIDs within a session.
Managing the session lifecycle
- TypeScript: after a single string input finishes or the input message stream ends, the SDK closes the session automatically; to end early, use an
AbortControlleror callq.close()directly. - Python: the
QoderSDKClientconnection lifecycle is owned by the caller; preferasync withfor automatic management, or useconnect()/disconnect()manually.
Automatic cleanup bound to a code block
Suited to sessions whose lifecycle is tied to a function or code block. TypeScript puts close() in finally to guarantee resources are released; Python disconnects automatically when the async with block exits:
Ending on an external condition
Suited to closing the session on external conditions (timeout, user cancellation, app exit, etc.). TypeScript creates an AbortController, passes it via options.abortController, and calls abort() when the condition fires—closing the whole session and ending message iteration; Python holds the client manually and calls disconnect() in finally: