Authentication¶
Every merchant API request authenticates with the API key in the X-Api-Key header. A key is bound to one merchant and to one environment (test or live): a test key can never see or charge live objects.
Keep the key on the server
The API key is a secret. Never embed it in browser JavaScript or a mobile app. Buyer-facing checkout endpoints (/v1/payments/session/{id}, /v1/payments/intent, /v1/payments/subscription) do not need a key: the unguessable session ID is their credential.
Where to get a key¶
- Sign in to the 4Geeks Console.
- Open Settings → API Keys.
- Use the Test key immediately; the Live key unlocks after Business Verification (KYC) is approved.
Production keys use the sk_live_ prefix and test keys sk_test_. Keys created before the prefix change (pk_live_ / pk_test_) keep working: the server looks keys up by their hash, not by their prefix.
Environments¶
| Key | Environment | When it is available | Money |
|---|---|---|---|
sk_test_… | Sandbox | Immediately after sign-up | Never moves real money |
sk_live_… | Production | After KYC approval | Real charges and payouts |
A request made with a test key is automatically scoped to test objects, even if the same merchant also has a live account. See Testing cards for sandbox card numbers.
Code examples¶
Errors¶
| Status | Meaning |
|---|---|
401 | Missing, malformed or unknown API key |
403 | The key does not own the requested object |
404 | The object does not exist or belongs to another merchant |
409 | Business rule (for example the merchant has no approved payment account) |
422 | Validation error (amount, currency, URL, mode) |
429 | Rate limit exceeded |
Validation errors use FastAPI’s envelope:
{
"detail": [
{ "loc": ["body", "amount"], "msg": "field required", "type": "value_error.missing" }
]
}
Business errors use a stable machine-readable code:
{
"detail": {
"code": "gateway_account_not_configured",
"message": "The merchant has no payment account configured for this mode."
}
}
Common payment codes: gateway_account_not_configured, gateway_account_not_approved, session_not_found, session_not_pending, wrong_session_mode, subscription_no_payment_required, already_refunded, amount_exceeds_refundable.
FAQ¶
Can I use the same key on the frontend? No. Only the checkout session ID is safe to expose. Keep the API key on your server.
Do keys expire? No. Rotate them from the console if one leaks.
Can I have multiple keys? One test key and one live key per merchant account. The console shows both.
How do webhooks authenticate? Webhooks are delivered by 4Geeks to your endpoint; verify the signature, not an API key. See Payments API.
Still have questions? Ask on Discord or explore the tutorials.