curl --request POST \
--url https://openrouter.ai/api/v1/batches/{id}/cancel \
--header 'Authorization: Bearer <token>'import requests
url = "https://openrouter.ai/api/v1/batches/{id}/cancel"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://openrouter.ai/api/v1/batches/{id}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/batches/{id}/cancel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openrouter.ai/api/v1/batches/{id}/cancel"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/batches/{id}/cancel")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://openrouter.ai/api/v1/batches/{id}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"completion_window": "24h",
"created_at": 123,
"endpoint": "<string>",
"error": {
"message": "<string>"
},
"expires_at": 123,
"finalized_at": 123,
"id": "<string>",
"model": "<string>",
"object": "batch",
"provider": "<string>",
"request_counts": {
"completed": 123,
"failed": 123,
"total": 123
},
"results": [
{
"custom_id": "<string>",
"error": {
"message": "<string>",
"param": "<string>",
"type": "<string>",
"error_type": "rate_limit_exceeded"
},
"id": "<string>",
"response": {
"body": {
"choices": [
{
"finish_reason": "stop",
"index": 123,
"logprobs": {
"content": [
{
"bytes": [
123
],
"logprob": 123,
"token": "<string>",
"top_logprobs": [
{
"bytes": [
123
],
"logprob": 123,
"token": "<string>"
}
]
}
],
"refusal": null
},
"message": {
"content": "<string>",
"refusal": "<string>",
"role": "assistant",
"annotations": [
{
"file": {
"content": [
{
"text": "Quarterly revenue grew 12%.",
"type": "text"
}
],
"hash": "abc123",
"name": "report.pdf"
},
"type": "url_citation"
}
],
"images": [
{
"image_url": {
"url": "<string>"
},
"type": "image_url"
}
],
"reasoning": "<string>",
"reasoning_details": [
{
"summary": "The model analyzed the problem by first identifying key constraints, then evaluating possible solutions...",
"type": "reasoning.summary"
}
],
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"index": 123,
"type": "function"
}
]
},
"native_finish_reason": "<string>"
}
],
"created": 123,
"id": "<string>",
"model": "<string>",
"object": "chat.completion",
"alignment": {
"calls": [
{
"call": 1,
"outcome": "allowed",
"rules": [
{
"applicable": true,
"broken": false,
"probability": 0.04
}
]
}
]
},
"debug": {
"echo_upstream_body": {},
"timings": {
"epoch_ms": 123,
"event": "adapter_request",
"start_ms": 123
}
},
"openrouter_metadata": {
"attempt": 1,
"endpoints": {
"available": [
{
"model": "openai/gpt-4o",
"provider": "OpenAI",
"selected": true
}
],
"total": 1
},
"generation_time": 2016,
"is_byok": false,
"region": "iad",
"requested": "openai/gpt-4o",
"strategy": "direct",
"summary": "available=1, selected=OpenAI"
},
"provider": "<string>",
"safeguard_results": [
{
"status": {
"tool_uses": {
"call_abc": {
"explanation": "[Data Exfiltration]",
"outcome": "flagged",
"type": "evaluated"
},
"call_def": {
"outcome": "not_flagged",
"type": "evaluated"
}
},
"type": "available"
},
"type": "dangerous_tool_use"
}
],
"service_tier": "<string>",
"system_fingerprint": "<string>",
"usage": {
"completion_tokens": 123,
"prompt_tokens": 123,
"total_tokens": 123,
"completion_tokens_details": {
"audio_tokens": 123,
"image_tokens": 123,
"reasoning_tokens": 123
},
"prompt_tokens_details": {
"audio_tokens": 123,
"cache_write_tokens": 123,
"cached_tokens": 123,
"file_tokens": 123,
"video_tokens": 123
},
"server_tool_use": {
"tool_calls_executed": 123,
"tool_calls_requested": 123,
"web_search_requests": 123
},
"server_tool_use_details": {
"tool_calls_executed": 123,
"tool_calls_requested": 123,
"web_search_requests": 123
}
}
},
"request_id": "<string>",
"status_code": 123
}
}
],
"status": "validating",
"usage": {
"completion_tokens": 123,
"prompt_tokens": 123,
"total_tokens": 123,
"cache_creation": {
"ephemeral_1h_input_tokens": 0,
"ephemeral_5m_input_tokens": 100
},
"completion_tokens_details": {
"audio_tokens": 123,
"image_tokens": 123,
"reasoning_tokens": 123
},
"cost": 123,
"cost_details": {
"upstream_inference_completions_cost": 0.0004,
"upstream_inference_cost": null,
"upstream_inference_prompt_cost": 0.0008
},
"is_byok": true,
"iterations": [
{
"cache_creation": null,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"input_tokens": 100,
"output_tokens": 50,
"type": "message"
}
],
"prompt_tokens_details": {
"audio_tokens": 123,
"cache_write_tokens": 123,
"cached_tokens": 123,
"file_tokens": 123,
"video_tokens": 123
},
"server_tool_use": {
"tool_calls_executed": 123,
"tool_calls_requested": 123,
"web_search_requests": 123
},
"service_tier": "<string>",
"speed": "standard"
},
"output": {
"uri": "gs://my-bucket/openrouter-batch/output/org_abc/batch_123/batch_123/prediction-model-2026-01-01T00:00:00.000000Z"
}
}{
"error": {
"code": 400,
"message": "No active workspace resolved for this request."
}
}{
"error": {
"code": 401,
"message": "No auth credentials found."
}
}{
"error": {
"code": 403,
"message": "Batch cancellation is not enabled for this organization."
}
}{
"error": {
"code": 404,
"message": "Batch not found."
}
}{
"error": {
"code": 409,
"message": "This batch has already ended and cannot be cancelled."
}
}{
"error": {
"code": 429,
"message": "Rate limit exceeded."
}
}{
"error": {
"code": 500,
"message": "Internal server error."
}
}{
"error": {
"code": 502,
"message": "Upstream batch-api is unavailable."
}
}{
"error": {
"code": 503,
"message": "Service Unavailable"
}
}Cancel a batch
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. OpenRouter returns no result rows for a cancelled batch, and the provider still charges for the requests that finished before the cancellation. 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.
curl --request POST \
--url https://openrouter.ai/api/v1/batches/{id}/cancel \
--header 'Authorization: Bearer <token>'import requests
url = "https://openrouter.ai/api/v1/batches/{id}/cancel"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://openrouter.ai/api/v1/batches/{id}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/batches/{id}/cancel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openrouter.ai/api/v1/batches/{id}/cancel"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/batches/{id}/cancel")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://openrouter.ai/api/v1/batches/{id}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"completion_window": "24h",
"created_at": 123,
"endpoint": "<string>",
"error": {
"message": "<string>"
},
"expires_at": 123,
"finalized_at": 123,
"id": "<string>",
"model": "<string>",
"object": "batch",
"provider": "<string>",
"request_counts": {
"completed": 123,
"failed": 123,
"total": 123
},
"results": [
{
"custom_id": "<string>",
"error": {
"message": "<string>",
"param": "<string>",
"type": "<string>",
"error_type": "rate_limit_exceeded"
},
"id": "<string>",
"response": {
"body": {
"choices": [
{
"finish_reason": "stop",
"index": 123,
"logprobs": {
"content": [
{
"bytes": [
123
],
"logprob": 123,
"token": "<string>",
"top_logprobs": [
{
"bytes": [
123
],
"logprob": 123,
"token": "<string>"
}
]
}
],
"refusal": null
},
"message": {
"content": "<string>",
"refusal": "<string>",
"role": "assistant",
"annotations": [
{
"file": {
"content": [
{
"text": "Quarterly revenue grew 12%.",
"type": "text"
}
],
"hash": "abc123",
"name": "report.pdf"
},
"type": "url_citation"
}
],
"images": [
{
"image_url": {
"url": "<string>"
},
"type": "image_url"
}
],
"reasoning": "<string>",
"reasoning_details": [
{
"summary": "The model analyzed the problem by first identifying key constraints, then evaluating possible solutions...",
"type": "reasoning.summary"
}
],
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"index": 123,
"type": "function"
}
]
},
"native_finish_reason": "<string>"
}
],
"created": 123,
"id": "<string>",
"model": "<string>",
"object": "chat.completion",
"alignment": {
"calls": [
{
"call": 1,
"outcome": "allowed",
"rules": [
{
"applicable": true,
"broken": false,
"probability": 0.04
}
]
}
]
},
"debug": {
"echo_upstream_body": {},
"timings": {
"epoch_ms": 123,
"event": "adapter_request",
"start_ms": 123
}
},
"openrouter_metadata": {
"attempt": 1,
"endpoints": {
"available": [
{
"model": "openai/gpt-4o",
"provider": "OpenAI",
"selected": true
}
],
"total": 1
},
"generation_time": 2016,
"is_byok": false,
"region": "iad",
"requested": "openai/gpt-4o",
"strategy": "direct",
"summary": "available=1, selected=OpenAI"
},
"provider": "<string>",
"safeguard_results": [
{
"status": {
"tool_uses": {
"call_abc": {
"explanation": "[Data Exfiltration]",
"outcome": "flagged",
"type": "evaluated"
},
"call_def": {
"outcome": "not_flagged",
"type": "evaluated"
}
},
"type": "available"
},
"type": "dangerous_tool_use"
}
],
"service_tier": "<string>",
"system_fingerprint": "<string>",
"usage": {
"completion_tokens": 123,
"prompt_tokens": 123,
"total_tokens": 123,
"completion_tokens_details": {
"audio_tokens": 123,
"image_tokens": 123,
"reasoning_tokens": 123
},
"prompt_tokens_details": {
"audio_tokens": 123,
"cache_write_tokens": 123,
"cached_tokens": 123,
"file_tokens": 123,
"video_tokens": 123
},
"server_tool_use": {
"tool_calls_executed": 123,
"tool_calls_requested": 123,
"web_search_requests": 123
},
"server_tool_use_details": {
"tool_calls_executed": 123,
"tool_calls_requested": 123,
"web_search_requests": 123
}
}
},
"request_id": "<string>",
"status_code": 123
}
}
],
"status": "validating",
"usage": {
"completion_tokens": 123,
"prompt_tokens": 123,
"total_tokens": 123,
"cache_creation": {
"ephemeral_1h_input_tokens": 0,
"ephemeral_5m_input_tokens": 100
},
"completion_tokens_details": {
"audio_tokens": 123,
"image_tokens": 123,
"reasoning_tokens": 123
},
"cost": 123,
"cost_details": {
"upstream_inference_completions_cost": 0.0004,
"upstream_inference_cost": null,
"upstream_inference_prompt_cost": 0.0008
},
"is_byok": true,
"iterations": [
{
"cache_creation": null,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"input_tokens": 100,
"output_tokens": 50,
"type": "message"
}
],
"prompt_tokens_details": {
"audio_tokens": 123,
"cache_write_tokens": 123,
"cached_tokens": 123,
"file_tokens": 123,
"video_tokens": 123
},
"server_tool_use": {
"tool_calls_executed": 123,
"tool_calls_requested": 123,
"web_search_requests": 123
},
"service_tier": "<string>",
"speed": "standard"
},
"output": {
"uri": "gs://my-bucket/openrouter-batch/output/org_abc/batch_123/batch_123/prediction-model-2026-01-01T00:00:00.000000Z"
}
}{
"error": {
"code": 400,
"message": "No active workspace resolved for this request."
}
}{
"error": {
"code": 401,
"message": "No auth credentials found."
}
}{
"error": {
"code": 403,
"message": "Batch cancellation is not enabled for this organization."
}
}{
"error": {
"code": 404,
"message": "Batch not found."
}
}{
"error": {
"code": 409,
"message": "This batch has already ended and cannot be cancelled."
}
}{
"error": {
"code": 429,
"message": "Rate limit exceeded."
}
}{
"error": {
"code": 500,
"message": "Internal server error."
}
}{
"error": {
"code": 502,
"message": "Upstream batch-api is unavailable."
}
}{
"error": {
"code": 503,
"message": "Service Unavailable"
}
}Path Parameters
Response
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.
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.
Was this page helpful?