Overview
The API maintains two completely separate environments: test mode and live mode. Every API object includes alivemode boolean field indicating which environment it belongs to.
livemode: true— the object was created with a live key and represents real money.livemode: false— the object was created with a test key and is for development only.
Key prefixes and environments
| Key prefix | Environment | Accesses |
|---|---|---|
sk_test_ | Test | Test data only |
pk_test_ | Test | Test data only |
sk_live_ | Live | Live data only |
pk_live_ | Live | Live data only |
Complete data isolation
Test and live data are isolated at the database level. This means:- A
sk_test_key cannot read, update, or delete objects created with ask_live_key. - A
sk_live_key cannot read, update, or delete objects created with ask_test_key. - Customer IDs, PaymentIntent IDs, and all other identifiers are unique per environment.
Checking livemode in code
Always verify thelivemode field when processing webhooks or debugging issues:
Best practices
- Use separate API keys per environment. Store
sk_test_in your development/staging config andsk_live_in production. - Never use live keys in development. Test keys give you the same API behavior without moving real money.
- Check
livemodein webhook handlers. If you use the same webhook endpoint for both environments, always verify thelivemodefield before taking real-world actions. - Use test card numbers. In test mode, use payment methods like
pm_card_visaandpm_card_declinedto simulate different outcomes.
Test mode capabilities
Test mode supports all the same API endpoints and behaviors as live mode, including:- Creating and confirming PaymentIntents
- Simulating successful and failed payments
- Refunds and cancellations
- Pagination, metadata, and expand
- Webhooks (delivered to your configured test endpoint)