Skip to content

[bot] Anthropic Message Batches API not instrumented #146

@braintrust-bot

Description

@braintrust-bot

What instrumentation is missing

The Anthropic SDK (anthropic-sdk-go v1.23.0) exposes a Message Batches API for submitting multiple message requests for asynchronous batch processing. The anthropicRouter in trace/contrib/anthropic/traceanthropic.go only matches the exact path /v1/messages:

func anthropicRouter(cfg *middlewareConfig, path string) internal.MiddlewareTracer {
    if path == "/v1/messages" {
        return newMessagesTracer(cfg)
    }
    return nil
}

The Message Batches API paths are:

Method Path Purpose
POST /v1/messages/batches Submit a batch of message requests
GET /v1/messages/batches/{id} Poll batch status
GET /v1/messages/batches/{id}/results Stream back per-request results

None of these match, so all batch LLM calls are silently untraced.

What could be traced

Batch creation (POST /v1/messages/batches): The request body is an array of requests[], each containing a custom_id and a full params object (model, messages, max_tokens, tools, etc.) — identical to the fields already captured by messagesTracer. A dedicated tracer could record:

  • braintrust.input_json: the array of message requests
  • braintrust.metadata: model, params from the first request (or per-request summary)

Batch results (GET /v1/messages/batches/{id}/results): The response body is an NDJSON stream where each line contains a custom_id and a full message result (including usage). This maps directly to the fields already parsed by parseUsageTokens().

Each entry in the results stream is structurally a complete Messages API response — the same token fields (input_tokens, output_tokens, cache_creation_input_tokens, cache_read_input_tokens) that parseUsageTokens() already handles.

SDK access point

// Create a batch
batch, err := client.Beta.Messages.Batches.New(ctx, anthropic.BetaMessageBatchNewParams{
    Requests: []anthropic.BetaMessageBatchNewParamsRequests{...},
})

// Stream results
stream := client.Beta.Messages.Batches.ResultsStreaming(ctx, batch.ID)
for stream.Next() {
    result := stream.Current()  // BetaMessageBatchIndividualResponse
}

Braintrust docs status

unclear — The Braintrust Anthropic integration guide covers messages.create (including streaming, tool use, and prompt caching) but does not mention Message Batches. No evidence this surface is excluded by design.

Source: https://www.braintrust.dev/docs/integrations/ai-providers/anthropic

Upstream sources

Local repo files inspected

  • trace/contrib/anthropic/traceanthropic.goanthropicRouter (line 105): exact-match on /v1/messages, no coverage for /v1/messages/batches or /v1/messages/batches/{id}/results
  • trace/contrib/anthropic/messages.gomessagesTracer and parseUsageTokens: reference pattern reusable for batch results
  • trace/contrib/anthropic/go.modanthropic-sdk-go v1.23.0 (Message Batches is available in this version)
  • trace/contrib/anthropic/traceanthropic_test.go — no batch-related tests

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