Uh oh!
There was an error while loading. Please reload this page.
docs: document /v1/messages Anthropic-shape error envelope exception across error/integration docs - #352
Conversation
…across error/integration docs Closes#351. PR #343 changed proxy errors on `POST /v1/messages` to emit an Anthropic-shape envelope (`{type:"error", error:{type, message}, request_id:"req_..."}`) instead of the OpenAI envelope used by every other proxy endpoint. Four documentation pages still claimed the OpenAI envelope was universal across the proxy. A Claude SDK developer writing client-side error handling against any of these four pages would parse against the wrong shape and see the wrong type strings from `/v1/messages`. Per the consumer at `crates/aisix-proxy/src/error.rs:320-338` (`anthropic_kind_from_status()`), the gateway currently maps 9 of Anthropic's 10 canonical error types explicitly plus one fallback: 400, 422 → invalid_request_error 401 → authentication_error 403 → permission_error 404 → not_found_error 408 → timeout_error (in the map but currently unreachable — the gateway's internal timeouts surface as 502 via the Bridge and fold into api_error via the fallback) 413 → request_too_large 429 → rate_limit_error 503 → overloaded_error else → api_error The canonical Anthropic type list per https://platform.claude.com/docs/en/api/errors is 10 strings: the 9 above plus `billing_error` (402), which this gateway currently folds into `api_error`. Pre-merge re-grep at PR-time HEAD `2c1d485` confirmed the 9-string subset is still current; the issue body documents the same mapping with a 9-of-10 framing relative to canonical Anthropic. Fixes applied: - `docs/integration/anthropic-messages.md:58` — `## Error Shape` body rewritten to describe the Anthropic-shape envelope, list the gateway's 9-string subset with status mappings, note the 408→timeout_error unreachability, and cross-link the canonical 10-type list at the Anthropic Errors documentation URL. - `docs/integration/errors-and-retries.md` — exception note inserted between the page lede and the `## Error Envelope` heading, pointing readers to the Anthropic Messages Error Shape section for the per-endpoint shape and type-string subset. - `docs/reference/headers-and-error-codes.md` — exception note appended after the Proxy Error Types section, naming the OpenAI-vs-Anthropic-shape split as load-bearing, listing the Anthropic-shape type strings, and cross-linking the integration page. - `docs/quickstart/anthropic-sdk.md:115` — Verification Notes bullet rewritten in concise quickstart form, naming the envelope shape, enumerating the 8 reachable type strings, calling out the billing_error fold-in, and cross-linking both the integration page and the Anthropic Errors documentation. CLAUDE.md §7: this PR touches a wire-format claim against an upstream provider, so upstream-spec citation is required. The Anthropic Errors documentation URL is cited in each of the four sections per §7. Reference-implementation citation is N/A here — LiteLLM and Portkey do not implement this gateway's subset-vs-canonical relationship, so they are not authoritative for the doc claim.
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (4)
📝 WalkthroughWalkthroughDocumentation across four pages is updated to clarify that the ChangesAnthropic Error Envelope Documentation
🎯 1 (Trivial) | ⏱️ ~3 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above. Comment |
There was a problem hiding this comment.
Pull request overview
Updates documentation to correctly describe that POST /v1/messages is an exception to the gateway’s default OpenAI-style proxy error envelope, and to document the Anthropic-style error envelope and the gateway’s emitted Anthropic error-type subset for Claude SDK users.
Changes:
- Rewrites the Anthropic Messages integration doc’s “Error Shape” section to describe the Anthropic-style envelope and type mappings.
- Adds an exception callout to the Errors and Retries integration page pointing
/v1/messagesreaders to the Anthropic error shape details. - Appends an exception note to the Headers and Error Codes reference and updates the Anthropic SDK quickstart verification notes accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| docs/integration/anthropic-messages.md | Updates /v1/messages error-envelope documentation to Anthropic-shape with type mapping notes. |
| docs/integration/errors-and-retries.md | Adds a top-of-page exception callout for /v1/messages error envelope shape. |
| docs/reference/headers-and-error-codes.md | Adds an exception note clarifying /v1/messages uses a different error envelope/type taxonomy. |
| docs/quickstart/anthropic-sdk.md | Updates quickstart verification notes to reflect Anthropic-shape errors on /v1/messages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…its this Anthropic-upstream field Addresses Muslim's MEDIUM cold-audit finding on PR #352 round 1 (msg `bfbf705b`). The previous text cited the gateway's Anthropic-shape error envelope as `{type:"error", error:{type, message}, request_id:"req_..."}`. The gateway's actual `AnthropicErrorEnvelope` struct at `crates/aisix-proxy/src/error.rs:287-300` has only the `type` (renamed `discriminator`) and `error.type`/`error.message` (`AnthropicErrorBody`) fields. There is no `request_id` field on either struct; grep for `request_id` / `req_` in `crates/aisix-proxy/src/error.rs` returns zero matches. Real Anthropic upstream responses do carry an optional `request_id`; the gateway currently omits it. A reader parsing `response.request_id` from the gateway's `/v1/messages` error response would get undefined — a stealth parser bug for custom error-handlers branching on that field. Fix shape mirrors the existing `billing_error` caveat already in the sections: drop `request_id:"req_..."` from the envelope literal and add a parenthetical noting the gateway omits this optional Anthropic-upstream field. Applied in three locations: - `docs/integration/anthropic-messages.md:58` — Error Shape paragraph - `docs/reference/headers-and-error-codes.md` — exception note after Proxy Error Types - `docs/quickstart/anthropic-sdk.md:115` — Verification Notes bullet The 4th edit in this PR (`docs/integration/errors-and-retries.md` exception callout) did not contain the envelope literal — that one just says "use the Anthropic-shape envelope" and points readers to the integration page. Not affected by this fix.
…through Addresses Copilot inlines `3271289278` (item b — passthrough exception missing on headers-and-error-codes.md note) and `3271289287` (single- exception too narrow on errors-and-retries.md callout). Both Copilot findings trace to the same substantive observation: the gateway has TWO envelope exceptions, not one — `POST /v1/messages` uses the Anthropic-shape envelope, and `ANY /passthrough/:provider/*rest` forwards the upstream provider's status and body verbatim. The passthrough behavior was already documented on `docs/integration/errors-and-retries.md:87`: "`/passthrough/:provider/*rest` follows its own raw upstream status behavior after proxy auth and provider resolution". The round-1/round-2 framing of "every endpoint EXCEPT /v1/messages" omitted passthrough as a second exception. Fixes applied: - `docs/integration/errors-and-retries.md:11` — pluralize "Exception:" → "Exceptions:" and add a bullet for passthrough alongside the `/v1/messages` bullet. Both bullets link out to the relevant detail pages. - `docs/reference/headers-and-error-codes.md:36` — narrow the framing from "every proxy endpoint except `/v1/messages`" to "gateway-generated errors on the OpenAI-shape proxy endpoints" and list both exceptions (`/v1/messages` for Anthropic envelope; `/passthrough/:provider/*` for raw upstream forwarding) in a bulleted format. The other 3 Copilot inlines on PR #352 (`3271289255`, `3271289269`, the `request_id` half of `3271289278`) were stale comments on parent `f57c4f5`; round-2 commit `123ccf2` already addressed them by dropping `request_id` from the envelope literal. Will reply on each of those threads confirming round-2 resolution. The 4th Copilot's mention of `x-aisix-request-id` as alternative locating mechanism (verified in code at `crates/aisix-proxy/src/messages.rs:368` etc.) is scoped OUT of this round per Umar's call — separate doc-improvement candidate for future wave.
Uh oh!
There was an error while loading. Please reload this page.
… density Operator directive (DM `29bc02aa`): trim verbosity, match host page style. Apply to PR #352's 4 affected pages. - `docs/integration/anthropic-messages.md` Error Shape — replace the single ~9-sentence prose paragraph with a short intro + bullet list of `error.type` strings (each with status code in parens) + short paragraph on the 408 unreachable case + cross-link to Anthropic's spec. Bullet form matches the page's bullet style elsewhere; substance preserved (9 emitted strings + 402/billing_error caveat as inline "including 402" note + 408 unreachable + spec link). - `docs/quickstart/anthropic-sdk.md:115` Verification Notes bullet — collapse the multi-line bullet to a single-line bullet with cross-reference to anthropic-messages.md instead of duplicating the type-string subset. Neighboring bullets are single-line; this now matches. - `docs/reference/headers-and-error-codes.md` exception note — collapse the two long bullets that duplicated the type-string subset into two short bullets per exception with cross-references to the detail pages. Reference-page style. - `docs/integration/errors-and-retries.md` passthrough bullet — drop the trailing "and the Endpoint-Specific Notes section below" clause; the bullet's primary link is the action. Substantive preservation: - 9 emitted error-type strings + status mappings (now in bullet list on anthropic-messages.md as canonical reference) - 402/billing_error fold-in caveat (now inline on the api_error bullet) - 408 unreachable caveat (preserved as short paragraph) - gateway omits request_id (preserved on anthropic-messages.md, dropped from anthropic-sdk.md since the cross-reference covers it) - passthrough exception (preserved on errors-and-retries.md + headers- and-error-codes.md) - Anthropic spec link (preserved on anthropic-messages.md as canonical reference) Substance is unchanged; what changed is density and duplication. Cross-references collapse duplication; bullet form replaces dense prose lists.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Closes#351. PR #343 changed proxy errors on
POST /v1/messagesto emit an Anthropic-shape envelope ({type:"error", error:{type, message}}) instead of the OpenAI envelope used by every other proxy endpoint. Four documentation pages still described the OpenAI envelope as universal across the proxy — a Claude SDK developer writing client-side error handling against any of these four pages would parse against the wrong shape and see the wrong type strings from/v1/messages. This PR documents/v1/messagesas the exception and enumerates the gateway's emitted 9-string subset of Anthropic's 10 canonical error types.Doc-only diff (4 files, +6/-2). No code, schemas, configs, or test fixtures touched.
Changes
docs/integration/anthropic-messages.md:58## Error Shapebody rewritten. Removed the incorrect "Even on the Anthropic-style endpoint, proxy errors still use the gateway's OpenAI-compatible error envelope" claim. New body describes the Anthropic-shape envelope, lists the gateway's 9-string subset with per-status mappings, notes the408→timeout_errorunreachability, and cross-links the canonical 10-type list at https://platform.claude.com/docs/en/api/errors.docs/integration/errors-and-retries.md(between L9 and L11)## Error Envelopeheading:**Exception:** errors on POST /v1/messages use the Anthropic-shape envelope instead of the OpenAI envelope — see [Anthropic Messages — Error Shape] for the shape and the gateway's emitted type-string subset.docs/reference/headers-and-error-codes.md(after L34)408→timeout_errorunreachability, and cross-links the integration page for the per-status mapping and wider-canonical context.docs/quickstart/anthropic-sdk.md:115billing_errorfold-in note, and cross-links to the Errors and Retries integration page + Anthropic's Errors documentation.Net diff: 4 files, +6 / -2. Source:
git diff --stat.Test plan
Doc-only diff — no
.rsfiles, schemas, configs, or test fixtures touched. The cargo trio was still run end-to-end as the canonical pre-merge gate. Used-j 2for parallel compile cap per the locked workaround on this 8 GB VPS.cargo fmt --check— PASS (exit 0).cargo clippy --workspace --all-targets -j 2 -- -D warnings— PASS (exit 0, 0.70s incremental, no warnings).cargo test --workspace -j 2— PASS (exit 0; 33 suites all green; 1067 tests passed, 0 failed, 3 ignored).grep -rln <each affected page> tests/e2e/for all 4 pages returns empty.pnpm testundertests/e2e/is not applicable for this diff. The Anthropic-shape envelope contract this PR documents IS exercised bytests/e2e/src/cases/anthropic-messages-error-envelope-e2e.test.ts(added in fix(proxy): /v1/messages emits Anthropic-shape error envelope (#336) #343) — that suite tests the envelope shape and the per-status type strings the gateway emits.cargo clippytailcargo testsummaryAffected pages
docs/integration/anthropic-messages.mddocs/integration/errors-and-retries.mddocs/reference/headers-and-error-codes.mddocs/quickstart/anthropic-sdk.mdPre-merge-check verification log
Issue #351 called out three pre-merge checks. All three resolved as follows:
Re-grep the consumer at PR-time HEAD. Verified
crates/aisix-proxy/src/error.rs:320-338on currentorigin/mainHEAD2c1d485:✓ 9-string subset documented in the issue body matches verbatim. The
408→timeout_error"in the map but unreachable" framing is supported by the code comment.Verify the cited Anthropic spec URL.https://platform.claude.com/docs/en/api/errors resolves and lists the canonical 10-type set (
invalid_request_error,authentication_error,billing_error,permission_error,not_found_error,request_too_large,rate_limit_error,timeout_error,api_error,overloaded_error). ✓ Match — the gateway maps 9 of these 10 explicitly;billing_erroris folded intoapi_errorand called out as the one omission in each affected section.Editorial choice for finding feat(core): Model, ApiKey, RateLimit entities + JSON Schema validators #3. Used the inline exception-note form (appended after the existing "These values appear in the proxy's OpenAI-compatible error envelope." sentence) rather than a parallel sub-section. Rationale: the existing Proxy Error Types section is already a compact list; an inline note preserves its scan-rate and gives the OpenAI/Anthropic distinction equal weight in the prose without restructuring the page.
CLAUDE.md §7 wire-format claim — upstream-spec citation. This PR touches a wire-format claim against an upstream provider. Anthropic's Errors documentation (https://platform.claude.com/docs/en/api/errors) is cited in each of the four affected sections per §7. Reference-implementation citation is N/A here — LiteLLM and Portkey do not implement this gateway's subset-vs-canonical relationship (they pass the upstream's error shape through unchanged or normalise to their own taxonomy), so they are not authoritative for the doc claim. The runtime consumer (
anthropic_kind_from_status()inaisix-proxy/src/error.rs) is the authoritative ref-impl in this case, and is cited in each section.Coexistence with PR #350
PR #350 (Wave-2 sibling,
docs/tutorials/enable-response-caching.mdcache-fingerprint correction) touches a disjoint file from this PR. Nogit merge-treecollision check needed.References
Upstream spec citation (per CLAUDE.md §7)
Summary by CodeRabbit