keh4l
b5467d610a
fix(gateway): apply full Claude Code mimicry on /chat/completions and /responses
...
Before: the OpenAI-compat forwarders only called injectClaudeCodePrompt,
which prepends the Claude Code banner but leaves the rest of the body
in its original non-Claude-Code shape. The codebase already admits this
is insufficient (see the comment on rewriteSystemForNonClaudeCode in
gateway_service.go: "仅前置追加 Claude Code 提示词无法通过检测").
Effect: OAuth accounts served through /v1/chat/completions or /v1/responses
were detected as third-party apps and bled plan quota with:
Third-party apps now draw from your extra usage, not your plan limits.
Fix:
- apicompat.AnthropicRequest: add Metadata json.RawMessage so metadata
survives the OpenAI->Anthropic->Marshal round trip; without it the
downstream rewrite has no user_id to work with.
- service: extract applyClaudeCodeOAuthMimicryToBody, a ParsedRequest-free
variant of the /v1/messages mimicry pipeline
(rewriteSystemForNonClaudeCode + normalizeClaudeOAuthRequestBody +
metadata.user_id injection) so the OpenAI-compat forwarders can reuse it.
- service: add buildOAuthMetadataUserIDFromBody + hashBodyForSessionSeed
for the same reason (no ParsedRequest at the call site).
- ForwardAsChatCompletions / ForwardAsResponses: replace the 3-line
prompt-prepend with the full mimicry pipeline.
- applyClaudeCodeMimicHeaders: set x-client-request-id per-request
(real Claude CLI always does); missing/duplicated values are one more
third-party fingerprint signal.
No change to the native /v1/messages path: it already called the full
pipeline, we only lift those helpers into a reusable function.
Tests:
- go build ./... passes
- go test ./internal/service/... ./internal/pkg/apicompat/... passes
- lsp_diagnostics clean on all touched files
- pre-existing failures in internal/config are unrelated (env-sensitive
tests that also fail on upstream main)
2026-04-24 23:16:32 +08:00
..
2026-04-19 18:45:04 +08:00
2026-04-23 21:40:58 +08:00
2026-04-23 21:40:58 +08:00
2026-04-14 16:26:46 +08:00
2026-04-14 16:26:46 +08:00
2026-04-05 17:11:01 +08:00
2026-04-23 12:44:44 +08:00
2026-04-22 18:12:03 +08:00
2026-04-23 12:44:44 +08:00
2026-04-15 15:29:52 +08:00
2026-04-15 15:29:52 +08:00
2026-04-14 09:32:11 +08:00
2026-04-23 12:44:44 +08:00
2026-04-22 00:54:38 +08:00
2026-04-22 13:19:28 +08:00
2026-04-23 21:40:58 +08:00
2026-04-14 09:15:49 +08:00
2026-04-22 00:54:38 +08:00
2026-04-22 00:54:38 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-05 17:11:01 +08:00
2026-04-23 16:34:37 +08:00
2026-04-09 18:14:28 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-21 09:53:15 -07:00
2026-04-21 09:53:15 -07:00
2026-04-21 09:53:15 -07:00
2026-04-04 14:32:26 +08:00
2026-04-04 14:32:26 +08:00
2026-04-04 14:32:26 +08:00
2026-04-05 17:21:36 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-22 14:57:47 +08:00
2026-04-22 14:56:56 +08:00
2026-04-22 14:56:56 +08:00
2026-04-21 09:53:15 -07:00
2026-04-22 14:56:56 +08:00
2026-04-22 14:56:56 +08:00
2026-04-22 14:57:47 +08:00
2026-04-21 08:28:48 +08:00
2026-04-23 21:40:58 +08:00
2026-04-23 16:34:37 +08:00
2026-04-14 09:36:40 +08:00
2026-04-14 09:36:26 +08:00
2026-04-14 09:31:45 +08:00
2026-04-14 09:35:20 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-17 22:06:32 +08:00
2026-04-17 22:06:32 +08:00
2026-04-20 22:01:41 +08:00
2026-04-17 22:06:32 +08:00
2026-04-23 17:28:01 +08:00
2026-04-23 00:45:10 +08:00
2026-04-23 00:45:10 +08:00
2026-04-20 23:38:59 +08:00
2026-04-20 20:21:02 +08:00
2026-04-21 14:14:49 +08:00
2026-04-21 14:14:49 +08:00
2026-04-22 19:17:08 +08:00
2026-04-22 20:08:31 +08:00
2026-04-22 20:08:31 +08:00
2026-04-22 19:17:08 +08:00
2026-04-20 20:21:02 +08:00
2026-04-21 14:39:19 +08:00
2026-04-21 14:39:19 +08:00
2026-04-21 14:14:49 +08:00
2026-04-20 20:21:02 +08:00
2026-04-23 00:45:10 +08:00
2026-04-23 00:45:10 +08:00
2026-04-23 00:45:10 +08:00
2026-04-14 09:20:39 +08:00
2026-04-23 00:45:10 +08:00
2026-04-23 21:40:58 +08:00
2026-04-14 17:35:27 +08:00
2026-04-23 22:30:45 +08:00
2026-04-14 10:18:39 +08:00
2026-04-23 21:40:58 +08:00
2026-04-23 21:40:58 +08:00
2026-04-08 14:06:06 +08:00
2026-04-08 16:11:19 +08:00
2026-04-08 16:23:02 +08:00
2026-04-04 11:25:01 +08:00
2026-04-04 11:25:01 +08:00
2026-04-24 23:16:32 +08:00
2026-04-24 23:16:32 +08:00
2026-04-23 21:40:58 +08:00
2026-04-23 21:40:58 +08:00
2026-04-08 14:06:06 +08:00
2026-04-14 09:23:02 +08:00
2026-04-19 18:05:25 +08:00
2026-04-19 18:05:25 +08:00
2026-04-05 17:11:01 +08:00
2026-04-17 22:06:32 +08:00
2026-04-24 23:16:32 +08:00
2026-04-14 09:36:40 +08:00
2026-04-14 17:35:27 +08:00
2026-04-16 01:53:22 +08:00
2026-04-23 21:40:58 +08:00
2026-04-23 16:34:37 +08:00
2026-04-24 23:16:32 +08:00
2026-04-23 00:45:10 +08:00
2026-04-22 12:30:08 +08:00
2026-04-14 09:36:40 +08:00
2026-04-14 09:35:20 +08:00
2026-04-23 12:58:13 +08:00
2026-04-21 13:50:55 +08:00
2026-04-20 17:39:57 +08:00
2026-04-23 21:40:58 +08:00
2026-04-04 11:25:01 +08:00
2026-04-09 12:29:49 +08:00
2026-04-23 15:13:57 +00:00
2026-04-23 15:13:57 +00:00
2026-04-09 12:29:49 +08:00
2026-04-20 22:01:41 +08:00
2026-04-11 22:48:45 +08:00
2026-04-23 12:58:13 +08:00
2026-04-21 13:56:02 +08:00
2026-04-23 21:40:58 +08:00
2026-04-15 23:56:56 +08:00
2026-04-23 15:09:47 +08:00
2026-04-23 15:13:57 +00:00
2026-04-24 08:58:51 +08:00
2026-04-23 16:30:43 +08:00
2026-04-23 21:40:58 +08:00
2026-04-23 21:40:58 +08:00
2026-04-09 12:29:28 +08:00
2026-04-09 12:29:28 +08:00
2026-04-23 21:40:58 +08:00
2026-04-04 14:07:19 +08:00
2026-04-05 17:11:01 +08:00
2026-04-05 17:21:36 +08:00
2026-04-05 17:11:01 +08:00
2026-04-05 17:11:01 +08:00
2026-04-14 20:13:59 +08:00
2026-04-07 11:40:41 +03:00
2026-04-14 09:23:02 +08:00
2026-04-15 15:29:52 +08:00
2026-04-21 10:10:56 +08:00
2026-04-14 17:35:27 +08:00
2026-04-14 17:35:27 +08:00
2026-04-22 12:30:08 +08:00
2026-04-09 17:49:02 +08:00
2026-04-14 17:35:27 +08:00
2026-04-15 01:27:24 +08:00
2026-04-22 13:18:10 +08:00
2026-04-22 13:18:10 +08:00
2026-04-14 09:36:26 +08:00
2026-04-14 17:35:27 +08:00
2026-04-22 14:57:16 +08:00
2026-04-22 14:57:16 +08:00
2026-04-21 23:20:37 +08:00
2026-04-21 23:20:37 +08:00
2026-04-23 19:22:43 +08:00
2026-04-22 10:26:22 +08:00
2026-04-23 18:33:28 +08:00
2026-04-11 13:16:35 +08:00
2026-04-22 11:28:58 +08:00
2026-04-22 18:01:51 +08:00
2026-04-22 18:01:51 +08:00
2026-04-21 13:35:54 +08:00
2026-04-21 13:35:54 +08:00
2026-04-22 12:30:17 +08:00
2026-04-22 11:17:23 +08:00
2026-04-21 13:35:54 +08:00
2026-04-21 13:35:54 +08:00
2026-04-22 12:30:17 +08:00
2026-04-22 12:30:17 +08:00
2026-04-22 14:57:16 +08:00
2026-04-22 12:30:17 +08:00
2026-04-22 16:38:36 +08:00
2026-04-11 13:16:35 +08:00
2026-04-22 16:38:36 +08:00
2026-04-22 02:32:53 +08:00
2026-04-21 12:50:55 +08:00
2026-04-23 21:40:58 +08:00
2026-04-23 21:40:58 +08:00
2026-04-23 12:58:13 +08:00
2026-04-23 12:58:13 +08:00
2026-04-23 12:58:13 +08:00
2026-04-23 12:58:13 +08:00
2026-04-23 21:40:58 +08:00
2026-04-08 10:39:15 -07:00
2026-04-16 20:41:40 +08:00
2026-04-21 20:36:10 +08:00
2026-04-22 16:51:23 +08:00
2026-04-22 12:30:07 +08:00
2026-04-21 00:05:17 +08:00
2026-04-22 13:18:10 +08:00
2026-04-23 22:30:45 +08:00
2026-04-23 22:30:45 +08:00
2026-04-21 10:13:28 -07:00
2026-04-23 21:40:58 +08:00
2026-04-04 11:13:58 +08:00
2026-04-05 17:11:01 +08:00
2026-04-05 17:11:01 +08:00
2026-04-05 17:11:01 +08:00
2026-04-05 17:11:01 +08:00
2026-04-20 19:53:22 +08:00
2026-04-16 01:53:22 +08:00
2026-04-17 22:07:15 +08:00
2026-04-14 09:36:26 +08:00
2026-04-14 09:22:12 +08:00
2026-04-23 16:34:37 +08:00
2026-04-23 16:34:37 +08:00
2026-04-21 01:00:59 +08:00
2026-04-22 14:57:47 +08:00
2026-04-22 19:11:51 +08:00
2026-04-23 16:34:37 +08:00
2026-04-14 09:36:40 +08:00
2026-04-14 17:35:27 +08:00
2026-04-23 22:30:45 +08:00