Skip to content

fix: add LiteLLM Responses API attribute extraction for ResponseAPIResponse format#1412

Closed
icohangar-ops wants to merge 1 commit into
AgentOps-AI:mainfrom
icohangar-ops:fix/litellm-responses-api
Closed

fix: add LiteLLM Responses API attribute extraction for ResponseAPIResponse format#1412
icohangar-ops wants to merge 1 commit into
AgentOps-AI:mainfrom
icohangar-ops:fix/litellm-responses-api

Conversation

@icohangar-ops

Copy link
Copy Markdown

Description

This PR adds support for the LiteLLM Responses API response format (ResponsesAPIResponse) to the AgentOps instrumentation layer.

Problem

When using litellm.responses() (LiteLLM's /v1/responses endpoint), the returned objects have a different structure than ModelResponse (chat completions). Specifically:

  • output instead of choices
  • usage with input_tokens/output_tokens instead of prompt_tokens/completion_tokens/total_tokens
  • No choices[].message structure

LiteLLM's own OpenTelemetry integration (which success_callback = ["agentops"] uses) assumes chat completion format and silently fails to extract attributes from ResponsesAPIResponse objects.

Changes

  1. New LiteLLM Responses API wrapper (agentops/instrumentation/providers/litellm/wrappers/responses.py):

    • is_responses_api_response(): Detect if a response object is a ResponsesAPIResponse
    • handle_litellm_responses_attributes(): Extract OTel span attributes from ResponsesAPIResponse objects, normalizing output -> completions and input_tokens/output_tokens -> token counts
  2. Updated canary test: Added documentation noting the ResponsesAPIResponse format differences

Related

Closes #1079 -- adds building block for LiteLLM Responses API tracking support.

Notes

The actual fix for LiteLLM's success_callback = ["agentops"] path needs changes in LiteLLM's opentelemetry.py (_handle_success, set_attributes, _record_metrics) to handle ResponsesAPIResponse objects. This PR adds the AgentOps-side attribute extraction helpers that LiteLLM's callback can use when processing Responses API responses.

Adds the missing @record_function decorator to the legacy module with
a proper deprecation warning. The decorator creates a trace span using
the new v4 instrumentation system.

Fixes #1076
@icohangar-ops icohangar-ops closed this by deleting the head repository Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LiteLLM + AgentOps integration: Provider-specific tracking issue with Anthropic models

2 participants