Skip to content

feat: Route dispatch — detect native-capable models, branch to pass-through #40

@HXYerror

Description

@HXYerror

Part of #38. Depends on #39.

Background

src/routes/messages/route.ts currently routes all /v1/messages requests through the OpenAI translation layer. We need to branch: Claude 4.5+ models → native pass-through, everything else → existing translation.

Goal

Add model-based dispatch at the top of the messages handler so native-capable Claude models skip translation entirely.

Tasks

  • In src/routes/messages/handler.ts (or route.ts), after parsing the request body:
    import { NATIVE_ANTHROPIC_MODELS, createMessagesNative } from "~/services/copilot/create-messages-native"
    
    const model = resolveAlias(payload.model)  // after F1.B lands; for now use payload.model
    if (NATIVE_ANTHROPIC_MODELS.has(model)) {
      // native pass-through path
      return createMessagesNative(payload, c)
    }
    // existing translation path (non-stream-translation.ts → /chat/completions)
  • Model resolution: apply alias resolution before the native check (so client can use alias "sonnet-4.5" → resolves to "claude-sonnet-4.5" → hits native path)
  • If NATIVE_ANTHROPIC_MODELS.has(model) is false but model is Claude-family: fall through to translation (handles legacy claude-sonnet-4 on the translation path)
  • Log the dispatch decision at --verbose level: "[messages] native pass-through for claude-sonnet-4.5" vs "[messages] translation path for claude-sonnet-4"
  • Keep /v1/messages/count_tokens on the existing heuristic path (no native count_tokens endpoint on Copilot)

Acceptance criteria

  • POST /v1/messages {model: "claude-sonnet-4.5", thinking: {...}} uses native path — confirmed by thinking blocks in response
  • POST /v1/messages {model: "claude-sonnet-4"} uses translation path — confirmed by no thinking blocks (not supported on translation path) and OpenAI-style upstream call visible in --verbose
  • No regression for non-Claude models (gpt-4o etc.) on the translation path

File pointers

Metadata

Metadata

Assignees

No one assigned

    Labels

    anthropicAnthropic Messages API compatibility

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions