# For agents

One page for an agent setting itself up with Mirabase: get an API key, connect over MCP, make the basic calls, stay within limits, handle errors, and find the machine-readable files.

Mirabase keeps files, knowledge, and memory in one data model, reached by path, by id, or by meaning. If you are an agent reading this page, take the steps below in order. When a step requires a credential or a permission you do not have, stop and ask the person you work for.

| Item | Value |
| --- | --- |
| Base URL | `https://api.mirabase.io` |
| Authentication | `Authorization: Bearer mb_live_...` |
| MCP endpoint | `https://api.mirabase.io/mcp`, Streamable HTTP |
| OpenAPI | [https://api.mirabase.io/v2/openapi.yaml](https://api.mirabase.io/v2/openapi.yaml) |
| Guide for agents | [https://api.mirabase.io/llms.txt](https://api.mirabase.io/llms.txt) |

## Get an API key

1. Ask the person you work for to give you a key of your own. Do not use their root key.
2. They create the key in the [console](https://console.mirabase.io), or issue it with [`POST /v2/api-keys`](https://mirabase.io/developers/api/api-keys.md#apikeys-create), limited to the capabilities and Spaces you need with `grant_capabilities` and `allowed_space_ids`. The secret is shown once.
3. Read the key from the `MIRABASE_API_KEY` environment variable. Never write it to a file, a log, a memory, or a conversation.

> **Note:** Sign-up is self-serve: once the person signs in to the console with GitHub, the account is active at once, on the `free` plan (1 GiB of storage, and 10,000 writes and 1,000,000 model tokens each month).

| Capability | Allows |
| --- | --- |
| `knowledge:read` | Read Spaces, files, Entries, memories, and the change feed; call search and context |
| `knowledge:answer` | Call [`POST /v2/retrieval/answer`](https://mirabase.io/developers/api/retrieval.md#retrieval-answer), together with `knowledge:read` |
| `knowledge:write` | Write and edit files, ingest content, work on branches, and write the agent's own memory |
| `memory:confirm` | Write a confirmed memory directly, or correct a memory |

For the full list and how to narrow a key, see [Authentication and API keys](https://mirabase.io/developers/authentication.md).

## Connect over MCP

Prefer MCP when your client supports it. The credential is the same API key, sent as a header. MCP authorization (OAuth 2.1) is not enabled yet, so a client that supports only OAuth cannot connect for now.

Claude Code:

```bash
claude mcp add --transport http mirabase https://api.mirabase.io/mcp \
  --header "Authorization: Bearer $MIRABASE_API_KEY"
```

Codex:

```bash
codex mcp add mirabase --url https://api.mirabase.io/mcp \
  --bearer-token-env-var MIRABASE_API_KEY
```

JSON:

```json
{
  "mcpServers": {
    "mirabase": {
      "type": "http",
      "url": "https://api.mirabase.io/mcp",
      "headers": {
        "Authorization": "Bearer mb_live_..."
      }
    }
  }
}
```

| Address | Toolset |
| --- | --- |
| `/mcp` | The full toolset; tool names start with `mira.` |
| `/mcp/lean` | Six tools: `mira_search`, `mira_read`, `mira_save`, `mira_forget`, `mira_list_spaces`, and `mira_history` |

- After connecting, call `mira.whoami` first ([`GET /v2/whoami`](https://mirabase.io/developers/api/identity.md#identity-whoami) without MCP) to confirm your principal, your capabilities, and the Spaces you can read and write. If it fails, report the error code to the person; do not retry with another key.
- `tools/list` returns only the tools this key can call.
- Each tool makes one `/v2` request, so permissions, limits, and error codes are the same as REST.

For the tool list, parameters, and the recommended call order, see [Connect an Agent (MCP)](https://mirabase.io/developers/agents.md).

## Basic calls

Without MCP, call REST directly. These five requests cover files, memory, search, and answers. `default` stands for your default Space, or the only Space the key can access.

```bash
# 1. Write a file by path. The body is the file. Needs knowledge:write.
curl -X PUT "https://api.mirabase.io/v2/spaces/default/files?path=/notes/plan.md" \
  -H "Authorization: Bearer $MIRABASE_API_KEY" \
  -H "Content-Type: text/markdown" \
  -H "Prefer: wait=10" \
  --data-binary "We ship on Friday."

# 2. Store one lasting statement as a memory. Needs memory:confirm.
curl -X POST https://api.mirabase.io/v2/memories \
  -H "Authorization: Bearer $MIRABASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"scope": "project", "space_id": "default", "kind": "preference", "text": "Releases go out on Fridays."}'

# 3. Store a conversation; memories are distilled from it in the background. Needs knowledge:write.
curl -X POST https://api.mirabase.io/v2/spaces/default/ingest \
  -H "Authorization: Bearer $MIRABASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind": "conversation", "session_id": "chat-42", "messages": [{"role": "user", "content": "We ship on Friday."}]}'

# 4. Search. Needs knowledge:read.
curl -X POST https://api.mirabase.io/v2/retrieval/search \
  -H "Authorization: Bearer $MIRABASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "when do we ship", "space_ids": ["default"]}'

# 5. An answer that cites what it used, or status "abstained". Needs knowledge:read and knowledge:answer.
curl -X POST https://api.mirabase.io/v2/retrieval/answer \
  -H "Authorization: Bearer $MIRABASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"question": "When do we ship?", "space_ids": ["default"]}'
```

| Goal | Call |
| --- | --- |
| Store something with a path: a document, notes, a table | [`PUT /v2/spaces/{space_id}/files`](https://mirabase.io/developers/api/files.md#files-write) |
| Store text, a URL, or a conversation without a path | [`POST /v2/spaces/{space_id}/ingest`](https://mirabase.io/developers/api/ingest.md#ingest-ingest) |
| Store one statement that stays true | [`POST /v2/memories`](https://mirabase.io/developers/api/memories.md#memories-create) |
| Read what is known before a task | [`POST /v2/retrieval/context`](https://mirabase.io/developers/api/retrieval.md#retrieval-buildcontext): the service picks passages within a token budget |
| Pick the passages yourself | [`POST /v2/retrieval/search`](https://mirabase.io/developers/api/retrieval.md#retrieval-search) |
| Get a finished answer with citations | [`POST /v2/retrieval/answer`](https://mirabase.io/developers/api/retrieval.md#retrieval-answer) |
| Fix a memory | [`POST /v2/memories/{memory_id}/correct`](https://mirabase.io/developers/api/memories.md#memories-correct): the old memory is kept as history |

- Search, context, and answer without `space_ids` read every Space the key can read, not the default Space. Name the Space when a call concerns a single user.
- Give each end user a Space of their own: [`PUT /v2/spaces/{space_id}`](https://mirabase.io/developers/api/spaces.md#spaces-ensure) with `ext:<your id>` as the Space id returns the Space mapped to your own id for the user, creating it if it does not exist.
- Citations point to a specific version of an Entry (`entry_id`, `version_id`, `path`). Check the citation before you state a fact.

## Actions that require approval

These actions cannot be undone. Ask the person you work for before you take one:

- Forgetting a memory: [`DELETE /v2/memories/{memory_id}`](https://mirabase.io/developers/api/memories.md#memories-forget) or `mira.memory.forget`. When a memory is wrong, correct it instead.
- Permanently erasing an Entry, or deleting a Space. Deleting a file only moves it to the trash, where it can be restored.
- Revoking or rotating an API key.

For which actions can be undone, see [Undo rules](https://mirabase.io/developers/memory.md#undo-rules).

## Limits

- Every authenticated response carries `RateLimit-Limit`, `RateLimit-Remaining`, and `RateLimit-Reset`.
- [`GET /v2/limits`](https://mirabase.io/developers/api/usage.md#usage-limits) returns the account's plan and its limits, and [`GET /v2/usage`](https://mirabase.io/developers/api/usage.md#usage-usage) returns the remaining quota. These two responses are the source of truth for the numbers.
- 429 `rate_limited`: wait for `Retry-After`, then retry. When `limit` is `concurrency`, send fewer requests at the same time.
- 429 `quota_exceeded`: one of the plan's quotas is used up, and retrying does not help. Report the `quota` field to the person.
- A tool call over MCP counts as two requests: the `/mcp` call and the `/v2` request it makes.
- Direct writes accept files up to 16 MiB. Use [uploads](https://mirabase.io/developers/files.md#uploads) for larger files.

For the rules and the default limits, see [Rate limits and quotas](https://mirabase.io/developers/conventions.md#rate-limits).

## Errors

A failed request returns an `error` object: `code`, `type`, `status`, `message`, `request_id`, `retryable`, and, where a fixed next step exists, `remediation.action`. Branch on `code` and `remediation.action`; do not parse `message`. Over MCP, a failed call is a result with `isError: true`, and the error envelope is in `_meta["dev.mirabase/error"]`.

| Status and code | Meaning | What to do |
| --- | --- | --- |
| 401 `unauthorized` | The key is missing, invalid, expired, or revoked | Ask the person for a new key |
| 403 `forbidden` | The key's capabilities or its role in the Space are insufficient | Call [`GET /v2/whoami`](https://mirabase.io/developers/api/identity.md#identity-whoami) and report the missing capability to the person |
| 403 `proposal_required` | You are changing a file you do not own | Send `Prefer: handling=proposal` to submit the change as a proposal |
| 404 `not_found` | The resource does not exist, or you cannot see it | Check the id, the path, and the Space |
| 412 `precondition_failed` | The file changed after you read it | Read it again, then edit from the new version |
| 422 `validation_error` | A parameter, header, or body field is invalid or unknown | Fix the request using `field` and `errors` |
| 429 `rate_limited` | The request rate or the concurrency limit was reached | Wait for `Retry-After`, then retry |
| 429 `quota_exceeded` | A plan quota is used up | Stop retrying and tell the person |
| 503 `answer_not_configured` | The deployment has no answer model | Do not retry. Use [`POST /v2/retrieval/context`](https://mirabase.io/developers/api/retrieval.md#retrieval-buildcontext) and write the answer with your own model |

Every code is listed in [Error codes](https://mirabase.io/developers/errors.md#codes), and the retry rules are in [API conventions](https://mirabase.io/developers/conventions.md#retries).

## Machine-readable files

| Address | Contents |
| --- | --- |
| [https://api.mirabase.io/llms.txt](https://api.mirabase.io/llms.txt) | The guide for agents, served by the API itself: setup steps, every route, and the conventions |
| [https://api.mirabase.io/v2/openapi.yaml](https://api.mirabase.io/v2/openapi.yaml) | The OpenAPI document: every operation an API key can call, with examples |
| [https://mirabase.io/developers/llms.txt](https://mirabase.io/developers/llms.txt) | The index of these docs, one Markdown link per page |
| [https://mirabase.io/developers/llms-full.txt](https://mirabase.io/developers/llms-full.txt) | All the guides in one file |
| Any docs page address plus `.md` | That page as Markdown, for example `https://mirabase.io/developers/quickstart.md` |
| [https://mirabase.io/llms.txt](https://mirabase.io/llms.txt) | The site index: product pages and links to the files above |

For the base URL, routes, and fields, the OpenAPI document and the API's own llms.txt are the authority. For SDK versions, use the latest release on npm and PyPI; do not guess a version number.

## Contact

Send integration questions through the [contact page](https://mirabase.app/en/contact). Include the `request_id` from the error response when you report a problem.

## Next steps

- Write, search, and answer with the [quickstart](https://mirabase.io/developers/quickstart.md).
- See [the MCP tools and the recommended call order](https://mirabase.io/developers/agents.md#loop).
- Issue the agent [a narrowly scoped API key](https://mirabase.io/developers/permissions.md#agents).
- Read how the official [skills](https://mirabase.io/developers/skills.md) guide an agent to the right tool for each task.
