# HTTP API

Call Amiril's HTTP API from your own code with an OAuth access token. Find the base URL, the sign-in steps for a token, the environment header and the errors.

The HTTP API reads and changes the data in your Amiril workspace. Every request goes to `https://api.amiril.ai`, and every path starts with `/api`. The pages under **HTTP API** in the sidebar list every route an access token can call.

## Access tokens [#access-tokens]

Send an OAuth access token in the `Authorization` header.

```http
GET /api/rules HTTP/1.1
Host: api.amiril.ai
Authorization: Bearer <access-token>
```

Your code gets a token through an OAuth 2.1 sign-in. A person signs in once in the browser and picks a workspace. Any OAuth 2.1 client library with discovery and PKCE runs these steps for you.

1. Fetch `https://api.amiril.ai/.well-known/oauth-protected-resource/mcp`. Its `authorization_servers` field names the authorization server.
2. Fetch `/.well-known/oauth-authorization-server` from that server. It lists the authorization, token and registration endpoints.
3. Register your client at the `registration_endpoint`.
4. Run the authorization code flow with PKCE. Set `resource` to one of the two addresses below, and ask for the `offline_access` scope.
5. Call the API. The access token expires after five minutes, so use the refresh token to get a new one without another sign-in.

The `resource` you ask for decides what the token can call.

| Token | `resource` | What it can call |
| --- | --- | --- |
| Full | `https://api.amiril.ai/mcp` | Every route in this reference |
| Read-only | `https://api.amiril.ai/mcp/readonly` | Only the routes that read or dry-run |

The token acts as the person who signed in, in the workspace they picked. Their role in that workspace decides what it may change. Each route says which token it needs. No token can change members, invitations, API keys or workspace settings. Manage those in the web app.

An AI assistant gets the same token when it [connects to Amiril](/assistants/connect).

### Tokens for a script [#tokens-for-a-script]

The HTTP API takes no API key. An API key only sends traces and lets the SDK fetch your rules. For a script that runs on its own, such as a CI job, run steps 1 to 4 once on a machine with a browser. Save the refresh token where the job can read it and write it back, such as a secret manager. A refresh can return a new refresh token, and then the old one may stop working. Save the new token after each refresh.

## Environment header [#environment-header]

The workspace comes from the token, and no header changes it. A request acts in your production environment unless you send another environment's id in `x-amiril-environment`. `GET /api/environments` lists the ids.

## Errors [#errors]

A refused request answers with an HTTP status and a JSON body. `error` says what went wrong. `tag` names the case, so your code can branch on it.

```json title="403 Forbidden"
{
  "error": "this can only be done in the web app, signed in",
  "tag": "NotForBearer"
}
```

| Status | Tag | Why |
| --- | --- | --- |
| `400` | `EnvironmentUnavailable` | No live environment has the id in `x-amiril-environment` |
| `401` | `InvalidToken` | The token is invalid or expired |
| `403` | `NotAMember` | You are no longer a member of the token's workspace |
| `403` | `NotForBearer` | The route works only in the web app, or the token is read-only |
| `429` | `RateLimited` | You sent more than 300 requests a minute in one workspace. Wait for the seconds in `Retry-After` |

## Route groups [#route-groups]

Each group takes its name from its paths, so a few names differ from the app's. To list runs, open **Unit list**.

| Group | What it covers |
| --- | --- |
| [Access](/reference/api/access) | Your tool servers and their tools |
| [Agents](/reference/api/agents) | Agents, their topics and where agent names come from |
| [Analytics](/reference/api/analytics) | An environment's activity and each tool's statistics |
| [Anomalies](/reference/api/anomalies) | Unusual runs, one run's trace and signals, and your reviews of runs |
| [Auth](/reference/api/auth) | Who the token acts as |
| [Dashboards](/reference/api/dashboards) | Dashboards and their widgets |
| [Definitions](/reference/api/definitions) | Your [Agent Systems](/assistants/tools#agent-systems) from **Systems** in the app's sidebar, and dry runs of a new one |
| [Environments](/reference/api/environments) | Your environments and what each one stores |
| [Imports](/reference/api/imports) | Trace files you upload |
| [Ingest](/reference/api/ingest) | Whether traces are arriving |
| [MCP](/reference/api/mcp) | The MCP server's address |
| [Rules](/reference/api/rules) | Rules, their checks, publishing and tests on past calls |
| [Runs](/reference/api/runs) | The rule decisions the SDK made in one run |
| [Schema](/reference/api/schema) | JSON Schemas for dashboards, filters and the rule language |
| [Unit list](/reference/api/unit-list) | The rows of the **Anomalies** and **Traces** lists |
| [Unit query](/reference/api/unit-query) | The rows behind each dashboard widget |
| [Units](/reference/api/units) | One Agent System's daily counts, its work items grouped by a field, and one work item in full |

## Next steps

- [SDK configuration](https://docs.amiril.ai/reference/sdk-config.md): Every option of the Amiril SDK's init and every environment variable it reads, in Python and TypeScript, with its type, its default and what it does.
- [Set up environments and API keys](https://docs.amiril.ai/traces/environments-and-keys.md): Create an environment such as Staging and an API key that sends to it, so test runs stay out of production. Then put the key where each service runs.
- [Connect an AI assistant to Amiril](https://docs.amiril.ai/assistants/connect.md): Add Amiril's MCP server to Claude Code, the Claude app, Cursor, VS Code or ChatGPT. Sign in with your Amiril account, then ask about your agents.

## More detail

- [HTTP API](https://docs.amiril.ai/assistant/api.md): How to call Amiril's HTTP API: signing in with a session or an OAuth access token, the environment headers, and the route groups.
- [Errors outside rule text](https://docs.amiril.ai/assistant/errors.md): Error shapes, status codes and exact messages of the HTTP API, sign-in and permissions, plans and billing, trace ingest, file imports, the MCP server and rate limits, with causes and fixes.
- [Limits and defaults](https://docs.amiril.ai/assistant/limits.md): Every limit and default a customer can hit in Amiril, with its number: plan amounts, ingest sizes and rates, imports, rules, backtests, API and MCP rates, page sizes, retention, name lengths.
