OpenAIAdapter extracts telemetry from OpenAI responses — model name, token counts, and cost in USD — and passes them directly into agentvista.record() or a traced run. The adapter works with both the Chat Completions API (client.chat.completions.create) and the Responses API (client.responses.create), auto-detecting the response shape. Cost is calculated automatically from the model name using AgentVista’s built-in pricing table.
Setup
1
Install the SDK with the OpenAI extra
agentvista along with the openai package.2
Initialize AgentVista
Call
agentvista.init() once at application startup with your API key.3
Import the adapter
Usage examples
- Basic
- With tracing
- Responses API
Use
adapter.extract() on any OpenAI response and unpack the result directly into agentvista.record().adapter.extract() returns a dict with any of these keys present:The adapter automatically detects whether the response uses
prompt_tokens / completion_tokens (Chat Completions) or input_tokens / output_tokens (Responses API) and normalizes both into the same output shape.Supported models
Cost calculation is automatic for the following OpenAI models. If your model is not listed,
cost_usd will be absent from the extracted telemetry; all other fields (tokens, model name) are still captured.Models that support prompt caching (
gpt-5.4, gpt-5.4-mini, gpt-5.4-nano, gpt-5, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, gpt-4o, gpt-4o-mini, o3, o4-mini) automatically detect cached token counts from the response and apply the correct cached read rate when calculating cost.