Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 2 ๐Ÿ“– 12 min read

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,

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 a real key at all: pass a fake string and return a recorded response. Use a real, capped dev key only for integration tests that must hit the network.
  • On SandBase, create the dev key in Console โ†’ Developer โ†’ API Keys with a small spending limit and an expiry date. A key over its limit gets HTTP 402 and an expired key gets 401 (API keys docs); failed calls are not charged (pricing page, 2026-12-03).
  • For $0 testing on SandBase, call deepseek/deepseek-v4.1-flash:free; my 2026-12-03 run recorded user_cost: "0". The 100 free calls a day cover eligible data APIs, not LLMs.
  • No platform I checked offers unlimited free calls to real models. OpenRouter's free models stop at 50 requests a day (1,000 after a $10 credit purchase), and SandBase's free model is limited to 30 requests a minute.

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.

How do I route my API key to a sandbox instead of production?

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 API keys documentation listing the steps to create a key, with an optional spending limit and expiry date

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)

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.

Where can I get a dummy API key for testing AI models locally?

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()
# 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

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.

Terminal output: a free-model call on the dev key with user_cost 0, a missing staging key, a dummy key rejected with 401, and an offline test passing

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.

How do I set up a capped dev key on SandBase?

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.

  1. Open Console โ†’ Developer โ†’ API Keys and click New key.
  2. Name it after the environment and app, for example research-app-dev.
  3. Set a Spending limit that matches what a day of testing should cost. A few dollars is plenty for chat models.
  4. Set an Expires date. For a contractor or a demo, make it days, not months.
  5. Copy the key from the creation banner. It is shown once.
  6. Put it in .env (listed in .gitignore) or your CI secret store as SANDBASE_API_KEY_DEV.

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.

Can I test AI models for $0?

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 page listing 100 free data API calls a day, $0 discovery, $0 sandboxes and $0 failed calls

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.

SandBase model page for DeepSeek V4.1 Flash (free) showing $0.00 input and output price and a 30 requests per minute limit

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.

Which unified AI platforms give you a free API key for testing?

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.

Platform Free calls for testing Per-key spend cap Environment separation Failed calls
SandBase A $0 chat model (30 req/min); 100 free data API calls a day per org; starter credits on the $0 Start plan Spending limit per key, 402 when reached One key per environment; optional expiry per key Not charged
OpenRouter 25+ free models; 20 req/min and 50 req/day, 1,000/day after buying $10 of credits Per-key credit caps inside a workspace; the pricing table lists Budgets & Spend Controls only on paid plans Workspaces: 5 on Free and Standard, 1,000 on Business Not charged for tokens, but count toward the free daily cap
Vercel AI Gateway Free tier covering a subset of models, with a monthly free credit; per-model rate limits, 429 above them API key budgets, 402 quota_for_entity_exceeded Keys can be scoped to a Vercel project; optional expiry Not stated on the pages I read
LiteLLM (self-hosted) None from LiteLLM; you pay your own providers max_budget on virtual keys Virtual keys per environment; duration sets expiry Depends on your providers

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 pricing table: Free plan with 25+ free models and no Budgets & Spend Controls; Standard and Business with 700+ models and spend controls

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.

Is there a unified AI API plan with unlimited sandbox testing keys?

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.

A short checklist before you ship

  • One key per environment and app, named after what runs it. The production key lives only in the production secret store.
  • .env in .gitignore and a secret scanner on the repo. If a key is committed, revoke it first and clean history second.
  • Dev and staging keys get a spending limit and an expiry date.
  • Test runners treat 401 and 402 as stop conditions and retry only 429 and transient 5xx errors.
  • Rotate by deploying the new key, confirming traffic, then revoking the old one.

Limits of this guide

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.

FAQ

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.

Related reading

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.