# Clara API authentication for agents

> How an agent or developer obtains and uses Clara API credentials: discovery, method, registration, token exchange, errors and revocation. Source of truth: https://developers.clara.team/auth.md

The Clara REST API authenticates every request with two layers, and both are required (the product MCP server uses OAuth instead; see [Product MCP (OAuth)](#product-mcp-oauth)):

1. **mTLS**: an X.509 client certificate issued by Clara.
2. **OAuth 2.0 Bearer token**: a JWT from `/oauth/token`, obtained with `client_id` and `client_secret` (the client credentials grant).

For the REST API, Clara supports one identity type, `service_auth`. It has no agent self-registration, so an agent cannot mint its own credentials.

## Discover

Read these in order: the OpenAPI 3.1 spec at https://developers.clara.team/openapi.json (a documented v3 subset, not an exhaustive backend contract), the API catalog at https://developers.clara.team/.well-known/api-catalog.json, the agent instructions at https://developers.clara.team/agent-instructions.md, and this page.

Each market has its own host and token endpoint. Use the one that matches the company's market:

| Market | Base URL | Token endpoint |
| - | - | - |
| Mexico | https://public-api.mx.clara.com | https://public-api.mx.clara.com/oauth/token |
| Brazil | https://public-api.br.clara.com | https://public-api.br.clara.com/oauth/token |
| Colombia | https://public-api.co.clara.com | https://public-api.co.clara.com/oauth/token |

The REST hosts above publish no discovery metadata: `/.well-known/oauth-protected-resource` and `/.well-known/oauth-authorization-server` on them return 404. Do not probe for them, and do not assume an `openid-configuration`. There is no `identity_endpoint` to look up, and REST errors carry no `WWW-Authenticate` pointer to one. The product MCP servers are different: they do publish OAuth discovery metadata, described in [Product MCP (OAuth)](#product-mcp-oauth).

## Pick a method

| Method | Status | Notes |
| - | - | - |
| `service_auth`: OAuth 2.0 client credentials over mTLS | Supported | The only way to call the REST API today |
| `agent_auth`: self-registration through an `identity_endpoint` | Not supported | Clara has no agent registration surface |
| `identity_assertion`: ID-JAG (`id-jag`) token exchange | Not supported | Clara does not accept assertion grants |

The consequence: you cannot mint your own credentials. A person with Clara platform access creates an API project, and the credentials are handed to the agent out of band.

## Register

Registration is a dashboard action for a human administrator, not an API call:

1. Sign in to the Clara dashboard for the market and open **Integrations → Clara API → Project credentials**.
2. Choose **Create project**, a name, a validity period (up to 360 days) and the read or write permissions the integration needs.

Mexico: https://app.clara.cc/settings/integrations/clara-api. Colombia: https://colombia.clara.com/settings/integrations/clara-api. Brazil: https://brasil.clara.com/settings/integrations/clara-api.

Creating a project returns three artifacts, downloadable once: a public key (the client certificate for mTLS), a private key (treat it like a password) and a client credentials JSON with `client_id`, `client_secret` and the granted scopes. Lost credentials cannot be re-downloaded: create a new project and retire the old one.

## Claim

There is no claim step. Clara has no `claim_endpoint` and no grant code to redeem. Credentials go directly to the person who created the project, and an ID-JAG presented by an agent has nowhere to be redeemed. An agent holding a `client_id` and `client_secret` is already provisioned.

## Exchange

Trade the client credentials for an access token. Send them as HTTP Basic auth, with the client certificate on the request:

```bash
curl --request POST "https://public-api.mx.clara.com/oauth/token" \
  --header "Authorization: Basic $(echo -n 'CLIENT_ID:CLIENT_SECRET' | base64)" \
  --cert client.crt \
  --key client.key
```

The response carries `access_token`, `token_type` (Bearer) and `expires_in` in seconds. It has no refresh token: request a new token with the same credentials, and refresh before expiry rather than waiting for a `401`. The token carries the project's permissions as scopes; it is not narrowed per call.

## Use the access token

Send the Bearer token and the certificate on every request, not only on the token call:

```bash
curl --request GET "https://public-api.mx.clara.com/api/v3/transactions?page=0&size=10" \
  --header "Authorization: Bearer <TOKEN>" \
  --cert client.crt \
  --key client.key
```

If the account manages several companies, add `X-Tax-Identifier: <tax_id>` to act for one of them.

**Sandbox.** The REST sandbox uses the same country base URL with `/api-test/` in place of `/api/` in the request path, for example `https://public-api.mx.clara.com/api-test/v3/...`. Sandbox details are at https://developers.clara.team/sandbox. Test integrations there before any call that changes live data.

Common scopes include `read:digital-account` (Brazil balance and transactions), `read:subscribers` and `write:subscribers` (webhook subscriptions), and `write:accounts-payable/pix` (Pix payments, Brazil). The authoritative list is the `scopes` field in the credentials JSON. A token that lacks a required scope gets `403`, and retrying will not help.

## Errors

| Status | Meaning | What the agent should do |
| - | - | - |
| `400` | Malformed request or missing field | Fix the request; do not retry as-is |
| `401` | Missing, expired or invalid Bearer token | Request a new token, retry once |
| `403` | Valid token, insufficient scope or role | Stop; ask the person to grant the permission |
| `404` | Resource does not exist for this company | Verify the identifier; do not retry |
| `511` | mTLS client certificate missing or invalid | Fix the certificate; do not retry |

Clara returns JSON errors, never HTML. Responses carry `X-RateLimit-Burst-Capacity`, `X-RateLimit-Replenish-Rate`, `X-RateLimit-Remaining` and `X-RateLimit-Requested-Tokens`; back off while `X-RateLimit-Remaining` is low.

## Revocation

Clara publishes no endpoint to revoke a token or a project. A token stops working when `expires_in` elapses. A project stops working at the end of its validity period. For a compromised credential, or a project that must be cut off now, contact Clara integration support: integration.support.mx@clara.team (Mexico), integration.support.br@clara.team (Brazil) or integration.support.co@clara.team (Colombia).

## Product MCP (OAuth)

Clara's product MCP server is a separate protected resource from the REST API. It acts on the cards and transactions of an existing Clara company account, and it signs in with the user's Clara login over OAuth, so there is no client secret or API token to create. Do not confuse it with the docs MCP server (https://developers.clara.team/mcp), which answers questions about the API documentation and needs no credentials.

| Market | MCP server (Streamable HTTP) | Protected-resource metadata (RFC 9728) | Authorization server (RFC 8414 metadata at `/.well-known/oauth-authorization-server`) | Scopes |
| - | - | - | - | - |
| Mexico | https://mx.clara.team/mcp | https://mx.clara.team/.well-known/oauth-protected-resource/mcp | https://mx-login.clara.cc/ | `clara.transactions.read`, `clara.cards.manage`, `offline_access` |
| Brazil | https://br.clara.team/mcp | https://br.clara.team/.well-known/oauth-protected-resource/mcp | https://br-login.clara.com/ | `clara.transactions.read`, `clara.cards.manage`, `offline_access` |
| Colombia | https://co.clara.team/mcp | https://co.clara.team/.well-known/oauth-protected-resource/mcp | https://co-login.clara.com/ | `clara.transactions.read`, `clara.cards.manage`, `offline_access` |

The documented tools are `list_cards`, `list_transactions`, `lock_card`, `unlock_card`, `upload-transaction-document`, `list_companies` and `switch_company`. The reference is https://developers.clara.team/mcp/tools.

**Discovery flow**

1. Send a request to the MCP endpoint with no token. The server answers `401` with `WWW-Authenticate: Bearer resource_metadata="<protected-resource metadata URL>"`.
2. Fetch that protected-resource metadata. It names the `resource`, the `authorization_servers` and the `scopes_supported`. The protected-resource metadata is served by the MCP host itself; www.clara.com does not serve it.
3. Fetch `/.well-known/oauth-authorization-server` on the authorization server from step 2. It gives the `authorization_endpoint`, the `token_endpoint` and the `code_challenge_methods_supported`. S256 is listed, and so is `plain`: use S256.
4. Run the authorization code flow with PKCE (S256) against the user's Clara login, then send the MCP requests with the resulting Bearer token.

The authorization server metadata advertises a `registration_endpoint`. That is all this page claims about registration: it does not say that dynamic client registration works for an agent, so confirm it in the developer quickstart before relying on it.

**Who can sign in.** Only Clara users with the **Admin** or **Bookkeeper** role. Other roles are not supported in this version. The quickstart for each AI tool is at https://developers.clara.team/mcp/quickstart.

**Certificate-bound tokens flag.** The protected-resource metadata sets `tls_client_certificate_bound_access_tokens` to true (RFC 8705). The AI-tool setups in the quickstart connect with the OAuth sign-in alone and document no client certificate; follow the quickstart for your tool.

**Revocation.** There is no self-service revocation yet. To revoke an AI tool's access to a Clara account, contact Clara Customer Happiness (contacto@clara.com) or Clara Solution Engineering. Access is cut off across all connected tools at once.

## Agent checklist (REST API)

- [ ] I hold a certificate, a private key, and a `client_id` and `client_secret` from a person, not invented
- [ ] I am using the token endpoint for the company's market
- [ ] I request a token from `/oauth/token` and renew it before `expires_in` elapses
- [ ] I send the certificate on every request
- [ ] I treat `401` (token) and `511` (certificate) as different failures
- [ ] I keep the requested scopes to the minimum the task needs

Full reference: https://developers.clara.team/auth.md (developer portal). Agent guide: https://www.clara.com/agents.md.
