---
title: "Cancel a batch"
method: POST
path: "/batches/{id}/cancel"
tags: ["Batch"]
---

# Cancel a batch

`POST /batches/{id}/cancel`

## Request

- Base URL: `https://openrouter.ai/api/v1`
- URL: `https://openrouter.ai/api/v1/batches/{id}/cancel`
- Auth: HTTP bearer

Asks the provider to stop a batch that is still running. Cancellation is enabled per organization; other organizations get `403`. The response is the batch in its current status: it stays `in_progress` until the provider confirms, then becomes `cancelled`, or `completed`, `failed`, or `expired` when the provider job ended first. Poll until the batch has any final status. Repeating the call is safe while the batch is still `in_progress`; once it has a final status the call returns `409`. On OpenAI a cancelled batch keeps the requests that finished before the cancellation when OpenAI returns them: they are in `results` and billed like the rows of a completed batch. On every other provider OpenRouter returns no result rows for a cancelled batch, and the provider still charges for the requests that finished. When the batch wrote its output to your own storage, retrieving the batch can still return that location, and the rows the provider wrote there stay yours to read. See the [Batch API Quickstart](https://openrouter.ai/docs/batch-quickstart).

## Path parameters

- `id` string, required: The batch job id returned from submit.

## Response `200`

The provider accepted the cancellation, or the provider job had already ended while OpenRouter still stores the batch as running. Poll the batch for its final status.

- BatchObject
  - `completion_window` '24h', required
  - `created_at` integer, required
  - `endpoint` string, required
  - `error` object, nullable, required
    - `message` string, required
  - `expires_at` integer, nullable, required: Unix timestamp after which the assigned provider no longer completes unfinished requests. Derived from the provider's documented batch window, so it can exceed `created_at` plus `completion_window` (Google Vertex can take up to 96 hours). `null` when the provider documents no hard expiry.
  - `finalized_at` integer, nullable, required
  - `id` string, required
  - `model` string, required
  - `object` 'batch', required
  - `output` BatchOutputReference: The output location of a batch submitted with `input`, whose `results` are `null`. Returned only by `GET /batches/{id}`, once the batch has ended and the provider reported an output folder or table. Batch lists and responses for a batch with an unpaid charge leave it out.
    - `uri` string, required: URI of the batch output in your own storage. For a Cloud Storage input file it is the output folder, in the form `gs://bucket/folder`, and the files are in the provider batch output format. For a BigQuery input table it is the output table, in the form `bq://project.dataset.table`.
  - `provider` string, nullable, required: Provider OpenRouter assigned to run the batch, using the same name as the `provider` field of sync responses.
  - `request_counts` object, required
    - `completed` integer, required
    - `failed` integer, required
    - `total` integer, required
  - `results` BatchResult[], nullable, required
    - `custom_id` string, required
    - `error` object, nullable, required
      - `error_type` 'context_length_exceeded' | 'max_tokens_exceeded' | 'token_limit_exceeded' | 'string_too_long' | 'authentication' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'provider_overloaded' | 'provider_unavailable' | 'invalid_request' | 'invalid_prompt' | 'not_found' | 'precondition_failed' | 'payload_too_large' | 'unprocessable' | 'content_policy_violation' | 'refusal' | 'invalid_image' | 'image_too_large' | 'image_too_small' | 'unsupported_image_format' | 'image_not_found' | 'image_download_failed' | 'server' | 'timeout' | 'unmapped': Canonical OpenRouter error type, stable across all API formats
      - `message` string, required
      - `param` string, nullable, required
      - `type` string, required
    - `id` string, required
    - `response` object, nullable, required
      - `body` union, required
        - object
          - `alignment` Alignment: Beta. The result of the alignment plugin for this request; the shape may change.
            - `calls` AlignmentCallRecord[], required: One record per evaluated assistant message of the request, in the order the messages were produced. Empty when no message of the request had content to evaluate.
              - …
          - `choices` object[], required
            - `finish_reason` 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call', required
            - `index` integer, required
            - `logprobs` object, nullable, required
              - …
            - `message` object, required
              - …
            - `native_finish_reason` string, nullable, required
          - `created` integer, required
          - `debug` object
            - `echo_upstream_body` object
            - `timings` object
              - …
          - `id` string, required
          - `model` string, required
          - `object` 'chat.completion', required
          - `openrouter_metadata` OpenRouterMetadata
            - `attempt` integer, required
            - `attempts` RouterAttempt[]
              - …
            - `endpoints` EndpointsMetadata, required
              - …
            - `generation_time` integer: Milliseconds measured for the generation, from dispatching the upstream request until its response body ended. Divide the completion token count by this for throughput. Absent when no upstream request was dispatched.
            - `is_byok` boolean, required
            - `params` RouterParams
              - …
            - `pipeline` PipelineStage[]
              - …
            - `region` string, nullable, required
            - `requested` string, required
            - `strategy` 'direct' | 'auto' | 'free' | 'latest' | 'alias' | 'fallback' | 'pareto' | 'bodybuilder' | 'fusion', required
            - `summary` string, required
          - `provider` string, nullable
          - `safeguard_results` ArmorSafeguardResult[]: OpenRouter Armor's verdict for each client tool call of this response, present whenever Armor evaluated the response (even when nothing was flagged). Independent of the `openrouter_metadata` opt-in.
            - `status` object, required
              - …
            - `type` 'dangerous_tool_use', required
          - `service_tier` string, nullable
          - `system_fingerprint` string, nullable
          - `usage` object
            - `completion_tokens` integer, required: The tokens generated
            - `completion_tokens_details` object, nullable
              - …
            - `prompt_tokens` integer, required: Including images, input audio, and tools if any
            - `prompt_tokens_details` object, nullable: Breakdown of tokens used in the prompt.
              - …
            - `server_tool_use` object, nullable: Usage for server-side tool execution (e.g., web search)
              - …
            - `server_tool_use_details` object, nullable: Usage for server-side tool execution (e.g., web search)
              - …
            - `total_tokens` integer, required: Sum of the above two fields
        - OpenResponsesResult: Complete non-streaming response from the Responses API
          - [`BaseResponsesResult`](https://skmtc.dev/openrouterteam/apis/openrouter-api/revisions/f797e38f23b4/schema?at=%2Fcomponents%2Fschemas%2FBaseResponsesResult)
          - object
            - `access_programs` object, nullable: Access program the upstream provider reported for this response (OpenAI `access_programs`). `null` when the provider reported none, including OpenAI's implicit Standard program.
              - …
            - `alignment` Alignment: Beta. The result of the alignment plugin for this request; the shape may change.
              - …
            - `error` OpenResponsesErrorField, nullable: Error of a failed response; `metadata` carries OpenRouter-specific details.
              - …
            - `error_type` 'context_length_exceeded' | 'max_tokens_exceeded' | 'token_limit_exceeded' | 'string_too_long' | 'authentication' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'provider_overloaded' | 'provider_unavailable' | 'invalid_request' | 'invalid_prompt' | 'not_found' | 'precondition_failed' | 'payload_too_large' | 'unprocessable' | 'content_policy_violation' | 'refusal' | 'invalid_image' | 'image_too_large' | 'image_too_small' | 'unsupported_image_format' | 'image_not_found' | 'image_download_failed' | 'server' | 'timeout' | 'unmapped': Canonical OpenRouter error type, stable across all API formats
            - `input_transformations` ResponsesInputTransformation[]: Input items the upstream provider changed before inference (OpenAI `input_transformations`). Present only when the provider reported the field; empty when it changed nothing.
              - …
            - `openrouter_metadata` OpenRouterMetadata
              - …
            - `output` OutputItems[]
              - …
            - `safeguard_results` ArmorSafeguardResult[]: OpenRouter Armor's verdict for each client tool call of this response, present whenever Armor evaluated the response (even when nothing was flagged). Independent of the `openrouter_metadata` opt-in.
              - …
            - `service_tier` string, nullable
            - `text` TextExtendedConfig: Text output configuration including format and verbosity
              - …
            - `usage` Usage, nullable: Token usage information for the response
              - …
        - object
          - `container` AnthropicContainer, nullable, required
            - `expires_at` string, required
            - `id` string, required
            - `skills` AnthropicContainerSkill[], nullable
              - …
          - `content` ORAnthropicContentBlock[], required
            - union
              - …
          - `id` string, required
          - `input_transformations` AnthropicInputTransformation[], nullable
            - `path` string, nullable
            - `reason` string, nullable
            - `type` string, required
          - `model` string, required
          - `role` 'assistant', required
          - `stop_details` AnthropicRefusalStopDetails, nullable, required: Structured information about a refusal
            - `category` 'cyber' | 'bio' | 'frontier_llm' | 'reasoning_extraction' | 'general_harms' | 'null', nullable, required
            - `explanation` string, nullable, required
            - `type` 'refusal', required
          - `stop_reason` 'end_turn' | 'max_tokens' | 'model_context_window_exceeded' | 'stop_sequence' | 'tool_use' | 'pause_turn' | 'refusal' | 'compaction' | 'null', nullable, required
          - `stop_sequence` string, nullable, required
          - `type` 'message', required
          - `usage` intersection, required
            - [`AnthropicUsage`](https://skmtc.dev/openrouterteam/apis/openrouter-api/revisions/f797e38f23b4/schema?at=%2Fcomponents%2Fschemas%2FAnthropicUsage)
            - object
              - …
        - object: Embeddings response containing embedding vectors
          - `data` object[], required: List of embedding objects
            - `document_index` integer: Index of the source document when `input` was a list of documents (contextual embeddings). Absent otherwise.
            - `embedding` union, required: Embedding vector as an array of floats or a base64 string
              - …
            - `index` integer: Index of the embedding in the input list
            - `object` 'embedding', required
          - `id` string: Unique identifier for the embeddings response
          - `model` string, required: The model used for embeddings
          - `object` 'list', required
          - `usage` object: Token usage statistics
            - `cost` number, double: Cost of the request in credits
            - `cost_details` CostDetails, nullable: Breakdown of upstream inference costs
              - …
            - `is_byok` boolean: Whether a request was made using a Bring Your Own Key configuration
            - `prompt_tokens` integer, required: Number of tokens in the input
            - `prompt_tokens_details` object: Per-modality token breakdown. Only present when the input contains 2+ modalities (e.g. text + image) and the upstream provider returns modality-level usage data. Only non-zero modality counts are included.
              - …
            - `total_tokens` integer, required: Total number of tokens used
        - object
          - `audio` union, required
            - object
              - …
            - object
              - …
          - `model` string, required
          - `object` 'audio.speech', required
          - `usage` object, required
            - `completion_tokens` integer, required
            - `prompt_tokens` integer, required
            - `total_tokens` integer, required
        - BatchImageGenerationResponse: Image generation result of a batch request: image links and when they expire
          - `created` integer, required: Unix timestamp (seconds) when the image was generated
          - `data` BatchImageGenerationImage[], required
            - `layer` ImageGenerationLayer: Layer metadata, present when the request asked the provider to split the image into layers (Seedream: `provider.options.seed.layer_decomposition: true` with the required `layer_decomposition_options.max_images`, 2 to 16). Decomposition requires `n` to be 1 or omitted; the response returns up to `max_images` images (the base image plus its layers).
              - …
            - `media_type` string: Media type (MIME type) of the image, e.g. `image/png`, `image/jpeg`, `image/webp`, `image/svg+xml`. May be omitted if the format could not be determined.
            - `url` string, uri, required
          - `expires_at` integer, required: Unix timestamp (seconds) when the image URLs in `data` stop working. Download the images before then.
          - `id` string: Generation ID of this request. Look up its cost and details with `GET /api/v1/generation?id=<id>`.
          - `usage` ImageGenerationUsage: Token and cost usage for the image generation request, when available
            - `cache_creation` AnthropicCacheCreation, nullable
              - …
            - `completion_tokens` integer, required: The tokens generated
            - `completion_tokens_details` object, nullable
              - …
            - `cost` number, double, nullable: Cost of the completion
            - `cost_details` CostDetails, nullable: Breakdown of upstream inference costs
              - …
            - `is_byok` boolean: Whether a request was made using a Bring Your Own Key configuration
            - `iterations` AnthropicUsageIteration[], nullable
              - …
            - `prompt_tokens` integer, required: Including images, input audio, and tools if any
            - `prompt_tokens_details` object, nullable: Breakdown of tokens used in the prompt.
              - …
            - `server_tool_use` object, nullable: Usage for server-side tool execution (e.g., web search)
              - …
            - `service_tier` string, nullable: The service tier used by the upstream provider for this request
            - `speed` 'fast' | 'standard' | 'null', nullable
            - `total_tokens` integer, required: Sum of the above two fields
      - `request_id` string, nullable, required
      - `status_code` integer, required
  - `status` 'validating' | 'in_progress' | 'finalizing' | 'completed' | 'failed' | 'expired' | 'cancelling' | 'cancelled', required
  - `usage` object, nullable, required
    - `cache_creation` AnthropicCacheCreation, nullable
      - `ephemeral_1h_input_tokens` integer, required
      - `ephemeral_5m_input_tokens` integer, required
    - `completion_tokens` integer, required: The tokens generated
    - `completion_tokens_details` object, nullable
      - `audio_tokens` integer, nullable: Tokens generated by the model for audio output.
      - `image_tokens` integer, nullable: Tokens generated by the model for image output.
      - `reasoning_tokens` integer, nullable: Tokens generated by the model for reasoning.
    - `cost` number, double, nullable: Cost of the completion
    - `cost_details` CostDetails, nullable: Breakdown of upstream inference costs
      - `server_tool_cost` number, double, nullable: Metered server-tool execution cost (for example, shell sandbox time) billed for this request, in USD. Matches the billed checkpoint and settlement amounts exactly. 0 when a metered server tool ran but settled at zero dollars; absent when no metered server tool ran.
      - `upstream_inference_completions_cost` number, double, required
      - `upstream_inference_cost` number, double, nullable
      - `upstream_inference_prompt_cost` number, double, required
    - `is_byok` boolean: Whether a request was made using a Bring Your Own Key configuration
    - `iterations` AnthropicUsageIteration[], nullable
      - union
        - AnthropicCompactionUsageIteration
          - [`AnthropicBaseUsageIteration`](https://skmtc.dev/openrouterteam/apis/openrouter-api/revisions/f797e38f23b4/schema?at=%2Fcomponents%2Fschemas%2FAnthropicBaseUsageIteration)
          - object
            - `type` 'compaction', required
        - AnthropicMessageUsageIteration
          - [`AnthropicBaseUsageIteration`](https://skmtc.dev/openrouterteam/apis/openrouter-api/revisions/f797e38f23b4/schema?at=%2Fcomponents%2Fschemas%2FAnthropicBaseUsageIteration)
          - object
            - `model` string
            - `type` 'message', required
        - AnthropicAdvisorMessageUsageIteration
          - [`AnthropicBaseUsageIteration`](https://skmtc.dev/openrouterteam/apis/openrouter-api/revisions/f797e38f23b4/schema?at=%2Fcomponents%2Fschemas%2FAnthropicBaseUsageIteration)
          - object
            - `model` string, required
            - `type` 'advisor_message', required
        - AnthropicUnknownUsageIteration
          - [`AnthropicBaseUsageIteration`](https://skmtc.dev/openrouterteam/apis/openrouter-api/revisions/f797e38f23b4/schema?at=%2Fcomponents%2Fschemas%2FAnthropicBaseUsageIteration)
          - object
            - `type` string, required
    - `prompt_tokens` integer, required: Including images, input audio, and tools if any
    - `prompt_tokens_details` object, nullable: Breakdown of tokens used in the prompt.
      - `audio_tokens` integer, nullable: Tokens used for input audio.
      - `cache_write_tokens` integer, nullable: Tokens written to cache. Only returned for models with explicit caching and cache write pricing.
      - `cached_tokens` integer, nullable: Tokens cached by the endpoint.
      - `file_tokens` integer, nullable: Tokens used for input files/documents.
      - `video_tokens` integer, nullable: Tokens used for input video.
    - `server_tool_use` object, nullable: Usage for server-side tool execution (e.g., web search)
      - `tool_calls_executed` integer, nullable: Number of OpenRouter server tool calls that executed and produced a result.
      - `tool_calls_requested` integer, nullable: Total number of OpenRouter server-orchestrated tool calls the model requested, across all tool types. Provider-native tools (e.g. native web search) are not counted here.
      - `web_search_requests` integer, nullable: Number of web searches performed by server-side tools. For server-orchestrated tool calls a web search is also counted in tool_calls_requested; provider-native web search may report web_search_requests only. Do not sum the two.
    - `service_tier` string, nullable: The service tier used by the upstream provider for this request
    - `speed` 'fast' | 'standard' | 'null', nullable
    - `total_tokens` integer, required: Sum of the above two fields

## Other responses

- `400`: The API key resolved no active workspace.
- `401`: Missing or invalid API key.
- `403`: Batch cancellation is not enabled for the organization.
- `404`: No batch exists for the given id.
- `409`: The batch has already ended, has not reached the provider yet, runs on a provider without a cancel call, or its required provider key is unavailable.
- `429`: Batch API rate limit exceeded for the billable entity.
- `500`: Unexpected error in the ingress or upstream batch-api.
- `502`: The batch service is unavailable, or an upstream provider operation failed.
- `503`: OpenRouter could not check whether the caller may cancel the batch. No cancellation is sent to the provider. Retry the request.

## Changes

- **2026-12-02** `4d849efb71eb`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/openrouterteam/apis/openrouter-api/changes/batches/:id/cancel/post.md)

---

[API](https://skmtc.dev/openrouterteam/apis/openrouter-api.md) - [All operations](https://skmtc.dev/openrouterteam/apis/openrouter-api/llms.txt) - [OpenAPI document](https://skmtc.dev/openrouterteam/apis/openrouter-api/revisions/f797e38f23b4?raw)
