> For the complete documentation index, see [llms.txt](https://docs.toolkit.equs.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.toolkit.equs.ai/standards/agentic/ap2/flow-3.md).

# Flow 3: Agent Uses Its Own Token

The platform hosts your agent's wallet, and the agent signs in with its own credentials - no User session needed

{% hint style="warning" %}
**Experimental, and available on request.** This flow runs on the Web Custodial Wallet API, which is disabled by default, and it may change. The agent's credentials are issued on request too. Talk to us to have both set up.
{% endhint %}

**Flow 3** is [Flow 2](/standards/agentic/ap2/flow-2.md) with one difference: the agent signs in as itself. It has client credentials of its own and gets its own token, so it can make every call - including closing a grant long after the User approved it - with no User signed in anywhere.

Everything else is the same. The platform generates the agent's key, stores the grant in the agent's vault, and signs Closed mandates for it. You refer to the agent's key by its key ID, `kid`, which the platform returns when the agent requests a mandate.

### At a glance

|                        |                                                                                    |
| ---------------------- | ---------------------------------------------------------------------------------- |
| **Calls on**           | Web Custodial Wallet API                                                           |
| **Authenticates with** | The agent's own token, from its client credentials                                 |
| **Agent key**          | Generated and held by the platform, in the agent's vault. You refer to it by `kid` |
| **Grant storage**      | The agent's vault                                                                  |
| **Closing**            | One call per checkout, repeatable while the grant is valid                         |
| **Status**             | Experimental, available on request                                                 |

**Pick this flow** when the agent runs on its own, from your back end, and closes grants while the User is elsewhere.

**Watch out** for mixing flows on one agent. A `kid` or grant created with the agent's own token can't be reached through Flow 2, and the reverse - pick one and stay with it.

### Get the agent's token

The agent is a client of its own in the platform's Users realm. Once we've issued its client ID and secret, it gets a token with the client-credentials grant:

```http
POST https://<auth-server>/realms/users/protocol/openid-connect/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_id=<agent client ID>&client_secret=<agent client secret>
```

The token can't be refreshed: request a new one when it expires. See [Authentication](/standards/api/authentication.md) for the realms.

The token already identifies the agent, so send **no `x-agent-id` header** - an agent token that carries one is rejected.

### Make the calls

The same four steps as [Flow 2](/standards/agentic/ap2/flow-2.md), with the agent's token in place of the User's:

| Step                   | Call                                      | Returns                          |
| ---------------------- | ----------------------------------------- | -------------------------------- |
| 1. Request the mandate | `POST /api/v1/ap2/requests`               | `requestUri`, `txId` and `kid`   |
| 2. Get it to the User  | Embed UI, or screens you build            | One proof that the User answered |
| 3. Import the grant    | `POST /api/v1/ap2/requests/{txId}/verify` | `credentialId`                   |
| 4. Close the grant     | `POST /api/v1/ap2/credentials/{id}/close` | The signed artifact to deliver   |

`tenantId` and `verifierId` go in the body of each call, as on Flow 2. Mandate shapes and errors are in [Mandate Reference](/standards/agentic/ap2/mandate-reference.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.toolkit.equs.ai/standards/agentic/ap2/flow-3.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
