feat(gateway): take official hosts, output fallback and error shapes from core v0.42.0 - #42
Merged
Merged
Conversation
…from core v0.42.0 - `tw_dialect::official::is_official_host` replaces the three-host list in transport, so DeepSeek, Moonshot, Z.ai and the rest are official too and a relay cannot pass itself off as one through its path or user info. `ANTHROPIC_VERSION` comes from there as well. - The output length written for an upstream that requires one is `fallback_max_output_tokens(model)` (32000 for Claude, 8192 else) instead of a fixed 4096 that cut Claude answers short. - Stream error frames come from `tw_dialect::convert::error_frame`: Responses clients get `response.failed`, Anthropic clients an `error` event of the right type, instead of Chat-shaped frames they skip. - Whole error bodies come from `tw_dialect::convert::error_body` in the caller's format. The Chat body's `type` is now OpenAI's own vocabulary (`rate_limit_error`, `server_error`, ...). - The provider test builds its URL with `tw_dialect::url::upstream_url`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adopts the shared facts core v0.42.0 now carries, in place of this side's own copies.
Changes
Upstream::is_officialusestw_dialect::official::is_official_hostfor standard upstreams (Azure and Bedrock stay official by shape). The local list had three hosts; core's also covers DeepSeek, Moonshot, Zhipu/Z.ai, DashScope, xAI, and*.amazonaws.com, and compares the parsed host, sohttps://relay/api.openai.comorhttps://api.openai.com@relayno longer passes as official.anthropic-versioncomes fromtw_dialect::official::ANTHROPIC_VERSION.max_tokensand the caller set none, it isfallback_max_output_tokens(upstream model)(32000 for Claude, 8192 otherwise) instead of a fixed 4096 that cut Claude answers short. There is no per-model output limit stored here to prefer, so this mirrors the desktop's fallback branch.tw_dialect::convert::error_frame(client, status, message). Before, a Responses client got a Chat-shapedevent: errorframe it skips (the stream just stopped); it now getsresponse.failed. Anthropic clients get anerrorevent whoseerror.typefollows the status.tw_dialect::convert::error_bodyin the caller's format.GatewayErrorResponsecarries the client dialect; every generation handler sets it. Anthropic clients now get{"type":"error","error":{…}}. The Chat/Responses body'stypeis OpenAI's own vocabulary (rate_limit_error,server_error,invalid_request_error, …) instead of this gateway's tags (rate_limited,provider_http_error, …); status codes andRetry-Afterare unchanged.tw_dialect::url::upstream_url.tw_dialect::usagewas already the only usage parser;tokens()usesUsage::prompt_total.Tests
gateway_error_shapes.rs): Anthropic body on an upstream failure and on a refusal before routing, Chat error type, a failing Responses stream ending inresponse.failed(with the caller's model), a failing Anthropic stream ending in anerrorevent.--all-targetsand--lib), 679 unit tests, full integration suite with own containers. The only failures were three tests that resolve public hosts (AWS docs MCP, two MCP tool tests hitting "URL host could not be resolved"), which depend on this machine's DNS and are untouched here.🤖 Generated with Claude Code