Agentsai-org
POST/ai-sessions/{session_id}/cancel
Cancel a session: it ends at its next step.
cancel_ai_session
ai_org:manage
A token needs theai_org:managescope: Configure and operate an AI organization: drafts, pausing, suspending, sessionsGranted bywrite_api.Every operation this scope unlocksAudited · mutation
x-gitmoap-audit: {"kind":"audited","arg":"mutation"}
Its branch and the work it is linked to remain. The answer is the session as it stood before the cancellation took effect; cancelling a session that has already ended changes nothing. Maintainers and above of the organization's top-level group may cancel one.
Parameters
Path
- session_idAiSessionId (string · uuid)The session
Responses
200The session, as it stoodapplication/json
- cost_microsinteger · int64Settled spend, fee included, in micro-dollars.
- created_atstring · date-time
- org_idAiOrgId (string · uuid)
- root_group_idGroupId (string · uuid)The top-level group whose organization it ran in.
- session_idAiSessionId (string · uuid)
- stateAiSessionStatequeuedrunningwaiting_gatewaiting_personcompletedfailedcancelledhalted
subjectSessionSubject
- The SessionSubject schema
- addressstring or nulloptionalThe address acted on —
acme/api#412,acme/api!87— when the session has one. - started_bystring or nulloptionalThe person or account whose action started the session, when one did.
- trigger_kindAiTriggerKindassignmentreview_requestreview_feedbackmentionchannel_messageritualpipeline_failuretracker_eventgate_decisionhandoffcontinuationproposalmanualprofile_draftWhat started a session.
- turnsinteger · int32
- agent_idAgentId (string · uuid) or nulloptional
- branchstring or nulloptional
- ended_atstring · date-time or nulloptional
- instructionSessionInstruction (string) or nulloptional
- model_idAiModelKey (string) or nulloptional
- outcomeAiSessionOutcomemerge_request_openedreview_submittedwork_item_updatedmessage_postedproposal_writtenescalatedno_actionbudget_exhaustedrefusederrortaken_overor nulloptional
- repository_idRepositoryId (string · uuid) or nulloptionalThe repository the session works on, when it works on one.
- revision_numberinteger · int64 or nulloptionalThe revision it pinned at start; absent only for a platform session started before any revision was published.
- started_atstring · date-time or nulloptional
- summarystring or nulloptionalThe agent's own account of the session.
200 exampleSynthesized example
{
"cost_micros": 44,
"created_at": "2026-10-10T08:59:32Z",
"org_id": "5ff8888a-59ae-43f5-a00c-fe7a415151ee",
"root_group_id": "4c1d8e2f-6a3b-4f90-b7c5-1e2d3c4b5a69",
"session_id": "12dd8531-e01d-4b8c-8b68-4a48454dee98",
"state": "queued",
"subject": {
"address": "address-6f7a",
"started_by": "a3f1c2d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d"
},
"trigger_kind": "assignment",
"turns": 18,
"agent_id": "5d1003e4-047c-4752-a882-ccfc88fe5cf6",
"branch": "fix/payload-build-pin",
"ended_at": "2026-10-08T11:55:03Z",
"instruction": "instruction-6559",
"model_id": "e441e5f5-6041-42c5-bf19-e7159112a109",
"outcome": "merge_request_opened",
"repository_id": "5b0e7c2a-9d14-4e8b-a6f1-2c3d4e5f6a70",
"revision_number": 25,
"started_at": "2026-10-12T17:39:30Z",
"summary": "summary-b32b"
}
400Bad request — a path parameter is not a well-formed value of its typeapplication/json
Error codes
- BAD_REQUESTThe request is malformed: a parameter or a body field is not a well-formed value of its type
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
400 exampleSynthesized example
{
"error": {
"code": "code-322b",
"message": "Stream pipeline status into the run header"
}
}
401Unauthenticated — no credential, or an invalid oneapplication/json
Error codes
- UNAUTHORIZEDNo credential was sent, or the one sent is invalid, expired or revoked
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
401 exampleSynthesized example
{
"error": {
"code": "code-a719",
"message": "Label every synthesized example"
}
}
403Forbidden — the caller's access level or token scope is insufficientapplication/json
Error codes
- FORBIDDENYou are signed in but may not do this here;
reasonnames the permission or the rule that refused it - INSUFFICIENT_SCOPEThe access token lacks the scope this operation needs;
required_scopenames it - PERMISSION_REQUIREDYou need a permission you do not hold here; the message names it
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
403 exampleSynthesized example
{
"error": {
"code": "code-db0b",
"message": "Draw the region map from operation density"
}
}
404Not found — or found and private, which is masked as absentapplication/json
Error codes
- NOT_FOUNDThe resource does not exist — or exists and you cannot see it: a private resource you have no access to answers exactly as an absent one does
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
404 exampleSynthesized example
{
"error": {
"code": "code-4bd4",
"message": "Draw the region map from operation density"
}
}
409The request conflicts with the resource's current state; `reason` says howapplication/json
Error codes
- CONFLICTThe request conflicts with the resource's current state;
reasonsays how - LEGAL_ACCEPTANCE_REQUIREDAccept the current Terms of Service before changing anything; reading stays open
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
409 exampleSynthesized example
{
"error": {
"code": "code-4904",
"message": "Stream pipeline status into the run header"
}
}
CLI
gitmoap ai-org cancel-ai-session
- --session-ididThe session