Repository navigation
A hard dollar cap per Kilo CLI session with your own API key (x-session-id, config only) #14874
domondi1
started this conversation in
4. 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.
If you use the Kilo CLI with your own API key (a custom OpenAI-compatible provider rather than Kilo's gateway), you can give every session its own hard dollar ceiling with config only. The CLI already sends its session id as
x-session-idon every request to a custom provider, so a local gateway can use that as the run id and refuse a call with HTTP 402 before it reaches the provider once the session's budget is used. Disclosure: I maintain the gateway (Inferrail, open source).~/.config/kilo/kilo.json:{ "provider": { "capped": { "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "http://127.0.0.1:8000/v1", "apiKey": "unused", "headers": { "X-Inferrail-Budget-Usd": "3.00" } }, "models": { "gpt-4o-mini": { "name": "gpt-4o-mini" } } } }, "model": "capped/gpt-4o-mini" }Each session (
ses_...) gets its own $3, andinferrail report --by work_idlists calls, tokens and dollars per session. For a CI or scripted run that should be one budget across several sessions, add"X-Inferrail-Attribute-Work-Id": "<run id>"to the headers; an explicit id wins.What I checked (
@kilocode/cli7.8.3, inferrail 0.4.16,kilo runagainst a stand-in OpenAI endpoint with fixed token counts): two sessions recorded under their own ids; with a budget too small for the next call,kilo runprintedError: budget 'work_id:ses_...' would be exceededafter one refused request, nothing reached the upstream, no retry loop.Caveats: each call reserves its worst case from the max output tokens up front, so budgets need headroom (about $0.02 per call for gpt-4o-mini at the CLI's default here). A dollar budget needs a price for the model on the gateway side (most OpenAI and Anthropic models are built in,
inferrail models). This is for your own API keys, not Kilo's hosted gateway, which has its own billing. The gateway stores usage and cost per call, never prompts or code.All reactions