Skip to main content

Environments

Separate your API keys into live and test environments in Unkey. Isolate production traffic from development with environment-scoped keys.
2 min read

Environments let you issue distinct keys for development, staging, and production. Test keys can't affect real resources, while live keys have full access.

When to use this#

Safe development

Developers can test integrations without touching production data.

Automated testing

CI/CD pipelines can run tests with keys that won't affect live resources.

Different limits

Test keys might have lower rate limits or be free to use.

Prevent accidents

Prefixes like sk_test_ make it obvious when using non-production keys.

How it works#

Environments are implemented using key metadata and prefixes, there's no special "environment" field. This gives you full flexibility to model environments however you want.

Common pattern:

  • Prefix: sk_test_ vs sk_live_ (visible to users)
  • Metadata: { "environment": "test" } (returned on verification)

Create environment-specific keys#

Tip

Using prefixes makes it obvious to users which environment a key is for. This prevents accidental use of test keys in production (or worse, live keys in tests).

Verify and check environment#

The metadata is returned during verification, so your API can behave differently:

Response:

Handle environments in your API#

Common patterns#

Different rate limits per environment#

Sandbox vs real resources#

Block test keys from production endpoint#

Next steps#