Get started

API keys & tokens

Your server holds a key; your users' browsers hold tokens your server gives them. A key opens one project — or, for an organization key, any project of its organization. Every API takes them the same way.

01

Project keys

Each project has one key: xf_ and 32 characters. It is shown once, when the project is made or its key rotated — XFiles keeps only a hash of it. Send it as a bearer token, to the files API and the platform alike.

every request
1curl https://www.xfiles.dev/api/v1/files \
2 -H "Authorization: Bearer xf_AbC12dEfGhIjKlMnOpQrStUvWxYz9012"
02

Rotating a key

Lost or leaked? Under Keys & access → Rotate key a new key is shown once. The old one stops at once — or, if you choose, keeps working for 24 hours so a rolling deploy has no gap. Links, files, bundles and the platform's user tokens already handed out keep working: they are signed with other keys. To end every user token too, tick "Also end every user token".

03

Browsers & origins

A key is a server secret. A key sent from a browser is accepted only from the origins the project lists under Keys & access — and even then, prefer a token: a key can do anything in its project, a token only what you allow.

Origins: Origins match exactly — scheme, host and port: https://www.shop.example is not https://shop.example — and there are no wildcards. A key from an origin not on the list gets 403.

04

User tokens

For the platform — search, live updates, chat, notifications, multiplayer and email — browsers use a token your server mints for one user, with the scopes you choose. It lasts an hour by default (24 hours at most); ask for a new one a minute before expiresAt.

your server
1curl -X POST https://platform.xfiles.dev/v1/auth/tokens \
2 -H "Authorization: Bearer $XFILES_KEY" -H "Content-Type: application/json" \
3 -d '{ "userId": "user_42", "name": "Ana", "scopes": ["search", "realtime", "messages", "notifications"] }'
4# → { "token": "eyJ…", "expiresAt": "…" }
searchQueries on public collections, users' collections, and the restricted documents the user may see.
realtimeThe WebSocket, channel history and presence.
messagesChat as that user.
notificationsThe user's own notifications, preferences and push subscriptions.
gamesRooms, matchmaking and playing.
emailThe mailboxes the token names — their mail, never their administration.

A token without a userId is anonymous: it can search and listen to public: channels, nothing else. Rotating the project key leaves tokens working; ending them all is its own act (above), and they stop within a minute. The platform guide covers channel grants and every scope in detail.

05

Organization keys

A SaaS gives each of its customers a project. An organization key (xfo_…, made under Organization in the dashboard) acts as any project of its organization: name the project on every request with X-XFiles-Project. It is for servers only — a request with an Origin header is refused.

one key, many projects
1# Make a project for a new customer (a retry with the same externalId returns the same project)
2curl -X POST https://www.xfiles.dev/api/v1/projects \
3 -H "Authorization: Bearer $XFILES_ORG_KEY" -H "Content-Type: application/json" \
4 -d '{ "name": "Acme Bakery", "externalId": "tenant_812" }'
5
6# Then act as it
7curl https://www.xfiles.dev/api/v1/files \
8 -H "Authorization: Bearer $XFILES_ORG_KEY" \
9 -H "X-XFiles-Project: <project id>"

The projects API also lists, changes, deletes (restorable for 30 days) and restores projects, ends a project's user tokens, and reports each one's usage — see Organizations.

06

When a call is refused

401No key or token, a wrong one, an expired token, or a key rotated away.
402Out of credit: uploads stop at once; private links and the platform pause 7 days later, until a top-up.
403An origin the project does not allow, a scope the token lacks, a suspended account, or a deleted project.
429Too many requests: wait the Retry-After seconds.

Building with an AI assistant?

Point it at the complete reference, or connect the MCP server so it can read these docs and use your project.