Skip to main content

Documentation Index

Fetch the complete documentation index at: https://portkey-docs-feat-claude-platform-docs.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Self-hosted deployments require Enterprise Gateway v2.6.1+.
Portkey exposes Anthropic’s Message Batches API for Claude Platform on AWS through the unified OpenAI-compatible /v1/batches endpoints. All five batch operations — create, retrieve, cancel, list, and get output — are supported, enabling large asynchronous Claude jobs at 50% lower cost. Use batches for offline workloads like nightly evals, bulk summarization, or dataset grading.

Supported Endpoints

Gateway EndpointAnthropic UpstreamOperation
POST /v1/batchesPOST /v1/messages/batchesCreate a batch
GET /v1/batches/{batch_id}GET /v1/messages/batches/{batch_id}Retrieve a batch
POST /v1/batches/{batch_id}/cancelPOST /v1/messages/batches/{batch_id}/cancelCancel a batch
GET /v1/batchesGET /v1/messages/batchesList batches
GET /v1/batches/{batch_id}/outputStreams from results_urlGet batch output

Request Format

Unlike OpenAI’s file-based batches, Anthropic batch creation uses an inline requests[] array — there is no input_file_id. Each item carries a custom_id and a params object containing the standard Messages API payload.
{
  "requests": [
    {
      "custom_id": "req-1",
      "params": {
        "model": "claude-sonnet-4-6",
        "max_tokens": 1024,
        "messages": [
          { "role": "user", "content": "Hello" }
        ]
      }
    }
  ]
}

Create a Batch

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@claude-platform-aws-provider"
)

batch = portkey.post(
    "/batches",
    requests=[
        {
            "custom_id": "req-1",
            "params": {
                "model": "claude-sonnet-4-6",
                "max_tokens": 1024,
                "messages": [{"role": "user", "content": "Hello"}]
            }
        }
    ]
)

print(batch)

Retrieve a Batch

Returns the OpenAI-compatible Batch object. Once processing completes, the response includes results_url from Anthropic.
from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@claude-platform-aws-provider"
)

batch = portkey.batches.retrieve(batch_id="<batch_id>")

print(batch)

List Batches

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@claude-platform-aws-provider"
)

batches = portkey.batches.list()

print(batches)

Cancel a Batch

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@claude-platform-aws-provider"
)

cancelled = portkey.batches.cancel(batch_id="<batch_id>")

print(cancelled)

Get Batch Output

Before streaming results, Portkey retrieves the batch metadata and verifies that processing_status === 'ended'. It then fetches from Anthropic’s results_url, generating fresh SigV4-signed headers for the output URL. The response body is streamed back as JSONL in Anthropic’s native format.
curl https://api.portkey.ai/v1/batches/<batch_id>/output \
  -H "x-portkey-api-key: $PORTKEY_API_KEY" \
  -H "x-portkey-provider: @claude-platform-aws-provider"
A typical output line:
{
  "custom_id": "req-1",
  "result": {
    "type": "succeeded",
    "message": {
      "id": "msg_01XYZ...",
      "type": "message",
      "role": "assistant",
      "content": [{ "type": "text", "text": "Hello! How can I help?" }],
      "model": "claude-sonnet-4-6",
      "stop_reason": "end_turn",
      "usage": { "input_tokens": 10, "output_tokens": 12 }
    }
  }
}

Response Format

createBatch, retrieveBatch, cancelBatch, and listBatches return the OpenAI Batch shape so existing OpenAI tooling works unchanged:
  • object: "batch" and endpoint: "/v1/batches" on every batch record
  • status values normalized to OpenAI-compatible strings (validating, in_progress, finalizing, completed, failed, cancelling, cancelled, expired)
  • Timestamps converted from Anthropic’s ISO 8601 to Unix epoch seconds
  • Request counts mapped: succeeded → completed, errored → failed
  • retrieveBatch surfaces results_url from the Anthropic response when the batch has finished processing
getBatchOutput streams the raw Anthropic-native JSONL for full Claude response fidelity (content blocks, tool use, stop reasons, usage).

See Also

Last modified on May 25, 2026