Repository navigation
A hard dollar cap per Qwen Code session with ${session_id} in customHeaders #13496
domondi1
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The
${session_id}placeholder incustomHeaders(withoutboundCorrelation.allowDynamicHeaderValues) is enough to give every Qwen Code session its own hard dollar ceiling, config only. Point a provider at a local gateway, send the session id as the gateway's run id and a static budget, and the gateway refuses a call with HTTP 402 before it reaches the provider once that session's budget is used. Useful for long headless runs and loops where one session can spend far more than you meant. Disclosure: I maintain the gateway (Inferrail, open source).~/.qwen/settings.json:{ "modelProviders": { "openai": [ { "id": "gpt-4o-mini", "name": "gpt-4o-mini (capped)", "envKey": "INFERRAIL_PLACEHOLDER_KEY", "baseUrl": "http://127.0.0.1:8000/v1", "generationConfig": { "customHeaders": { "X-Inferrail-Attribute-Work-Id": "qwen-${session_id}", "X-Inferrail-Budget-Usd": "2.00" }, "samplingParams": { "max_tokens": 4000 } } } ] }, "outboundCorrelation": { "allowDynamicHeaderValues": true }, "security": { "auth": { "selectedType": "openai" } }, "model": { "name": "gpt-4o-mini" } }What I checked (Qwen Code 0.25.0 from npm, inferrail 0.4.15,
qwen -pagainst a stand-in OpenAI endpoint with fixed token counts):qwen-<session id>), 3 calls each, recorded separately with tokens and cost.[API Error: 402 budget 'work_id:qwen-...:per_work' ... would be exceeded], exit 1, about 2 s, 1 request, nothing reached the upstream, no retry loop.Caveats: each call reserves its worst case up front from
max_tokens, so keepsamplingParams.max_tokensrealistic. A dollar budget needs a price for the model on the gateway side (most OpenAI and Anthropic models are built in,inferrail models; for DashScope or other providers you add the endpoint and a price ininferrail.yaml). As the docs note, enabling dynamic values sends the session id to that provider entry's host, here only the local gateway, which stores usage and cost per call, never prompts or code. I didn't test/newand/resume; per the docs they rotate the id, which would start a fresh budget.All reactions