- Developer home
- AI API
- Best practices
Best practices
Keep keys secret, one key per app, revoke on a leak.
Keys
- Keep keys on a server or in a secret store. Never put a key in a web page, a mobile app or a public repository.
- Make one key per app or machine, so one can be revoked without stopping the others.
- If a key leaks, revoke it at once in Developer platform → AI API and make a new one; a revoked key stops working immediately.
- Watch each key's usage on the same page.
Requests
- Set max_tokens to what you need: it bounds the cost of a request.
- Retry 429 and 5xx with a short, growing pause.
- Reuse a long system prompt unchanged across requests so it is read from cache, which is cheaper.