Skip to content

fix: add missing API request headers for parity with Claude Code#109

Merged
griffinmartin merged 2 commits intomainfrom
fix/match-claude-code-request-fingerprint
Mar 31, 2026
Merged

fix: add missing API request headers for parity with Claude Code#109
griffinmartin merged 2 commits intomainfrom
fix/match-claude-code-request-fingerprint

Conversation

@griffinmartin
Copy link
Copy Markdown
Owner

@griffinmartin griffinmartin commented Mar 31, 2026

Summary

Adds missing HTTP headers to API requests to match what Claude Code sends, and bumps the version identifier to 2.1.88.

Changes

Headers added to buildRequestHeaders (src/index.ts)

  • anthropic-version: 2023-06-01 — API version header
  • x-client-request-id — unique UUID per request for tracing
  • X-Claude-Code-Session-Id — stable UUID per process lifetime (generated once via crypto.randomUUID() at module load, never persisted to disk)

User-Agent

  • User-agent kept as claude-cli/<v> (external, cli) to match Claude Code's primary API User-Agent (src/utils/http.ts:getUserAgent()). Note: claude-code/<v> is used upstream only for non-SDK HTTP requests (transports, telemetry), not for API calls.

Other fixes

  • ccVersion bumped from 2.1.80 to 2.1.88
  • Added validate-oauth and validate-oauth-dry Makefile targets

Tests (src/index.test.ts)

  • Asserts new headers are present with valid UUID format
  • Verifies x-client-request-id is unique per call
  • Verifies X-Claude-Code-Session-Id is stable across calls

All 161 tests pass. Lint and build clean.

Add headers that Claude Code sends on every API request:
- anthropic-version: 2023-06-01
- x-client-request-id: unique UUID per request
- X-Claude-Code-Session-Id: stable UUID per process lifetime

Also fixes user-agent format from 'claude-cli/<v> (external, cli)'
to 'claude-code/<v>' and bumps ccVersion to 2.1.88.

Adds validate-oauth and validate-oauth-dry Makefile targets.
@griffinmartin
Copy link
Copy Markdown
Owner Author

@minzique thoughts?

@griffinmartin griffinmartin added the enhancement New feature or request label Mar 31, 2026
@minzique
Copy link
Copy Markdown
Contributor

@minzique thoughts?

I will take a look later today and let you know https://minzique.github.io/claude-code-re/ should have all the request formats auto documented going forward but i need to double check it, the pipeline's only been running for a couple weeks

@griffinmartin
Copy link
Copy Markdown
Owner Author

I will take a look later today and let you know https://minzique.github.io/claude-code-re/ should have all the request formats auto documented going forward but i need to double check it, the pipeline's only been running for a couple weeks

@minzique Thanks for the resource.

An hour after I opened this and went through the effort to decompile the bun binary the cc source code leaked 🤣

Claude Code's API User-Agent is 'claude-cli/<v> (external, cli)', not
'claude-code/<v>'. The latter is used for non-SDK HTTP requests only
(transports, telemetry). Revert to the correct format.
@griffinmartin griffinmartin merged commit 5d6455d into main Mar 31, 2026
5 checks passed
@griffinmartin griffinmartin deleted the fix/match-claude-code-request-fingerprint branch March 31, 2026 20:24
griffinmartin pushed a commit that referenced this pull request Apr 3, 2026
## Summary

Fixes #119 — API 400 for `claude-haiku-4-5-20251001`.

- Adds a `haiku` model override in `model-config.ts` to exclude the
`interleaved-thinking-2025-05-14` beta flag from haiku requests
- Haiku 4.5 has limited extended thinking support (no adaptive thinking)
and does not benefit from this beta — excluding it reduces the surface
for API validation errors

## Root cause analysis

The reported 400 error on plugin v1.3.0 was primarily caused by:

1. **Malformed billing header** — v1.3.0 used `cch=00000` (hardcoded)
with the model ID embedded in the version string
(`cc_version=2.1.80.claude-haiku-4-5-20251001`), which doesn't match the
expected `cc_version=X.Y.Z.{3-char-hash}` format. Fixed in v1.4.3
(#116).
2. **Missing API headers** — `anthropic-version`, `x-client-request-id`,
and `X-Claude-Code-Session-Id` were absent. Fixed in v1.4.2 (#109).

This PR adds a defensive fix on top: excluding the
`interleaved-thinking-2025-05-14` beta for haiku, since Claude Code CLI
historically sent fewer betas to haiku (ref: `claude-code` v2.1.78
changelog) and the interleaved-thinking-with-tools behavior is not
well-documented for haiku models.

## Changes

- `src/model-config.ts` — Add `haiku` entry to `modelOverrides`
excluding `interleaved-thinking-2025-05-14`
- `src/betas.test.ts` — Update haiku test to verify excluded betas are
rejected; add dedicated test for both `claude-haiku-4-5` and
`claude-haiku-4-5-20251001`

## Test results

```
191 tests, 0 failures
lint: clean
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants