Appearance
Authentication and environments
Every route takes a bearer token in the Authorization header, unless the reference says it needs none. There are two kinds of token, and every project request acts on one environment.
A person's token
A member of your organization signs in with a one-time code sent by email:
| Step | Request | Answer |
|---|---|---|
| Ask for a code | POST /v1/auth/magic with {"email": "..."} | the code goes to that address; the account is created on first use |
| Exchange it | POST /v1/auth/magic/verify with {"email": "...", "code": "123456"} | data.token (the bearer token) and data.refresh_token |
| Renew | POST /v1/auth/refresh with {"refresh_token": "..."} | a new token and a rotated refresh token |
bash
curl https://api.frege.io/v1/me -H "Authorization: Bearer $TOKEN"A person's token can do what that person's role allows, in the environments they were invited to:
| Role | What it can do |
|---|---|
| Admin | The organization's admin: everything, including billing, organization limits, write policy and tool mode. |
| Manager | Runs a project: members, API keys, agents, publishing and promoting. |
| Developer | Builds: spec, tools, upstream sign-in, docs, hooks. |
| Viewer | Reads. |
Changes to Production that matter (promoting, publishing, deleting) also ask for a code emailed to the person, so a token alone cannot make them. See Quickstart.
A project API key
An API key lets your own code (a backend, a bot, a script) work with a project with no person signing in. Admins and managers make them in the dashboard (API keys) or with POST /v1/projects/{id}/api-keys:
bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/api-keys" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: live" \
-H "Content-Type: application/json" \
-d '{"name": "Order bot"}'- A key looks like
frege_sk_.... Its value is in the answer'skeyonce, and never again: Frege keeps only a hash. - A key belongs to the environment it was made in. It acts there whatever you send; naming another environment answers
422("this API key is bound to the staging environment and cannot act on live"). nameis at most 100 characters.expires_at, if you send it, must be in the future.- Revoke a key with
DELETE /v1/projects/{id}/api-keys/{keyID}.
Send it like any bearer token: Authorization: Bearer frege_sk_....
What a key can reach
A secret key (the default kind) reaches only these routes of its own project, under the environment's write policy:
| Routes | What for |
|---|---|
GET /v1/projects/{id}/operations, GET /v1/projects/{id}/tools/search | List and search the tools |
POST /v1/projects/{id}/tools/{toolName}/invoke | Run a tool as a customer (Running tools) |
GET /v1/projects/{id}/agents, GET /v1/projects/{id}/agents/{agentRef}, .../models, .../runtime | Read agents |
POST /v1/projects/{id}/agents/{agentRef}/run, .../stream | Run an agent turn (Agents API) |
GET, POST /v1/projects/{id}/attachments, DELETE /v1/projects/{id}/attachments/{attachmentID} | Files for agent turns |
GET /v1/projects/{id}/tasks, GET /v1/projects/{id}/tasks/{taskID}, POST .../cancel | Background tool calls |
Every other route refuses it. A key never opens an MCP server: MCP clients sign in with OAuth (see MCP servers and sign-in).
Widget keys
A key of kind widget is the one to put in a web page, for the chat widget. It only starts the chat for a person who signed in through that page, on your verified sites; every other route refuses it. Make one with {"name": "Website chat", "kind": "widget"}. Never put a secret key in a page: whoever copies it can act as any of your customers.
Environments
Every project has two environments: Staging, key staging, and Production, key live. A project request chooses one:
- the
X-Frege-Stageheader,stagingorlive; or - the
stagequery parameter, with the same values.
The header wins when both are sent. With neither, a person's request acts on Production (live), and a key's request on the key's own environment. Any other value answers 422 validation_failed with fields.stage = "must be staging or live".
Two exceptions:
- Spec uploads and deletions must name the environment. There is no default on purpose, because an upload is live in its environment at once.
- Skills are written in Staging only, and reach Production by promotion.
bash
curl "https://api.frege.io/v1/projects/$PROJECT/spec" \
-H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: staging"The two environments are independent: each has its own spec, sign-in recipe, variables and secrets, customers, API keys, hooks, agents and settings. Promotion copies Staging's spec and sign-in to Production; customers' credentials are never copied.