Skip to content

Responses streams report zero input usage and mask context overflow #10

Description

@LPFchan

Duplicate Check / 重复检查

  • I have searched existing issues and this is not a duplicate / 我已搜索现有 issue,确认非重复

Claudex Version

0.2.4

Operating System

Linux (x86_64)

Description / 描述

The OpenAI Responses streaming translator always starts Anthropic usage at input_tokens: 0 and only forwards output_tokens at the end. Claude Code consequently records every translated assistant turn with zero input tokens, so its context accounting cannot trigger proactive auto-compaction reliably.

When the Responses backend eventually emits response.failed with error.code: context_length_exceeded, upstream Claudex silently finalizes the stream as a normal end_turn. Newer error-aware variants that classify it as a generic api_error can instead make Claude Code enter its non-streaming fallback; ChatGPT's Codex Responses endpoint then rejects that fallback with Stream must be set to true, masking the original context overflow.

This is distinct from #5 / #6: those cover the proxy's HTTP request-body limit, while this report concerns translated token usage and terminal SSE error semantics.

Steps to Reproduce / 复现步骤

  1. Configure an OpenAIResponses profile, such as ChatGPT Codex OAuth.
  2. Run a long Claude Code session through Claudex until its upstream context window is full.
  3. Inspect Claude Code's transcript usage: translated assistant turns report input_tokens: 0.
  4. Observe the upstream response.failed event with context_length_exceeded; the client does not receive a recognizable Anthropic invalid_request_error and does not compact normally.

Expected Behavior / 预期行为

  • Terminal Responses usage is propagated through the final Anthropic message_delta, including input and cached-input accounting.
  • context_length_exceeded becomes one terminal Anthropic invalid_request_error with no fabricated message_stop, allowing Claude Code's context-limit recovery to run.

Actual Behavior / 实际行为

  • Input usage remains zero for the entire session.
  • Context overflow is ignored or masked by a secondary non-streaming error.

Configuration / 配置

[[profiles]]
provider_type = "OpenAIResponses"
auth_type = "oauth"
oauth_provider = "chatgpt"

Proxy Logs / 代理日志

streaming=true model=<model>
Responses stream terminated with an error upstream_code=context_length_exceeded
streaming=false model=<model>
status=400 Bad Request body={"detail":"Stream must be set to true"}

Additional Context / 补充信息

Anthropic's TypeScript SDK merges input_tokens, cache_creation_input_tokens, and cache_read_input_tokens supplied in message_delta.usage, so the terminal Responses usage can be forwarded without buffering the stream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions