You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
openrouter: trace alpha.extractions.create as extraction spans (1.3.106+) #1043
openrouter (Python SDK) 1.3.106 adds an alpha Extractions endpoint: client.alpha.extractions.create(...) / create_async(...) → POST /api/alpha/extractions. It isn't traced. braintrust-spec recently defined a dedicated extraction span type (spec commit), so this is a well-specified addition.
Found while reviewing the weekly dependency bump in #1037 (openrouter 1.3.79 → 1.3.106).
Upstream API (openrouter 1.3.106)
Module:openrouter/extractions.py, class Extractions, methods create and create_async. It's reached through openrouter/alpha.py (Alpha.extractions). Upstream marks it "Alpha: the shape is not stable."
Request:
required: fields (map of field name → typed field spec), model, state (text);
Usage:ExtractionsUsage has input_tokens, output_tokens, and optional cost, image_tokens, passes, schema_tokens, state_tokens.
Our code
Patchers:patchers.py only covers Chat.send[_async], Embeddings.generate[_async], Responses.send[_async] and BetaResponses.send[_async]. They're registered in integration.py.
Span payload: follow the spec rather than inventing a shape:
span_attributes.type: "extraction", one span per call, not per field;
input = {state, fields: [...]}, converting the fields map into an array with id = key and preserving order, plus images / reference_date / allowlisted options;
output.answers as an array keyed by id;
metadata.provider / metadata.model taken from the response model, falling back to the request;
canonical token/cost metrics. The spec has notes on input-only usage, and says not to invent metrics for schema_tokens / state_tokens; put those in metadata.
Precedent:integrations/question.py handles decision spans. Check whether extraction span shaping should live in a similar shared helper so other providers can reuse it.
Testing
Add VCR tests to test_openrouter.py for sync and async alpha.extractions.create, recorded with the local OPENROUTER_API_KEY. Pick an extraction-capable model.
Gate on openrouter.extractions existing: the 0.6.0 matrix pin doesn't have it.
Run cd py && nox -s "test_openrouter(latest)" and "test_openrouter(0.6.0)".
The endpoint is alpha, so keep the wrapper defensive about missing or renamed fields.
Activity
AbhiPrasad commentedon Nov 2, 2026
we'll wait till this gets out of alpha to trace