AI Rate Limit Proxy
A local reverse proxy for a bring-your-own-key model in VS Code Chat. It waits for a confirmed transient upstream 429 and makes one retry before returning a response to Chat. It accepts Retry-After seconds or HTTP dates and an explicitly configured JSON seconds field. Successful responses, including server-sent events (SSE), stream through to the current chat or agent turn.
Install and connect
Use desktop VS Code 1.148 or later and a trusted local workspace. The tested client is the Copilot harness in the Chat view. The extension runs one loopback listener for one OpenAI-compatible Chat Completions upstream. Connect a model you can access through VS Code’s Custom Endpoint.
Run Extensions: Install from VSIX and select the packaged extension.
Run AI Rate Limit Proxy: Configure. Enter the provider's full HTTPS Chat Completions URL and API key. Select the provider's authentication header. The key is stored in VS Code SecretStorage and bound to that URL.
Open the extension settings. Set Transient Codes to the exact documented error.code or error.type values that mean the provider refused this generation before processing. Add any provider-specific quota or other unrecoverable codes to Terminal Codes. If the response includes a numeric seconds field, set JSON Seconds Path to its exact path, such as error.retry_after_seconds if your provider defines that field. See the retry rules.
Run AI Rate Limit Proxy: Start and AI Rate Limit Proxy: Copy Local API Key. In Chat: Manage Language Models, add a Custom Endpoint provider, choose Chat Completions, and enter the copied local key through the API key prompt. Keep the generated apiKey secret input in chatLanguageModels.json.
Set the model URL to http://127.0.0.1:17861/v1/chat/completions, or paste the URL from Copy Local Endpoint if you changed the port. Add the explicit request header below to the model entry. Keep its actual model ID and token limits. Set toolCalling only for a model that supports tools.
"requestHeaders": {
"X-Rate-Limit-Proxy-Key": "${apiKey}"
}
Select the model in Chat's picker. For the Copilot harness, enable chat.agentHost.byokModels.enabled if required by your VS Code configuration. Choose a model with tools to use Agent mode. Organization policy may restrict BYOK.
The extension status item shows the connection and any cooldown. It opens the AI Rate Limit Proxy output channel. The channel reports status and retry timing. It excludes keys, URL query strings, prompts, and responses.
Start enables automatic start on the next eligible VS Code launch. Stop closes the listener and disables automatic start. Provider, port, and retry rule changes apply on the next stop/start. To switch back, select your previous model and stop or disable the proxy extension.
Retry rules
- Configure classification before relying on retries. An unknown or terminal 429 passes through. A recognized terminal code takes precedence even when the provider sends a delay. For header-only or JSON-only providers that omit a code, enable the matching Trust Header Only 429 or Trust JSON Seconds 429 setting only when the provider documents that the signal means a transient rejection before generation.
- A valid
Retry-After wins. An absent or malformed header falls back to the configured field, which accepts a nonnegative JSON number in seconds. The wait starts when the upstream 429 has been fully read. Zero waits get a 250 ms floor.
- The total pre-response budget is 80 seconds, with 5 seconds reserved for replay connection and response headers. The proxy waits the full requested interval when it fits. When it cannot fit, it returns the original 429 and continues honoring the shared cooldown for later requests. The second upstream 429 is terminal for the current request and can extend that cooldown.
- A closed client connection cancels the pending retry or active stream. The tested Copilot Agent can keep the HTTP connection open after you cancel the turn in Chat. In that case, run AI Rate Limit Proxy: Cancel Pending Retries after cancelling the turn. This returns the held 429 to the client and preserves the provider cooldown. Connections lost after response headers have been sent are surfaced as stream failures without replay.
Keep upstream credentials in Configure and put only routing parameters, such as an API version, in the configured URL. The proxy uses normal HTTPS certificate verification. The listener accepts only the local key on the one Chat Completions route. The provider error schema and supported wait window should be verified against the intended account and model. The packaged tests use a fixture.
Build and test
Use Node 24, the pnpm version in package.json, and OpenSSL for the test certificate.
pnpm install --frozen-lockfile
pnpm test
pnpm test:vscode
pnpm package
The extension-host smoke uses VS Code 1.148.0 by default and needs a display. Use Xvfb on headless Linux.
The local package is written to artifacts/ai-rate-limit-proxy.vsix under the publisher ID jo-hemphill.ai-rate-limit-proxy. The tests exercise the production proxy over HTTPS. The repository’s compatibility fixture also covers the underlying VS Code client behavior.
See Publishing for release preparation and registry setup.