Repository navigation
Conversation
Sail serves the flex window only to Responses requests with background=true, and the asap window only to requests without it. It answers every other pairing with a 400. The Sail config still mapped service_tier "flex" to the flex window on Chat Completions and on foreground Responses, so those calls reached Sail and failed, even under drop_params. Chat Completions now rejects a tier that selects flex before calling Sail. drop_params does not drop it, because chat billing reads the caller's service_tier and would bill flex for a request Sail runs at asap. Responses rejects flex without background=true and asap with it, from either service_tier or metadata.completion_window. Under drop_params the window is dropped and the request bills at the base price. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Automatic reviews are disabled for this repository. |
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
…indow-rules
Conflict resolutions:
- anthropic/messages/native/handler.py (renamed from pass_through on
main): main's MCP gateway call replaces the old block and now gets the
Anthropic-validated metadata like the other Anthropic calls. The
provider's request metadata joins main's tool cache-control marking
when building the optional params.
- custom_httpx/llm_http_handler.py: main now applies
additional_drop_params before logging, into request_params, so the
branch's own drop step and its relocated logging call are dropped and
the billing params are recorded from request_params instead.
- main.py: the Sail caller-metadata lines move into a helper, because
completion() is at basedpyright's complexity limit and the inline
branches pushed it over ("Code is too complex to analyze").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@shrey-berri this is ready for review. It makes the Sail provider follow Sail's current completion-window rules (flex only on background Responses) and bills from the |
TLDR
Problem this solves:
How it solves it:
Intentional product change: Chat and Messages reject Flex even with
drop_params, because dropping that choice can change the requested price. Flex requires native background ResponsesUser Flow
Before, a developer's Flex request on Messages succeeds and the gateway reports the ASAP price
metadata.completion_window: "flex"x-litellm-response-costheader reports the ASAP rateAfter, the same unsupported window gets an explicit rejection
metadata.completion_window: "flex"Behavior and scope
Chat and Messages accept
metadata.completion_window. Messages also accepts the same LiteLLMservice_tiermapping as Chat and Responses. Conflicting tier and metadata choices return an explicit error. Only caller string metadata is forwarded, excluding the proxy's internal metadataResponses rejects foreground Flex and background ASAP unless parameter dropping was explicitly enabled. Dropping an incompatible Responses window also removes its requested billing tier.
defaultandpriorityselect ASAP, andautolets Sail chooseBilling prefers Sail's reported tier. An explicit caller window provides the fallback for older responses. Streamed Messages retain
usage.service_tierwhen their usage is collectedExplicit
additional_drop_paramsremovals are applied before billing parameters are captured, so a removed tier or metadata window cannot survive as a discounted billing fallbackThis consolidates and supersedes #43477. That stale draft's synchronous Flex success cases contradict the current API and must not be merged separately
Merge with main
Current head
713bc1c7merges main at2e5cc9e0to clear conflicts. The behavior described above is unchanged. Three conflicts were resolved:llms/anthropic/pass_throughtollms/anthropic/messages/native. Main's new MCP gateway call now passes the Anthropic-validated metadata, like the other Anthropic calls. Sail's request metadata is combined with main's tool cache-control markingadditional_drop_paramsbefore the billing params are logged, intorequest_params. This branch's separate drop step is removed, and the logged billing params now come fromrequest_params, so a dropped tier still cannot be billedmain.py, the Sail caller-metadata lines move into a helper.completion()is at basedpyright's complexity limit, and the inline branches pushed it over ("Code is too complex to analyze")Validation
The PR is ready for review. CI has not run on
713bc1c7: its 11 workflow runs are waiting for a maintainer to approve runs from this fork. The previous head8c81a0a8passed all 88 checks, with 100% Codecov diff coverage (unit run)At
713bc1c7, 3,092 tests pass locally across the Sail, Anthropic Messages, HTTP handler, cost calculation andmainsuites. Six tests and one test module fail locally only because optional packages (tenacity,anthropic,google-cloud-speech) are not installed. Theanthropicandgoogle-cloud-speechfailures were confirmed on unmodified main; thetenacityones stop at the missing import. Strict Ruff, type discipline, test-quality and full basedpyright delta gates pass against2e5cc9e0, and changed-file formatting is cleanTwelve regression cases cover dropped tiers, whole and nested metadata removals, and the remaining window on collected and streamed Messages
Veria's stale-tier finding has a pushed fix, but its thread is still open and its only review was submitted before that fix. Greptile automatic reviews are disabled
The live proxy proof below was captured at
8c81a0a8, before the merge. A rerun on 2026-10-29 could not reach a model: Sail staging returned nothing within 240 seconds for synchronous inference, including direct calls without LiteLLM. Its model list and background request creation responded normally. So the Chat and dropped-tier Messages cases are pending a staging or production rerun. The two cases LiteLLM rejects before calling Sail were rerun at713bc1c7and are shown under "Rerun after the merge"Screenshots / Proof of Fix
Both proxies use
sail/zai-org/GLM-5.3-Flashagainst the real staging API, with a local-only master key. Port 4012 runs upstreamb9079755, also this branch's merge base. Port 4011 runs8c81a0a8. Credentials are provided through environment variables and are omitted hereChat payload, saved as
chat.json{"model":"sail-flash","max_tokens":64,"messages":[{"role":"user","content":"Reply with exactly OK."}],"reasoning_effort":"minimal","metadata":{"completion_window":"balanced"}}Messages payload, saved as
messages.json{"model":"sail-flash","max_tokens":64,"messages":[{"role":"user","content":"Reply with exactly OK."}],"metadata":{"completion_window":"flex"}}Dropped-tier Messages payload, saved as
messages-drop.json{"model":"sail-flash","max_tokens":64,"messages":[{"role":"user","content":"Reply with exactly OK."}],"service_tier":"flex","additional_drop_params":["service_tier"]}Responses payload, saved as
responses.json{"model":"sail-flash","max_output_tokens":32,"input":"Reply OK","service_tier":"flex"}Before (b907975)
Chat
curl -sS --max-time 240 -i http://127.0.0.1:4012/v1/chat/completions -H 'Authorization: Bearer sk-sail-local-audit' -H 'Content-Type: application/json' --data-binary @chat.jsonservice_tier: "asap",x-litellm-response-cost: 6.7699999999999996e-06, 17 uncached input tokens and 14 output tokens. Sail selected ASAP, although the caller requested BalancedMessages
curl -sS --max-time 240 -i http://127.0.0.1:4012/v1/messages -H 'Authorization: Bearer sk-sail-local-audit' -H 'Content-Type: application/json' --data-binary @messages.jsonusage.service_tier: "asap",x-litellm-response-cost: 1.307e-05, 17 uncached input tokens and 32 output tokens. Sail selected ASAP even though the caller requested FlexResponses
curl -sS --max-time 240 -i http://127.0.0.1:4012/v1/responses -H 'Authorization: Bearer sk-sail-local-audit' -H 'Content-Type: application/json' --data-binary @responses.jsonmetadata.completion_window, wrapped asSailExceptionAfter (8c81a0a)
Chat
service_tier: "balanced",x-litellm-response-cost: 1.832e-05, 17 input tokens including 16 cached and 64 output tokens. Sail selected Balanced and the cost exactly matches that tierMessages
sail serves metadata.completion_window='flex' only to Responses requests with background=true. Send 'balanced' for a synchronous request.The cost header is zerocurl -sS --max-time 120 -i http://127.0.0.1:4011/v1/messages -H 'Authorization: Bearer sk-sail-local-audit' -H 'Content-Type: application/json' --data-binary @messages-drop.jsonusage.service_tier: "asap",x-litellm-response-cost: 2.283e-05, 1 uncached input token, 16 cached input tokens and 64 output tokens. The cost matches ASAP after the caller explicitly removed FlexResponses
sail serves service_tier='flex' (completion_window 'flex') only to Responses requests with background=true. Send 'balanced' for a synchronous request.LiteLLM rejects this before sending it to SailRerun after the merge (713bc1c)
Same proxy setup and payloads on 2026-10-29: port 4012 runs the merge base
2e5cc9e0, port 4011 runs713bc1c7.Messages
x-litellm-response-cost: 0,litellm.UnsupportedParamsError: sail serves metadata.completion_window='flex' only to Responses requests with background=true. Send 'balanced' for a synchronous request.Nothing reaches SailResponses
SailException:completion_window "flex" is only available for background responses (POST /v1/responses with background=true) or Batch work; for synchronous requests use asap or balancedx-litellm-response-cost: 0,litellm.UnsupportedParamsError: sail serves service_tier='flex' (completion_window 'flex') only to Responses requests with background=true. Send 'balanced' for a synchronous request.LiteLLM rejects it before calling SailChat and dropped-tier Messages
Dependencies and remaining verification
Sail's served-tier response field merged in sailresearchco/sail#11084. The fresh staging responses now contain it on collected Chat and Messages, with matching costs. The full collected and streamed endpoint matrix still needs joint verification. The current Balanced Messages control still timed out through the proxy after 240 seconds. An earlier direct Sail control timed out after 130 seconds. This is not counted as a successful current-tip live case
Native background billing exists in LiteLLM, but exactly-once managed spend accounting through completion and repeated retrieval remains a separate live check. No database or Redis billing backend was connected in this local proxy run
Optional
polling_via_cacheis disabled by default. When enabled it rewrites background work into a foreground stream, which cannot serve Sail Flex. Keep Sail deployment names innative_background_modewhen using that optional featurePre-Submission checklist