{"slug": "probing-native-protocol-error-shapes-on-v1-messages-and-v1-responses", "title": "Probing native protocol error shapes on /v1/messages and /v1/responses", "summary": "A developer at Kantro probed the gateway's four less-common native endpoints — /v1/messages, /v1/messages/count_tokens, /v1/responses and /v1/responses/compact — and found each returns its provider's native 401 error envelope rather than a translated schema. The Anthropic paths return type: \"error\" with authentication_error, while the OpenAI paths return invalid_request_error with param and code fields, which the developer notes matters because official SDKs parse error envelopes differently before retry logic runs. The check covered only unauthenticated 401s and the documented route surface; streaming SSE parity on 200 responses was not tested.", "body_md": "Most LLM proxies advertise \"OpenAI-compatible\" endpoints and stop at `/v1/chat/completions`. That works fine for a single chat call, then breaks the moment you point Claude Code or the Codex CLI at the proxy. Claude Code expects Anthropic's `/v1/messages` and `/v1/messages/count_tokens` shapes (including `type: \"error\"` envelopes on 401s), and newer OpenAI clients call `/v1/responses` and `/v1/responses/compact`.\n\nOn [Kantro](https://kantro.dev), we kept the native endpoints separate instead of translating everything through a single schema. I wanted to verify whether unauthenticated error envelopes and route coverage actually stay native on the live edge, so I probed the four less-common endpoints directly against `kantro.dev`:\n\n```\nfor ep in /v1/messages /v1/messages/count_tokens /v1/responses /v1/responses/compact; do\n  echo \"=== $ep ===\"\n  curl -sS -w \"\\nHTTP:%{http_code}\\n\" -X POST \"https://kantro.dev$ep\" \\\n    -H \"Content-Type: application/json\" -d '{}'\ndone\n```\n\nHere is what came back:\n\n```\n=== /v1/messages ===\n{\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"Invalid Kantro API key. Check your Bearer token or generate a key: https://kantro.dev/app/keys\"}}\nHTTP:401\n\n=== /v1/messages/count_tokens ===\n{\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"Invalid Kantro API key. Check your Bearer token or generate a key: https://kantro.dev/app/keys\"}}\nHTTP:401\n\n=== /v1/responses ===\n{\"error\":{\"message\":\"Invalid Kantro API key. Check your Bearer token or generate a key: https://kantro.dev/app/keys\",\"type\":\"invalid_request_error\",\"param\":null,\"code\":\"invalid_api_key\"}}\nHTTP:401\n\n=== /v1/responses/compact ===\n{\"error\":{\"message\":\"Invalid Kantro API key. Check your Bearer token or generate a key: https://kantro.dev/app/keys\",\"type\":\"invalid_request_error\",\"param\":null,\"code\":\"invalid_api_key\"}}\nHTTP:401\n```\n\nBoth Anthropic paths return Anthropic's `authentication_error` wrapper, while both OpenAI paths return OpenAI's `invalid_request_error` shape with `param` and `code`. That matters because official SDKs parse the error envelope differently before they even reach your retry logic. If a gateway returns an OpenAI error JSON on `/v1/messages`, the Anthropic SDK's error parser falls back to an untyped error.\n\nChecking [the OpenAPI spec](https://kantro.dev/openapi.json) also turned up `/v1/key`, `/v1/keys`, and `/v1/keys/{hash}` alongside `/v1/models` for inspecting per-key spend limits and rotating keys programmatically. On the CLI side, `npx kantro-setup` writes keys to `~/.config/kantro/key` (or reads `KANTRO_API_KEY`) and prints file diffs before editing local tool configs instead of dropping keys into a repo `.env`.\n\nThis only checks the unauthenticated 401 envelope and documented route surface. I did not run a streaming SSE diff against upstream Anthropic or OpenAI in this pass, so header and chunk parity on 200 responses still needs a keyed run to verify directly.", "url": "https://wpnews.pro/news/probing-native-protocol-error-shapes-on-v1-messages-and-v1-responses", "canonical_source": "https://dev.to/kantrodev/probing-native-protocol-error-shapes-on-v1messages-and-v1responses-2a8l", "published_at": "2026-11-23 00:28:56+00:00", "updated_at": "2026-11-23 00:41:38.627850+00:00", "lang": "en", "topics": ["large-language-models", "ai-infrastructure", "developer-tools", "ai-agents"], "entities": ["Kantro", "Anthropic", "OpenAI", "Claude Code", "Codex CLI"], "also_reported_by": [], "takeaway": "Kantro's /v1/messages and /v1/messages/count_tokens return Anthropic's authentication_error envelope on 401, while /v1/responses and /v1/responses/compact return OpenAI's invalid_request_error with param and code, so proxies must preserve native error shapes or official SDKs fall back to untyped err", "recommendation": {"advice": "Preserve each provider's native error envelope on its own routes and curl the unauthenticated 401s of /v1/messages and /v1/responses to confirm SDKs parse them correctly.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/probing-native-protocol-error-shapes-on-v1-messages-and-v1-responses", "markdown": "https://wpnews.pro/news/probing-native-protocol-error-shapes-on-v1-messages-and-v1-responses.md", "text": "https://wpnews.pro/news/probing-native-protocol-error-shapes-on-v1-messages-and-v1-responses.txt", "jsonld": "https://wpnews.pro/news/probing-native-protocol-error-shapes-on-v1-messages-and-v1-responses.jsonld"}}