Skip to content

[bot] Anthropic Messages Batch API (client.messages.batches) not instrumented #169

@braintrust-bot

Description

@braintrust-bot

Summary

The Anthropic Ruby SDK provides client.messages.batches for submitting multiple message requests for asynchronous Claude inference. This is a generative AI execution surface — each item in a batch runs the Claude model and produces a completion — but it is not instrumented. The SDK currently instruments the synchronous (messages.create) and streaming (messages.stream) paths for Anthropic, but not the batch path.

What is missing

The Messages Batch API (Anthropic::Resources::Messages::Batches) exposes these generative execution methods:

batches.create(requests: [...])

Submits up to 10,000 message requests for asynchronous processing. Each request item is a full MessagesCreateParams with a caller-provided custom_id. Returns a MessageBatch with a processing_status and a results_url.

batch = client.messages.batches.create(
  requests: [
    { custom_id: "req-1", params: { model: "claude-opus-4-5", max_tokens: 1024, messages: [...] } },
    { custom_id: "req-2", params: { model: "claude-opus-4-5", max_tokens: 1024, messages: [...] } }
  ]
)

batches.results(batch_id)

Streams back the completed results once the batch finishes processing. Each result item contains a custom_id, a result type (succeeded, errored, expired), and for successes a full Message response object including content, usage tokens, model, and stop reason.

What instrumentation should capture

Because batch execution is asynchronous, tracing requires instrumenting both sides:

At submit time (batches.create):

  • Each request item as input (messages, system prompt, model, max_tokens, tools, tool_choice, etc.)
  • Batch-level metadata: total request count, model(s), custom IDs

At result time (batches.results):

  • Each result item's output (content blocks, stop_reason)
  • Per-item token metrics (input_tokens, output_tokens, cache tokens) from the Message usage object
  • Per-item success/error status

A reasonable implementation is to emit one Braintrust span per batch result item when results are retrieved, carrying the original input from the corresponding custom_id request, matching the pattern the sync Messages integration already uses per-call.

Braintrust docs status

not_found — The Braintrust Anthropic integration docs at https://www.braintrust.dev/docs/integrations/ai-providers/anthropic and the Ruby SDK docs at https://www.braintrust.dev/docs do not mention batch API tracing. No Ruby-side batch instrumentation is documented anywhere in Braintrust's published docs.

Upstream sources

Local repo files inspected

  • lib/braintrust/contrib/anthropic/patcher.rb — defines MessagesPatcher and BetaMessagesPatcher; no BatchesPatcher
  • lib/braintrust/contrib/anthropic/instrumentation/messages.rb — wraps create() and stream() on Anthropic::Resources::Messages; no batches wrapper
  • lib/braintrust/contrib/anthropic/instrumentation/beta_messages.rb — wraps create() and stream() on beta messages; no batches wrapper
  • Grep for batches, MessageBatch, batch_id, custom_id across lib/braintrust/ returns zero matches

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions