Skip to content

Stopping a turn ​

A turn can take a while: a long answer, a slow tool, a tool loop. Stop ends the turn that is running right now, from Studio, from a portal or embedded chat, or from your own code over the API. The model call stops, so spending stops with it, and what the agent had already written is kept.

One cancel semantic sits behind every surface (the cancel standard): the runs API, the session, the OpenAI Responses endpoint, A2A, Studio and portals all end the turn the same way.

What a stop does ​

The answerWhat the agent had streamed so far is kept as its answer. Nothing is thrown away and nothing is invented to finish the sentence.
The stop reasonThe turn ends with stop_reason: cancelled (in a response, in the session events, in the transcript). Chat UIs show it as Stopped before it finished.
The model callThe request to the model provider is aborted, so it stops generating and stops billing.
UsageThe model usage row of the aborted call is recorded with status cancelled, not error. Tokens produced before the stop are still counted.
The sessionGoes back to Idle. You can send the next message at once.

Nothing running is not an error. A Stop that lands just as the turn ends is normal, so the API answers 200 with cancelled: false.

What happens to tools that are running ​

The stop reaches a tool while it is running when the tool is one of these:

ToolOn Stop
OpenAPI toolsThe upstream HTTP request is aborted.
MCP toolsThe upstream request is aborted.
Sandbox (exec, run_code)The call is aborted.
Built-in web searchThe call is aborted.

Every other tool is not interrupted: it finishes, its result is dropped, and the turn ends without calling the model again. A 10-second OpenAPI tool does not hold a stopped turn for 10 seconds; a tool that cannot be aborted may.

A side effect a tool has already caused (a record created, an email sent) is not undone by a stop.

In Studio ​

While an agent is answering, the composer's send button becomes Stop. Press it and the answer stays, marked as stopped. The same Stop is on a session that is answering in another window: a second tab or a reload follows the turn live, and Stop there ends it for everybody.

If the session is waiting for an approval or an answer, Stop cancels those open requests too, as if they were answered "no". See Approvals.

Portals and embedded chat ​

A portal and the embedded chat use the same Stop button. It ends the turn on the server, not just the page's connection.

Two rules apply:

  • Closing the page does not stop a turn. A closed connection leaves the turn running, which is intended: a person can reload and pick the answer up again.
  • Stop is for a turn that runs. A portal conversation that only waits for the person (an approval or a question is open, nothing runs) answers 409 with the code action_pending, and leaves the request exactly as it was. The chat turns that into Answer the request above, or send a new message.

The cancel standard ​

SurfaceCall
Runs API (canonical)POST /api/client/v1/agents/runs/{runId}/cancel
SessionPOST /api/client/v1/agents/sessions/{sessionId}/cancel
OpenAI ResponsesPOST /api/client/v1/responses/{id}/cancel
A2Atasks/cancel

Older routes (/agents/conversations/{id}/cancel, /agents/responses/{id}/cancel) remain as aliases with identical behaviour. What the call does depends on the state of the run:

Run stateEffect
scheduled, queuedBecomes canceled at once and never starts.
running (inline, detached or queued)cancel_requested_at is set; the turn stops at its next checkpoint (about a second) and ends canceled, stop_reason: cancelled, the partial answer kept.
requires_actionBecomes canceled at once: the open requests are cancelled as if answered "no" and the session is released. No row is left waiting. A pause dropped any other way ends its run the same way: a new message to an agent set to cancel pending requests, a session truncate, or the cancel choice of the timeout policy. Each sends the run's callback and the agent_run.canceled webhook.
FinishedThe runs API answers 409 agent_run_already_terminal. The OpenAI route answers 200 with the final response, as OpenAI does. A session cancel answers 200 with cancelled: false.

A canceled async run also delivers its callback and webhook (agent_run.canceled). A client that disconnects from a streaming chat completions or Responses call cancels the turn too (unless background: true was sent). On the runs API a dropped stream continues by default (on_disconnect: "cancel" stops it), and a dropped A2A message/stream does not cancel the task: stop it with tasks/cancel.

Over the API ​

All the client-API routes take the same bearer token as the rest of /api/client/v1 and see only the token's project. A session or run of another project, or an unknown one, is 404.

By run ​

bash
curl -X POST "$CONSOLE_URL/api/client/v1/agents/runs/run_65f1c0a2b9d3e4f5a6b7c8d9/cancel" \
  -H "Authorization: Bearer $COGNIPEER_API_TOKEN"

Answers 200 with the run. A run that was running may still read running with cancel_requested_at set for about a second.

By session ​

bash
curl -X POST "$CONSOLE_URL/api/client/v1/agents/sessions/6f1c0a2b9d3e4f5a6b7c8d9e/cancel" \
  -H "Authorization: Bearer $COGNIPEER_API_TOKEN"
json
{ "object": "agent.session.cancel", "cancelled": true, "run_ids": ["run_65f1c0a2b9d3e4f5a6b7c8d9"] }

{sessionId} is the session id. It cancels the session's active or paused run. Use it when you hold the session id but not the run id, for example from a chat front end.

By response id (OpenAI) ​

bash
curl -X POST "$CONSOLE_URL/api/client/v1/responses/resp_65f1c0a2b9d3e4f5a6b7c8d9/cancel" \
  -H "Authorization: Bearer $COGNIPEER_API_TOKEN"

Answers with the response object: status: "cancelled", or in_progress for the moment a cooperative cancel is still landing. The id is resp_<runId> (or run_<runId>, or the older resp_<conversationId>). For a streaming call it is the id in the first event. OpenAI SDK: client.responses.cancel(id).

The result ​

FieldMeaning
cancelledtrue when a running turn was told to stop, a queued one was cancelled, or open approvals and questions were settled. false when there was nothing to stop.
run_idsThe runs that were cancelled or told to stop. Empty when nothing ran.

The route answers when the turn has been told to stop, not when it has ended. The request that is running the turn returns its own response a moment later, with stop_reason: cancelled and the partial answer. Read it from there, from the run, or from the session events.

Who may stop ​

Stopping a session is acting on it. The owner of a session may always stop it. Anybody else needs the agent.session_manage_others permission, otherwise the call is refused as for any other session action.

Ending an open approval is answering it "no", so it needs the right to answer approvals (agent.approve). Without that right the turn still stops, and the approval stays open, with cancelled: false if there was no running turn. See Access control.

Dashboard route (Studio) ​

Studio uses its own route, behind the dashboard sign-in and the agent's permissions:

http
POST /api/agents/{agentId}/sessions/{sessionId}/cancel

It answers 200 with { "cancelled": true, "runIds": ["…"], "cancelledActions": false } (camelCase, as the dashboard API does). It works for a turn started from anywhere: the playground, the API, a portal.

Runs ​

A run is stopped with the routes above; POST /agents/runs/{runId}/cancel is the direct one. A queued run never starts; a running one keeps its partial answer and delivers its callback. A run waiting on an approval (requires_action) is settled right away, and the caller needs the right to answer it, or the call is refused with 403 action_forbidden.

A2A ​

An A2A client stops a task with JSON-RPC tasks/cancel:

json
{ "jsonrpc": "2.0", "id": 7, "method": "tasks/cancel",
  "params": { "id": "run_65f1c0a2b9d3e4f5a6b7c8d9" } }

The task id is the one the server handed out: run_{runId} for new tasks (older task_{conversationId}_{messageIndex} ids still resolve). A running task answers:

json
{ "jsonrpc": "2.0", "id": 7,
  "result": { "kind": "task", "id": "run_65f1c0a2b9d3e4f5a6b7c8d9",
              "contextId": "6f1c0a2b9d3e4f5a6b7c8d9e",
              "status": { "state": "canceled", "timestamp": "2026-10-14T09:00:00.000Z" } } }
ErrorWhen
-32001The task is not found.
-32002TaskNotCancelable (it was -32004 before): nothing to cancel. The message says why: the task cannot be canceled: it is not running, or waiting for an approval or an answer, so there is no running turn to stop with the open ids in data.pending_action_ids.
-32010The caller may not answer the approval the task waits on (with a decision_id).

A JSON-RPC error is an HTTP 200, as everywhere in A2A. Closing a message/stream connection leaves the task running; tasks/resubscribe reattaches to it (A2A).

Across nodes ​

Cognipeer may run on several servers behind a load balancer, and the Stop request does not have to reach the server that runs the turn. Every turn holds the session's single run slot in the database. A Stop writes a cancel request on it:

  • On the same server, the turn is aborted immediately.
  • On another server, that server notices the request within about a second and aborts the turn.

So a Stop works from any node, for a turn started from any door, with at most a second of delay when the two differ.

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub