Send the key
Put the key in theAuthorization header of every request, using the Bearer scheme:
Key format
A key is the prefixsfs_live_ followed by 43 characters from the set 0–9, A–Z and a–z: 52 characters in total. Treat it as an opaque, case-sensitive string. A value that does not have this shape is answered 401 invalid_api_key, like any other bad key.
Keys that start with sfs_test_ are rejected by the production API.
Organisation keys and partner keys
The Surfais team creates and revokes the links between a partner account and its organisations.
PATCH /orgs/{orgId}/link is a write, and the write rule below is checked first. A key without the write scope gets 403 write_scope_required there, whichever kind of key it is.
Scopes and the write rule
Two settings decide what a request may do.- The key’s scopes. A key is issued with
read, or withreadandwrite, according to the access your plan, or your partner agreement, includes — see Who can use it. Every key carriesread. - The link’s scope (partner keys only). A partner’s link to each organisation is
read_onlyorread_write. You can read it aslink_scopeonGET /orgs. An organisation key has no link: only its own scopes apply.
read. A write — any POST, PATCH, PUT or DELETE — needs the write scope and, for a partner key, a read_write link.
Webhook management writes need the
write scope too, and answer the same 403 write_scope_required without it. They involve no organisation, so no link scope applies.
An organisation your key cannot reach is
404 not_found before any write-rule 403 (write_scope_required, link_scope_insufficient or partner_only). The API never confirms that an organisation exists. A refused write is also rejected before its body is read, so a 403 says nothing about whether the body was valid, and it does not use up an Idempotency-Key.Access is re-checked on every request
An organisation key works only while its organisation is on a plan that includes API access. The plan is checked on every request. If the organisation moves to a plan without API access, the key’s next call is answered403 tier_not_entitled:
403 counts against the key’s per-minute allowance like any other request, so it carries the X-RateLimit-* headers, and a key that is already over its allowance is answered 429 rate_limited first.
Partner keys have equivalent checks. The partner account must be active, or every request is 401 invalid_api_key. The link to the organisation in the path must be active, or the request is 404 not_found.
When authentication fails
Every authentication failure is the same response, deliberately. It does not tell the caller which check failed.401 invalid_api_key when:
- the
Authorizationheader is missing, or is notBearerfollowed by a key; - the key does not have the key format;
- the key is unknown, revoked or expired;
- the key starts with
sfs_test_; - the key belongs to a platform partner whose account is suspended;
- the key belongs to an organisation that has been deleted.
401. The same request fails the same way until the key is fixed.
Repeated failures are throttled
Failed attempts are counted per client IP address, per minute. After too many in one minute, requests from that address that present a key are answered429 rate_limited until the minute ends — even when the key is valid. The response carries Retry-After, the number of seconds until the minute ends. On this 429, the X-RateLimit-* headers describe the address’s failed-attempt allowance, not your key’s rate limit.
Every 401 for a request that presented a key counts, whatever the reason. A request with no usable Authorization header is answered 401 but is not counted.
Keep keys safe
- Call the API from your server only. CORS is disabled: the API never sends an
Access-Control-Allow-Originheader, so a browser refuses the responses, and a preflight request is answered405 cors_disabled. Never ship a key in a web page or a mobile app. - Store keys in a secret manager. Keep them out of source control, logs and error reports.
- Use one key per integration and per environment. One key can then be revoked without touching the others.
- Ask for the least access you need. Ask for a
readkey unless the integration changes what is tracked. Write access also depends on your plan. - Set an expiry where it helps. A key can be issued with an expiry date, which suits a contractor or a time-boxed project. Without one, a key does not expire. After its expiry, a key is answered
401 invalid_api_key. - Never send a whole key to anyone, Surfais included. Surfais keeps only a hash of each key, so a lost key cannot be recovered — ask for a new one.
sfs_live_ prefix plus the next three. That is enough to tell your keys apart, and too little to be of use to anyone else.
Rotate a key
Two keys work side by side, so you can rotate without downtime.- Ask support@surfais.com for a new key with the same access.
- Deploy the new key, and confirm your traffic has moved to it.
- Ask for the old key to be revoked. A revoked key is answered
401 invalid_api_keyfrom its next request.
Related
- Errors — the error envelope and every error code.
- Rate limits — per-minute limits, monthly quotas and
Retry-After.