Test API Keys for AI Models: Dev, Staging and Sandbox Keys (2026)
Originally published on the SandBase Blog . Key takeaway Unified AI APIs generally do not have a Stripe-style test mode. A "sandbox key" is a normal key that you create for one environment, cap with a spending limit, give an expiry date, and revoke when you are done. For unit tests you do not need

Posted on Dec 4 • Originally published at blog.sandbase.ai
Originally published on the SandBase Blog.
Here is how it usually goes: "staging used the prod key for a week." Nothing leaked. The staging deploy read a shared secret, the shared secret held the production key, and a load test ran against the production balance. The team had one key and several environments.
This guide is for developers who call LLMs through a unified API and want a "test key" or "sandbox key" that cannot spend production money. It covers the pattern that works anywhere, the SandBase setup, and what OpenRouter, Vercel AI Gateway, LiteLLM and SandBase give you for free, from each vendor's own pages read on 3 December 2026.
Route by key, not by URL. None of the four platforms compared below documents a separate sandbox host or a test-mode key type in the pages I read. You create one key per environment and let the environment decide which key the process loads. The base URL stays the same.
SandBase's API keys documentation spells this out in an "Environment strategy" table: one key each for local development, staging and production, plus a temporary key with an expiry for one-off automation. There is no test-mode key type. Each key gets a name, an optional spending limit, an optional expiry and a Revoke button, and usage is billed to the owning organization.
SandBase's API keys page on 2026-12-03: create a key under Developer → API Keys, optionally with a spending limit (empty means unlimited) and an expiry date (empty means no expiry).
In code, give each environment its own variable name, pick it from APP_ENV, and fail loudly when it is missing. Falling back to "whatever key is set" is how staging ends up on the production key.
import os import sys from openai import OpenAI # One key per environment: SANDBASE_API_KEY_DEV, _STAGING, _PROD. APP_ENV = os. environ. get ( "APP_ENV", "dev" ) KEY_VAR = { "dev": "SANDBASE_API_KEY_DEV", "staging": "SANDBASE_API_KEY_STAGING", "prod": "SANDBASE_API_KEY_PROD", }. get ( APP_ENV ) if KEY_VAR is None: sys. exit ( f "unknown APP_ENV={APP_ENV}" ) api_key = os. environ. get ( KEY_VAR ) if not api_key: sys. exit ( f "{KEY_VAR} is not set for APP_ENV={APP_ENV}" ) # Dev runs on the $0 model; staging and prod use the model you ship. MODEL = { "dev": "deepseek/deepseek-v4.1-flash:free", "staging": "deepseek/deepseek-v4.1-flash", "prod": "deepseek/deepseek-v4.1-flash", } [ APP_ENV ] client = OpenAI ( api_key = api_key, base_url = "https://api.sandbase.ai/v1" ) resp = client. chat. completions. create ( model = MODEL, messages = [ { "role": "user", "content": "Reply with exactly: dev key ok" } ], max_tokens = 64, ) print ( APP_ENV, resp. model, repr ( resp. choices [ 0 ]. message. content ), resp. usage. total_tokens ) Enter fullscreen mode Exit fullscreen mode I ran this with the openai Python SDK 3.63.0.
With APP_ENV=dev it returned 'dev key ok' from the free model. With APP_ENV=staging and no staging key exported, it exited with an error instead of quietly borrowing another key. That second result is the one that prevents the incident above.
Name keys after the deployment that uses them ( support-bot-staging, not daniel-test ), so that when one shows up in a usage spike you know what to turn off.
You can make one up. For unit tests, a dummy key is any string, because the request should never leave the process. The test replaces the client with a stub that returns a response you recorded once from a real call. No account, no network, no cost, and the test gives the same result on a plane.
The cleanest way to do that is to pass the client into your code instead of building it inside the function:
# app.py def label_ticket ( client, model, text ): resp = client. chat. completions. create ( model = model, messages = [ { "role": "user", "content": f "One-word label for: {text}" } ], max_tokens = 16, ) return resp. choices [ 0 ]. message. content. strip ( ). lower ( ) Enter fullscreen mode Exit fullscreen mode # test_app.py from types import SimpleNamespace from unittest. mock import MagicMock from app import label_ticket # Recorded once from a real dev-key call, then frozen in the repo. RECORDED = SimpleNamespace ( choices = [ SimpleNamespace ( message = SimpleNamespace ( content = "Billing" ) ) ] ) def test_label_ticket_offline ( ): fake = MagicMock ( ) # no key, no network fake. chat. completions. create. return_value = RECORDED assert label_ticket ( fake, "any-model", "I was charged twice" ) == "billing" sent = fake. chat. completions. create. call_args. kwargs assert sent [ "max_tokens" ] == 16 Enter fullscreen mode Exit fullscreen mode I ran that test with an empty environment ( env -i, so no key variable existed) and it passed. I stubbed the client instead of the HTTP layer on purpose: openai 3.63.0 depends on a new HTTP client package ( httpx2 ) instead of httpx, so transport-level mocks written for older SDK versions can break on upgrade.
A dummy key tests your code, not the provider. It will not catch a renamed model or a changed response field. That is the job of a small integration suite that runs with a real dev key before a release, not on every save.
If a fake key does reach the real API, it fails clearly: sk-test-0000000000000000 got HTTP 401 {"error":"invalid API key"} from SandBase. A 401 in a unit test means the test is wired to the network.
My run on 2026-12-03 (UTC): the dev key called deepseek/deepseek-v4.1-flash:free and the account history row for that request id shows user_cost: '0'; the dummy key got 401; the offline test passed with no key in the environment.
The steps below come from the SandBase docs. I could not log in to the Console for this article, so I did not create or revoke a key myself.
The edges are documented. A key at its spending limit gets 402 - API key spending limit exceeded; an expired key gets 401 - API key has expired; a revoked key gets 401 - API key has been revoked, and revocation cannot be undone. The errors reference says not to retry an unchanged 401 or 402. The key list shows Spent, Limit, Expires and Status, and Request History can be filtered by key, which is how you prove a staging test never touched the production key.
Know the limits of this setup. All keys share one organization balance, so a dev key's cap protects production only if you set it. And the Console does not offer scopes for a standard key, so a dev key can call the same endpoints as a production key. Separate keys limit spend and blast radius; they do not create a separate data world.
On SandBase, yes, within limits. Three things on the pricing page apply to testing: failed model or API calls are not charged, agent sandboxes (code runtimes, unrelated to API keys) are free for now with possible fair-use caps, and the Start plan is $0 with starter credits and no subscription. The page does not state the starter credit amount.
SandBase pricing on 2026-12-03: pay per call with no subscription and no credit card to start; 100 free calls a day for eligible data APIs, reset at 00:00 UTC; free sandboxes for now; failed calls not charged.
For LLM tests, the $0 option is DeepSeek V4.1 Flash (free), model id deepseek/deepseek-v4.1-flash:free. Its page lists $0.00 per 1M input and output tokens, a 1M-token context window and support for tool calling and structured output. It is rate limited: 30 requests a minute by default, 60 after a single $10 top-up, and HTTP 429 above the limit. That is fine for a test suite and too tight for a load test.
The free model page on 2026-12-03: $0.00 / $0.00 per 1M tokens, 1M context, 384K max output, and "Free model · 30 / min" with HTTP 429 above the limit.
I checked the $0 claim instead of trusting the label. The chat response has token counts but no cost field. The cost is in GET /v1/account/history: the row for my request id showed status: completed, 51 total tokens and user_cost: "0".
Do not mix these up: the 100 free calls a day cover eligible data APIs (search, social and similar data endpoints), shared by the organization. They do not cover LLM tokens. An integration test on a paid chat model spends real money, capped by the dev key's limit.
All four platforms below let you create a key for free; the best one depends on what your tests call. For free chat calls, SandBase's free model allows 30 a minute and OpenRouter's free models 50 a day until you buy credits. For hard dollar caps per key on a managed gateway, SandBase, OpenRouter's paid plans and Vercel all qualify. If keys must live in your own infrastructure, use LiteLLM. Details below come from each vendor's own pages, read on 2026-12-03.
OpenRouter's pricing FAQ answers the environment question directly: "Workspaces give each environment its own keys, limits and activity." Within a workspace, each API key can carry its own credit cap. The comparison table marks Budgets & Spend Controls as unavailable on Free, and the FAQ does not say whether per-key credit caps work on the Free plan.
OpenRouter's pricing page on 2026-12-03: Budgets & Spend Controls are marked unavailable on Free and available on Standard, Business and Enterprise.
Vercel's budgets documentation (updated 2026-11-19) has the most detailed per-key controls of the managed options: budgets stack across team, project, key and member, and a key without a budget has unlimited spend. Its pricing page says buying credits moves you to the paid tier, where the monthly free credit no longer applies. That page does not state the free credit amount.
LiteLLM's virtual keys are the self-hosted version of the same idea. You run the proxy with a Postgres database and a master key, then call /key/generate to mint keys with an allowed model list, a max_budget and a duration. The software is free. The model calls still go to your own provider accounts, so a "free key" there means free to create, not free to use. For the trade-offs of running it, see LiteLLM explained.
Not with unlimited free model calls. I did not find any plan, on these four platforms, that gives unlimited free requests to real hosted models. Every free option has a cap: a rate limit (SandBase's free model at 30 a minute), a daily limit (OpenRouter's 50, or 1,000 after $10), a credit grant (Vercel's monthly free credit, SandBase's starter credits), or your own provider bill (LiteLLM).
What can be unlimited is the number of keys and the spend on an uncapped key. SandBase's docs call an empty spending limit "unlimited" and do not state a cap on how many keys an organization can create; I did not test one. OpenRouter caps workspaces (5 on Free and Standard, 1,000 on Business) but the pages I read state no per-workspace key limit.
So the honest version of "unlimited sandbox testing keys" is: create as many keys as you need, cap each one, and keep the truly unlimited testing (mocks and recorded responses) off the network. No subscription is needed for that on SandBase: the Build plan is metered, pay per call.
I verified one real free-model call, the dummy-key 401 and the offline test. I did not create, cap or revoke a key in any Console, so the 402 and expiry behavior comes from SandBase's docs. Third-party rows come from vendor pages read on 2026-12-03 and can change. I did not verify Vercel's failed-call billing, any platform's key-count limit, or the starter and free credit amounts.
Does SandBase have a test mode or sandbox API key? No separate key type. You create a normal key for your dev or staging environment, give it a spending limit and an expiry date, and revoke it when finished. Usage is billed to your organization like any other key.
Can I run integration tests for free? Yes, if the test can use deepseek/deepseek-v4.1-flash:free on SandBase or a free model on OpenRouter, within their rate limits. Tests that need a specific paid model cost money, so cap the key.