Someone stole my AI API key. Why am I paying for their requests?
Last reviewed

Imagine your app sold six AI-generated illustrations yesterday. This morning your AI provider shows $4,000 in overnight usage. Your sales dashboard is quiet. You switch off the Generate button. The provider keeps recording new requests.
How can both dashboards be right? An AI API key is a secret your app presents when it asks a provider to do paid work. If someone copies a valid key, they can make their own requests directly to the provider, within the permissions attached to it. Their work is billed to your project. Those requests never pass through your Generate button, your sign-in screen, or your ten-images-per-customer limit. Source: OpenAI’s API key safety guidance
A key can leak through a browser bundle, a public repository, a screenshot, a shared .env file, or an application log. See how a private repository can still ship a key to the browser.
The bill is a clue. Compare the two sides.
Open the provider’s Usage dashboard and your own job history. Pick the same project, time window, and time zone. Which models ran? Can you account for that work with customer jobs, background tasks, or retries? A tenfold jump that lines up with a stuck image job points you toward your own worker. Recent activity on a model your app never calls deserves a different investigation. Allow for reporting delays, especially when checking whether usage has stopped.
If the key is exposed, revoke it now
- Revoke the affected key at the provider. Taking down a screenshot or fixing a build leaves copied keys usable. Revoking the key stops whoever has it from making new requests with it. Your Generate button will also stop working until you deploy a replacement. Accept that temporary outage to cut off unauthorized spending now.
- Close the leak before issuing the replacement. Keep the new key in a server-only secret setting. Update each legitimate app or worker that needs it, redeploy, and confirm one ordinary job completes. Otherwise the next build can hand out the replacement too.
- Ask the provider to investigate the charges. Send the project ID, recorded spend, relevant dates and time zone, and any request IDs you have. If you had an enforced limit, include its amount and whether it was active during that period. Include the revocation time to help narrow the investigation. Keep API keys out of the ticket. Charges already recorded need a billing review. Source: OpenAI’s project guidance for unexpected spending
Put the spending control where the bill is created
Give production and development separate projects and keys. In the production project, allow only the models your product uses. Set an early spend alert that reaches someone who can revoke the key. In OpenAI’s project settings, look for Enforce a hard limit if you want requests to stop when tracked spending reaches the budget. Recorded spending can still exceed the threshold while enforcement takes effect. Source: OpenAI spend limits
Using another AI provider? Look for the same three controls in its dashboard: per-project keys, model restrictions, and an enforced spending limit. Check which your provider offers and whether reaching the limit actually refuses the next request.
Trace one paid AI request from the Generate button to the provider. List the services that use the credential by setting name only. Show what my app records for each job and which limits apply at the provider if a request never touches my app. Flag any dashboard settings you can’t verify.
Try the Generate button when the budget runs out
In a development project with its own key, set a small enforced limit. If your provider permits it, set the limit at or below spend already recorded for the current period. Once enforcement takes effect, try one ordinary generation. The provider should refuse it, and the app should tell the user that generation is temporarily unavailable. Check that the failed job leaves the user’s credit balance unchanged and that the worker stops retrying. Restore the development setting afterward.
If your provider offers alerts only, simulate a budget refusal in your test app. That checks the message, credits, and retries. Provider-side spending still needs a separate control.
Check your other paid features before launch with Jungle’s prelaunch security guide.
Get early access to Jungle Security
Explore the proposed plans and join the waitlist for your app.