Skip to content

Anthropic /v1/messages -> Responses API adapter (Claude Code on Codex) #17

@HXYerror

Description

@HXYerror

Part of #1. Depends on #3, #4, #5.

Goal

Let a Claude Code / Anthropic SDK client hit POST /v1/messages and have copilot-api dispatch to upstream /responses (instead of /chat/completions) when the resolved model is in the codex / o-pro family. This is the path that lets Claude Code use Copilot's gpt-5.3-codex / gpt-5.1-codex-max.

Current state

src/routes/messages/ only translates Anthropic Messages to Chat Completions, never to Responses. Once #4 lands and a codex model is resolved, this code path errors out because chat/completions can't reach codex on the upstream.

Tasks

  • Decide dispatch policy in src/routes/messages/route.ts:
    • Resolve target model
    • If endpoint === 'responses' only → call new messagesToResponses(...)
    • Else → existing chat-completions translator (no change)
  • Add src/routes/messages/responses-translation.ts:
    • Anthropic messages → Responses input items
    • Anthropic system → Responses instructions
    • Anthropic tools → Responses tools (function-call shape)
    • Anthropic tool_choice → Responses tool_choice
    • Anthropic thinking { type: 'enabled', budget_tokens: N } → Responses reasoning: { effort: tier(N), summary: 'auto' }
      • tier mapping (match litellm): ≥10000 → 'high', ≥5000 → 'medium', ≥2000 → 'low', else 'minimal'
    • Anthropic tool_use block in history → Responses function_call input item
    • Anthropic tool_result block in history → Responses function_call_output input item
  • Add src/routes/messages/responses-stream-translation.ts:
  • Round-trip reasoning items: when the next turn arrives with Anthropic thinking blocks containing signature (encrypted_content holder), forward them as Responses reasoning items in input (cross-link Model-to-endpoint routing (chat vs responses) #5)

Acceptance criteria

  • POST /v1/messages with model=gpt-5.3-codex works end-to-end against Copilot upstream
  • Streaming returns Anthropic-shaped SSE that Claude Code understands
  • Two-turn agent loop preserves reasoning context (no "encrypted content could not be verified" errors)
  • Existing Anthropic→Chat Completions tests still pass for non-codex models

File pointers

  • src/routes/messages/route.ts:10–18
  • src/routes/messages/non-stream-translation.ts — reference for Anthropic→OpenAI translation
  • src/routes/messages/stream-translation.ts — reference for streaming state machine
  • litellm reference: litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py (LiteLLMAnthropicToResponsesAPIAdapter)
  • litellm PR #22448 — thinking_blocks ↔ reasoning round-trip

Metadata

Metadata

Assignees

No one assigned

    Labels

    anthropicAnthropic Messages API compatibilityreasoningReasoning / thinking / encrypted_contentresponses-apiOpenAI /v1/responses API support

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions