Authentication
API keys, scopes, origins, and the two limits worth knowing before you build.
Updated
On this page
Two ways in, kept strictly apart. A person using the dashboard presents a
short-lived session token. A program presents an API key. Both arrive on
Authorization: Bearer, and the platform tells them apart by the
shape of the credential, not by the header.
API keys
A key is self-describing:
vox_sk_live_<43 url-safe characters> secret, server-side only
vox_sk_test_<43 url-safe characters>
vox_pk_live_<43 url-safe characters> publishable, safe in a browserThat shape is deliberate. A key found in a log, a paste or a public repository is instantly identifiable as ours and as which kind, which is what lets automated secret scanning revoke it before somebody else uses it.
cURL
curl https://api.voxcore.net/api/v1/orgs/<org_id>/contacts/ \
-H "Authorization: Bearer vox_sk_live_..."Python
import os, httpx
BASE, ORG = "https://api.voxcore.net", os.environ["VOXCORE_ORG"]
AUTH = {"Authorization": f"Bearer {os.environ['VOXCORE_API_KEY']}"}
page = httpx.get(f"{BASE}/api/v1/orgs/{ORG}/contacts/", headers=AUTH).json()Python (voxcore)
# pip install voxcore
from voxcore import Voxcore
# Reads VOXCORE_API_KEY and VOXCORE_ORG from the environment.
with Voxcore() as vox:
for contact in vox.contacts.iterate():
print(contact["display_name"])The environment is where a key belongs. The alternative is a file that ends up in a commit. The client holds a connection pool, so make one and reuse it instead of building a new one per call. It works as a context manager if you want the pool closed at the end.
X-Voxcore-Key is accepted as an alternative header, and it takes
precedence when both are present.
Every error the library raises inherits from VoxcoreError, so
one except catches everything it raises and nothing it doesn't.
AuthenticationError means the key is wrong, expired or revoked, and
retrying will never help. PermissionDenied means the key is fine
and is missing a scope. Each error carries .code,
.message, .status and .request_id. Quote
the request id in a support conversation; it's how one request is found in the
logs.
Creating a key
cURL
curl -X POST https://api.voxcore.net/api/v1/orgs/<org_id>/keys/ \
-H "Authorization: Bearer vox_sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"name": "Nightly export",
"kind": "sk",
"environment": "live",
"scopes": ["contact:view", "call:view"],
"expires_at": null
}'Python
import os, httpx
BASE, ORG = "https://api.voxcore.net", os.environ["VOXCORE_ORG"]
AUTH = {"Authorization": f"Bearer {os.environ['VOXCORE_API_KEY']}"}
created = httpx.post(
f"{BASE}/api/v1/orgs/{ORG}/keys/",
headers=AUTH,
json={
"name": "Nightly export",
"kind": "sk",
"environment": "live",
"scopes": ["contact:view", "call:view"],
"expires_at": None,
},
).json()
print(created["key"]) # the only time it existsPython (voxcore)
from voxcore import Voxcore
vox = Voxcore()
created = vox.keys.create(
name="Nightly export",
kind="sk",
environment="live",
scopes=["contact:view", "call:view"],
)
print(created["key"]) # the only time it existskind defaults to sk and environment to
test. The 201 response carries the plaintext key as
key, and that is the only time it will ever exist.
Only a SHA-256 of the key is stored, plus a short display prefix and the last four characters. This is stricter than encrypting a recoverable copy: nothing in the database, in a backup or in a snapshot can be turned back into a working credential. "Show me that key again" is answered with "rotate it".
Scopes
scopes is a list of exact permission strings such as
contact:view or agent:view. Three things about it:
- An empty list means everything the organization's plan allows. A populated list is a strict subset.
- Matching is exact string membership. No wildcards, no hierarchy.
contact:updatedoes not implycontact:view. - Scope strings are not validated on creation. A typo produces a key that is silently locked out of everything.
Publishable keys and origins
A pk key is meant to ship to browsers, so the key itself is not
a secret. allowed_origins is what stops somebody lifting it out of
your page and running it from their own domain. An empty list means any origin.
That's permitted, though not encouraged, and the create response says so with a
warning field.
Matching is exact host, or a single leading-wildcard subdomain
(*.example.com). There is no suffix matching, so
evil-example.com can never satisfy example.com.
Revoking
cURL
curl -X POST https://api.voxcore.net/api/v1/orgs/<org_id>/keys/<key_id>/revoke/ \
-H "Authorization: Bearer vox_sk_live_..."Python
import os, httpx
BASE, ORG = "https://api.voxcore.net", os.environ["VOXCORE_ORG"]
AUTH = {"Authorization": f"Bearer {os.environ['VOXCORE_API_KEY']}"}
httpx.post(
f"{BASE}/api/v1/orgs/{ORG}/keys/{key_id}/revoke/", headers=AUTH
).raise_for_status()Python (voxcore)
from voxcore import Voxcore
vox = Voxcore()
vox.request("POST", f"/api/v1/orgs/{vox.org}/keys/{key_id}/revoke/")There is no PATCH and no DELETE on a key. A key is
created and revoked. It's never edited, and the row stays so the audit trail
survives.
What a rejected key says
| Code | Means |
|---|---|
bad_key | Malformed, or no such key. |
key_revoked | Revoked. |
key_expired | Past its expires_at. |
org_inactive | The organization is no longer active. |
origin_missing | A publishable key with an origin list, called without an Origin header. |
origin_denied | Called from a host that is not on the list. |
Two limits worth knowing before you build
What a key may do is decided by its scopes
Keys read and write. A key issued with no scopes is unrestricted within its plan, which is how keys are issued by default, so a fresh key can do anything your plan allows.
Narrow a key by giving it a scope list, and it is then held to exactly that
list. A key scoped to contact:view reads the directory and is
refused on every write, with a message naming the scope it is missing rather
than talking about roles, which a key does not have.
Two things a key never gets, whatever its scopes. It cannot act outside its own organization, and it cannot do the things that belong to a person rather than to a program: inviting a member, changing somebody's role, or altering billing. Those need a signed-in human.
What a key creates is recorded as authored by nobody, because no person authored it. The audit log names the key that did it, so a change made by a program is still traceable to a credential you can revoke.
The organization in the path is not what scopes a key
A key already names its organization, and that is what the request is scoped
to. The <org_id> in the URL is not checked against it, so a
key belonging to organization A calling organization B's path returns
organization A's data rather than a 404.
That isn't a cross-tenant leak. You can only ever read your own rows. It does mean the URL is not authoritative for key-authenticated calls, so put your own organization id in the path and keep it there.