Skip to content

[bot] Streaming aggregator drops service_tier and system_fingerprint from OpenAI Chat Completions chunks #53

@braintrust-bot

Description

@braintrust-bot

Summary

The BraintrustStream streaming aggregator only extracts model from OpenAI Chat Completions streaming chunks, silently dropping service_tier and system_fingerprint. These are documented fields on every ChatCompletionChunk object. The StreamMetadata type already has an extra: HashMap<String, Value> that could hold these values, but the aggregation logic always passes an empty map.

What is missing

OpenAI Chat Completions streaming chunks include these fields alongside model:

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion.chunk",
  "created": 1694268190,
  "model": "gpt-4o",
  "service_tier": "scale",
  "system_fingerprint": "fp_44709d6fcb",
  "choices": [...]
}

Currently in the SDK:

  1. StreamChunk (src/stream.rs:687-694) only deserializes three fields — model, choices, and usage. The service_tier, system_fingerprint, id, and created fields are silently discarded during serde deserialization.

  2. aggregate() (src/stream.rs:983) creates metadata with an always-empty extra map:

    let metadata = StreamMetadata::new(model, HashMap::new());

    The StreamMetadata type already supports extra fields via its extra: HashMap<String, Value>, but the aggregation logic never populates it.

Why these fields matter

  • service_tier ("default" | "scale" | "flex") — determines which pricing tier processed the request. Scale tier is ~2x the cost of default; flex tier is ~50% cheaper. Without this field, cost attribution in Braintrust spans may use incorrect pricing assumptions. This is especially relevant as OpenAI's newer flex tier becomes more widely used.
  • system_fingerprint (string) — identifies the backend configuration the model ran with. Used alongside the seed parameter to detect when backend changes affect determinism. Important for reproducibility analysis and debugging behavior regressions.

Braintrust docs status

unclear — Braintrust's OpenAI integration page documents automatic token metrics capture but does not explicitly mention service_tier or system_fingerprint capture from streaming responses. The tracing guide states that "Model parameters (model name, temperature, etc.)" and "Token usage and costs" are captured, but does not enumerate response-level metadata fields.

Upstream sources

Relationship to existing issues

Local files inspected

  • src/stream.rs:687-694StreamChunk struct only has model, choices, usage fields
  • src/stream.rs:983aggregate() always creates StreamMetadata::new(model, HashMap::new())
  • src/stream.rs:488-535StreamMetadata struct has extra: HashMap<String, Value> that could hold these values
  • src/stream.rs:840-1009 — full aggregate() function; no code path reads service_tier, system_fingerprint, id, or created from chunks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions