---
title: "LLM API key security - env vars, rotation, IP lists | BroadRouter"
description: "Keep LLM API keys out of code and logs, give each workload its own key, rotate on a schedule, lock keys to server IPs and revoke a leak in seconds."
url: https://broadrouter.com/blog/llm-api-key-security/
lang: en
updated: 2026-11-14
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# LLM API key security: storage, rotation and IP allow-lists

By the BroadNet Inference team · 6 min read · Published 2026-11-14 · Updated 2026-11-15

Keep LLM API keys in a secret manager, never in code or the browser. Give each app or agent its own key, rotate on a schedule, and lock keys to your servers with an IP allow-list. BroadNet Inference says its allow-lists take 32 entries, revocation stops new requests within five seconds, and keys last one year.

## Key takeaways

-   Never ship a key to a browser or mobile app; call the LLM from your server.
-   One key per workload: up to 10 live keys per BroadNet account makes leaks easy to isolate.
-   IP allow-lists stop a stolen key from working elsewhere. BroadNet takes up to 32 IPv4, IPv6 or CIDR entries.
-   Revocation and allow-list changes take effect within five seconds on BroadNet Inference.
-   Keys expire one year after creation, so rotation must be a routine, not an emergency.

**On this page**

1.  Where should you store an LLM API key?
2.  Can you put an API key in a browser or mobile app?
3.  Why give each workload its own key?
4.  How do IP allow-lists protect a key?
5.  Why separate inference keys from admin credentials?
6.  How often should you rotate API keys?
7.  What should you do when a key leaks?
8.  How do keys leak through logs?
9.  How do you limit the damage of a leak you have not found yet?
10.  Which key controls does BroadNet Inference provide?

To secure an LLM API key, keep it in a secret manager and call the model only from your server, never from a browser or app. Give each workload its own key, rotate keys on a schedule, lock them to your server IPs with an allow-list, and revoke a leaked key first, investigating second.

This post covers the habits that keep keys safe, with the specific controls BroadNet Inference provides. For step-by-step portal clicks, see the [API keys and IP allow-lists guide](https://broadrouter.com/guides/api-keys-ip-allow-lists/); for budgets and runaway-loop protection, see [LLM API spend control](https://broadrouter.com/blog/llm-api-spend-control/).

## Where should you store an LLM API key?

Store keys in a secret manager or your platform’s encrypted secrets, never in code. The [OWASP Secrets Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) covers the options in depth. Note its caution: environment variables “are generally accessible to all processes and may be included in logs or system dumps”, so OWASP prefers mounted secret files or fetching secrets from a secret store where you have the choice. An environment variable filled from a secret manager at start-up is the common middle ground.

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://inference.broadnet.ai/v1",
    api_key=os.environ["BROADNET_API_KEY"],  # fails loudly if missing
)
```

Use `os.environ[...]`, not `os.getenv(...)` with a hard-coded fallback; a fallback is how keys end up in Git. For local development, a `.env` file is fine if it is in `.gitignore` from the first commit. Turn on your Git host’s secret scanning and push protection. On GitHub, [push protection](https://docs.github.com/en/code-security/secret-scanning/introduction/about-push-protection) blocks pushes that contain known secret formats before they reach the repository; push protection for users is on by default, but repository-level push protection is off by default and must be enabled by a repository administrator or organisation owner.

## Can you put an API key in a browser or mobile app?

No. Anything shipped to a client can be extracted. Front-end code and app bundles are public, however they are minified or obfuscated. Call the LLM from your server, authenticate your own users there, and apply your own per-user limits before forwarding.

The same goes for desktop tools you hand to others. If a teammate needs access to a coding agent, give them their own key on their own account rather than sharing one.

## Why give each workload its own key?

On BroadNet Inference an account can hold **up to ten live keys**. Use them:

| Key label | Used by |
| --- | --- |
| `prod-api` | Production backend |
| `prod-worker` | Batch jobs |
| `staging` | Staging environment |
| `agent-ci` | Coding agent in CI |
| `dev-laptop-<name>` | Local development |

When one leaks, you revoke only that key, and the others keep working. Labels also make usage readable: you can see which workload spends what. Name keys after what uses them, not who created them.

## How do IP allow-lists protect a key?

An [IP allow-list](https://broadrouter.com/glossary/ip-allow-list/) means a stolen key fails anywhere except your own infrastructure. On BroadNet Inference:

-   The account allow-list takes **up to 32 entries**, one IPv4 or IPv6 address or CIDR range per line.
-   An empty list means no restriction.
-   New keys inherit the account list, unless you create a key with its own `allowed_ips`, which replaces the inherited list for that key.
-   A request from an address outside the list is refused with a 403 (“refused by model, route or IP policy”).

Create a key with its own list through the portal API:

```bash
curl -X POST https://inference.broadnet.ai/portal/keys \
  -H "Authorization: Bearer $BROADNET_PORTAL_CREDENTIAL" \
  -H "Content-Type: application/json" \
  -d '{"label":"prod-worker","allowed_ips":["203.0.113.7","198.51.100.0/24"]}'
```

The response contains the raw key once. Store it in your secret manager immediately; it cannot be read back. Full steps are in the [IP allow-list guide](https://broadrouter.com/guides/api-keys-ip-allow-lists/).

Allow-lists suit servers with stable egress IPs: a VPS, a NAT gateway, a fixed office IP. For laptops on changing networks, use a separate key without a list and keep its balance exposure small.

## Why separate inference keys from admin credentials?

BroadNet uses two kinds of credential:

| Credential | Can do | Store it |
| --- | --- | --- |
| Inference key | Model requests to `/v1/*` | Wherever the app runs |
| Portal credential | Create and revoke keys, change allowed IPs, make purchases | Only in your automation or admin tooling |

The docs say to treat each portal credential as full account authority. Never deploy a portal credential next to your application. If your app server is compromised, the attacker should get one inference key, not control of the account.

## How often should you rotate API keys?

OWASP recommends regular rotation “so that any stolen credentials will only work for a short time.” BroadNet keys last **one year** from creation, so every key will need replacing anyway. Make rotation routine:

1.  Create a new key with the same label pattern and allow-list.
2.  Deploy it alongside the old one, or switch the secret and restart.
3.  Watch traffic move to the new key.
4.  Revoke the old key with `DELETE /portal/keys/{alias}`.

Because an account can hold up to ten live keys, you can overlap old and new keys for a few minutes without downtime. Rotate sooner for keys that a departing team member had access to.

## What should you do when a key leaks?

When a key leaks, revoke it first and investigate second. On BroadNet Inference, new requests stop **within five seconds** of a revocation or allow-list change; the docs explain that authorisation decisions may remain in a replicated cache for that bounded interval.

After revoking:

-   check usage for the key in the account page or `GET /portal/usage`;
-   find how it leaked (commit history, CI logs, a shared screenshot);
-   rotate any other secrets stored in the same place.

A revoked or blocked key returns 401 or 403; see the [errors guide](https://broadrouter.com/guides/errors-and-retries/) so your monitoring does not treat those as transient.

## How do keys leak through logs?

Logs are an easy leak to miss. Redact the `Authorization` header in HTTP debug logging, error reporters and proxy access logs. When you contact support, send the `X-Request-ID`, timestamp, route, status and the key **alias**, never the key itself. BroadNet’s docs say the portal stores only a hash of each key, so it cannot show you a lost key either.

## How do you limit the damage of a leak you have not found yet?

Even with every habit above, assume a key may leak someday. Shrink the blast radius:

-   Keep the pay-as-you-go balance at a level you are comfortable losing, and top up as needed.
-   Use a flat plan for heavy agents: a plan session has a fixed price, so a stolen plan key cannot run up a per-token bill. See [what unlimited really means](https://broadrouter.com/blog/what-unlimited-llm-api-really-means/).
-   Alert on unusual spend or request rates per key; the [LLM API cost calculator](https://broadrouter.com/tools/llm-api-cost-calculator/) gives you a normal monthly figure to alert against. Our post on [LLM API spend control](https://broadrouter.com/blog/llm-api-spend-control/) covers budgets and alerts.

## Which key controls does BroadNet Inference provide?

| Control | BroadNet Inference |
| --- | --- |
| Key shown once, stored hashed | Yes |
| Live keys per account | Up to 10 |
| Key lifetime | One year |
| IP allow-list | Up to 32 IPv4, IPv6 or CIDR entries |
| Per-key allow-list | Yes, `allowed_ips` at creation |
| Revocation takes effect | Within five seconds |
| Separate admin credential | Portal credential |

Keys protect your account; [zero data retention](https://broadrouter.com/zero-data-retention/) protects what you send through it. Read both before you ship.

Free tools for this

-   [OpenAI to BroadNet migration helper](https://broadrouter.com/tools/openai-to-broadnet-migration/) Paste OpenAI SDK code; get base URL, key and model edits, a diff and the checks that remain.
-   [max\_tokens calculator for reasoning models](https://broadrouter.com/tools/reasoning-token-budget/) Answer length + reasoning budget + margin = a max\_tokens that does not cut the answer off.
-   [JSON schema generator for LLM structured output](https://broadrouter.com/tools/json-schema-generator/) Sample JSON to strict schema, Pydantic, Zod and a ready request.
-   [LLM JSON output validator](https://broadrouter.com/tools/llm-json-output-validator/) Parse errors by line and column, safe repairs, cut-off detection and JSON Schema checks for model output.

[All free tools](https://broadrouter.com/tools/)

## Terms in this article

[API key](https://broadrouter.com/glossary/api-key/)

An API key is a secret string that identifies and authorizes a client calling an API. LLM APIs usually expect it in an Authorization: Bearer header, and anyone who holds the key can make requests that are billed to the account that owns it.

[AI coding agent](https://broadrouter.com/glossary/coding-agent/)

An AI coding agent is a software tool in which a language model works on a codebase in a loop: it reads files, edits them, runs commands such as tests, reads the output and decides the next step until the task is done or a limit is reached.

[Tool calling](https://broadrouter.com/glossary/tool-calling/)

Tool calling, also called function calling, is an LLM API feature in which the model returns a structured request to run a function the developer has defined, with JSON arguments. The application runs the function and sends the result back; the model never runs code itself.

[IP allow list](https://broadrouter.com/glossary/ip-allow-list/)

An IP allow list is a security control that accepts requests only from listed IP addresses or CIDR ranges and refuses all others. On an API, it limits the damage from a leaked key, because the key does not work from networks that are not on the list.

[Pay-as-you-go](https://broadrouter.com/glossary/pay-as-you-go/)

Pay-as-you-go is a pricing model in which you pay only for what you use, metered per unit such as tokens, requests or audio minutes, with no subscription or minimum commitment. Most LLM APIs bill this way, from a prepaid balance or a periodic invoice.

[Prepaid credit](https://broadrouter.com/glossary/prepaid-credit/)

Prepaid credit is money added to an API account before use. Each request deducts its cost from the balance, and when the balance runs out, metered requests stop until you top up. It caps spend at what you have paid in.

[Zero data retention](https://broadrouter.com/glossary/zero-data-retention/)

Zero data retention (ZDR) is a data-handling policy in which an AI provider processes prompts and outputs only to serve a request and does not store that content afterward, in logs, caches or training data. Content-free records such as token counts and timings are usually still kept.

## Questions

### Where should I store an LLM API key?

In a secret manager or your platform's encrypted secrets, injected into the process as an environment variable such as BROADNET\_API\_KEY. Not in source code, not in a committed .env file, and never in front-end code.

### How fast can I revoke a BroadNet Inference key?

BroadNet's docs say new requests stop within five seconds of a revocation or an allow-list change, because authorisation decisions may stay in a replicated cache for that bounded interval.

### How long does a BroadNet Inference key last?

A pay-as-you-go key lasts one year from creation. An account can hold up to ten live keys, so you can create the replacement before the old one expires.

### Can BroadNet show me a key again if I lose it?

No. BroadNet's docs say the raw key is returned once and the portal stores only its hash. Create a new key and revoke the old one.

### What should I do if my OpenAI-compatible API key leaks?

Revoke it first, then investigate. Check the key's usage for unknown traffic, find where it leaked (commit history, CI logs, screenshots), rotate any other secrets stored in the same place, and issue a replacement key with an IP allow-list.

## Keep reading

-   [LLM API spend control: budgets, key limits and loop protection](https://broadrouter.com/blog/llm-api-spend-control/)
-   [Sending sensitive data to an LLM API: redact, minimise, log less](https://broadrouter.com/blog/llm-api-sensitive-data/)
-   [How to handle LLM API 429 errors: backoff, jitter and limiters](https://broadrouter.com/blog/handle-llm-api-429-rate-limits/)
-   [GDPR and LLM APIs: 15 questions to ask your provider](https://broadrouter.com/blog/gdpr-llm-api-checklist/)
-   [A private endpoint starts with a clear workload](https://broadrouter.com/blog/private-endpoint-planning/)
-   [Before fine-tuning: define the problem to solve](https://broadrouter.com/blog/fine-tuning-readiness/)
-   [Guide: Lock API keys to your servers with IP allow-lists](https://broadrouter.com/guides/api-keys-ip-allow-lists/)
-   [Guide: BroadNet Inference error codes and when to retry](https://broadrouter.com/guides/errors-and-retries/)
-   [Guide: Use the OpenAI Python SDK with BroadNet Inference](https://broadrouter.com/guides/openai-python-sdk/)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=blog-llm-api-key-security&utm_content=page-cta) ·

**Sources**

-   [BroadNet Inference API reference, limits: key lifetime, live keys (fetched 2026-11-14)](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=blog-llm-api-key-security&utm_content=sources#limits)
-   [BroadNet Inference API reference, IP allow-lists and portal keys (fetched 2026-11-14)](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=blog-llm-api-key-security&utm_content=sources#ip-allow-lists)
-   [OWASP Secrets Management Cheat Sheet (fetched 2026-11-14)](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html)
-   [GitHub Docs, secret scanning (fetched 2026-11-14)](https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning)
-   [GitHub Docs, about push protection (fetched 2026-11-14)](https://docs.github.com/en/code-security/secret-scanning/introduction/about-push-protection)
