---
title: "Sign requests as an agent"
description: "What a Visa CLI agent sends, every signature profile and when each is used, and what partner-run signing looks like today."
url: https://app.visacli.sh/docs/sign-requests-as-an-agent
updated: 2026-11-20
---

# Sign requests as an agent

> What a Visa CLI agent sends, every signature profile and when each is used, and what partner-run signing looks like today.

Canonical: https://app.visacli.sh/docs/sign-requests-as-an-agent. Updated: 2026-11-20. Full index: /llms.txt.

A Visa CLI agent never holds its signing key. The key stays in a secure enclave, and it signs only the exact request the agent asks about, after the agent has proved who is asking. There's no key file to export, so a Visa CLI key can't be imported into another tool.

To use this page, you need Visa CLI installed, as on the [Quickstart](/docs/quickstart.md). An owner also has to connect the agent first and approve it in their browser, which needs the [card step](/docs/how-the-pieces-fit.md). [Which agents can sign](/docs/client-integrations.md#which-agents-can-sign) says what each app can do.

## Signing one request

Agents call the `attest_http_request` tool in their app, over a local or hosted connection. A program, or an app that can't load the tools, runs the same tool with `visa-tool`, as below. Describe the request in a file. This one claims a task:

```json title="request.json"
{
  "url": "https://market.example/tasks/42/claim?ref=a",
  "method": "POST",
  "headers": [
    ["content-type", "application/json"]
  ],
  "body_sha256": "lVH0Kpm71IxwuPvOjdCShjrzCouWTVbs3GY4TjGfhnk"
}
```

`body_sha256` is the base64url SHA-256 of the exact body bytes, here the body `{"task":42}`:

```sh
node -p "require('crypto').createHash('sha256')
  .update('{\"task\":42}').digest('base64url')"
```

Then ask for the headers. An agent in an app calls `attest_http_request` with those fields; a program, or an app that can't load the tools, runs:

```sh
visa-tool attest_http_request "$(cat request.json)"
```

## What comes back

This is the whole answer from a real run, with the key ID, timestamps, nonce, signature and request ID replaced by example values:

```json title="attest_http_request output"
{
  "ok": true,
  "profile": "tap-http-request-v1",
  "request": {
    "url": "https://market.example/tasks/42/claim?ref=a",
    "method": "POST",
    "headers": [
      ["accept", "*/*"],
      ["content-type", "application/json"],
      ["signature-agent", "\"https://sbx.agenticdirectory.visa.com\""]
    ],
    "body_sha256": "lVH0Kpm71IxwuPvOjdCShjrzCouWTVbs3GY4TjGfhnk"
  },
  "key_id": "11111111-2222-4333-8444-555555555555",
  "created": 1794000000,
  "expires": 1794000060,
  "nonce": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=",
  "headers": {
    "content-digest": "sha-256=:lVH0Kpm71IxwuPvOjdCShjrzCouWTVbs3GY4TjGfhnk=:",
    "signature-input": "sig2=(\"@method\" \"@scheme\" \"@authority\" \"@path\" \"@query\" \"content-digest\" \"accept\" \"content-type\" \"signature-agent\");created=1794000000;expires=1794000060;keyid=\"11111111-2222-4333-8444-555555555555\";alg=\"ed25519\";nonce=\"BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=\";tag=\"agent-browser-auth\"",
    "signature": "sig2=:BASE64_SIGNATURE_BYTES:"
  },
  "turn": "agent",
  "next": "none",
  "request_id": "00000000-0000-4000-8000-000000000000"
}
```

| Field | What it is |
| --- | --- |
| `profile` | The rules this was signed under: [`tap-http-request-v1`](/docs/words-used-here.md#term-tap-http-request-v1) |
| `request.url`, `request.method` | What to send, normalized |
| `request.headers` | The application headers, as pairs. Notice the `accept` and `signature-agent` that Visa CLI added. They're signed, so they have to be sent |
| `request.body_sha256` | The digest you supplied |
| `key_id` | The key that signed, which is the `keyid` a verifier looks up |
| `created`, `expires` | Epoch seconds, 60 seconds apart |
| `nonce` | 32 random bytes in base64, new for each attempt |
| `headers` | `content-digest`, `signature-input` and `signature` |
| `turn`, `next`, `request_id` | Notes for the agent, and a reference for support. Nothing to send |

The answer from the hosted route, [`POST /agent/v1/http-attestations`](/docs/reference/visa-cli/attest-a-hosted-agent-http-request.md), has the same signing fields.

## What to send

**You must send `request.headers` and `headers` together.** The first holds the application headers, the second the signature headers, and sending only one fails the check.

```js title="send.mjs"
import { execFileSync } from 'node:child_process'
import { readFileSync } from 'node:fs'

const body = '{"task":42}'
const output = execFileSync('visa-tool', ['attest_http_request', readFileSync('request.json', 'utf8')], { encoding: 'utf8' })
const attestation = JSON.parse(output)
const headers = new Headers([
  ...attestation.request.headers,
  ...Object.entries(attestation.headers),
])
const response = await fetch(attestation.request.url, {
  method: attestation.request.method,
  headers,
  body,
  redirect: 'error',
})
```

`body` is the exact bytes whose SHA-256 went into `request.json`, and `output` is what `visa-tool attest_http_request` printed. The tool sends nothing, pays nothing and retries nothing. It returns the headers for one attempt, and the agent sends the request itself within 60 seconds, using the same body bytes. Every new attempt gets a new nonce. If you need the same action to be safe to retry, put your own idempotency key in a signed header or the body. Redirects are refused above because a signature is for one address, and following a redirect would pass the headers to another.

## Rules for the request

- It must use HTTPS and `GET`, `HEAD` or `POST`, so `attest_http_request` refuses an `http://` URL, with no credentials or fragment in the URL, and no empty trailing `?`. The URL limit is 8,192 characters.
- `GET` and `HEAD` require the empty-body digest `47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU`. A mismatch is invalid input; correct it before trying again. The body limit is 1 MiB.
- Up to 32 headers. Names up to 128 characters, values up to 4,096 printable ASCII characters with no leading or trailing spaces, and 16 KiB in total. Duplicates aren't allowed.
- When the key has metadata from the Visa Agent Directory, Visa CLI adds `signature-agent` and an explicit `accept: */*`. Send them as returned, because they're signed.

**Reserved headers are refused** before anything is signed:

| Kind | Headers |
| --- | --- |
| Credentials | `authorization`, `proxy-authorization`, `cookie`, `set-cookie` |
| Transport | `host`, `connection`, `content-length`, `transfer-encoding`, `te`, `trailer`, `upgrade`, `keep-alive`, `expect`, `via`, `forwarded`, `origin`, `referer` |
| Signature and payment | `content-digest`, `signature`, `signature-input`, `agent-payer-auth`, `payment`, `payment-signature`, `payment-required`, `payment-receipt`, `payment-response` |
| By prefix | `proxy-*`, `sec-*` and `x-forwarded-*`. Also `x-visa`, `x-stamp` and `x-payment`, each on its own or followed by `-`: `x-visa` and `x-visa-a` are reserved, while `x-visabank` isn't |

In words: Visa CLI refuses to sign credential headers such as `authorization` and `cookie`, transport headers such as `host`, and signature or payment headers, along with any header starting `proxy-`, `sec-` or `x-forwarded-`.

Your own headers are fine. A header such as `x-market-member` is signed like any other, and that's how a request can name an account when the API also takes a login: see [Add verified agents to a marketplace](/docs/add-verified-agents-to-a-marketplace.md#signatures-and-your-existing-logins).

## Which version can sign

The web installer on the [Quickstart](/docs/quickstart.md) gives you the current release, `@visa/cli@latest`, pointed at production. Visa CLI 4.x and earlier can't sign these requests, because they have neither the `attest_http_request` tool nor the `visa-tool` command.

## Every signature profile

Visa CLI signs in three situations, and an agent doesn't choose between them: the operation decides.

| | Identity request | Built-in verified task | Paid request |
| --- | --- | --- | --- |
| When | `attest_http_request` | A marketplace task that requires a verified worker, on a signed path | Every payment |
| Tag | `agent-browser-auth` | `agent-browser-auth` | `agent-payer-auth` |
| Label | `sig2` | `sig1` | `sig2` |
| `alg` | `ed25519` | `ed25519` | `ed25519` |
| Covered | `@method` `@scheme` `@authority` `@path` `@query` `content-digest`, then sorted application headers | The same | `@method` `@authority` `@path`, `content-digest` when there's a body, `authorization`; with metadata from the Visa Agent Directory (a UUID `keyid`) also `signature-agent`, `@query` when the URL has a query, and `accept` and `content-type` when the request carries them |
| Lifetime | 60 seconds | 60 seconds | With a UUID `keyid`, signed for 60 seconds by default, and a verifier accepts up to 300. With a thumbprint `keyid`, signed for 480 seconds, the most a verifier accepts |

In words: an identity request from `attest_http_request` is labelled `sig2`, tagged `agent-browser-auth` and lives 60 seconds. Releases from 5.0.0-rc.480 send `alg="ed25519"` on every profile. Older releases send `Ed25519` on identity and paid requests, and some are still in use, so a verifier accepts both. A built-in verified task is the same but labelled `sig1`. A paid request is tagged `agent-payer-auth` and covers `authorization`.

When a paid request carries more than one payment credential, such as `X-Payment` alongside `Authorization: Payment`, the signature must cover every one of them, so a signature over one credential can't carry another along unsigned. Visa CLI's own verifier refuses a paid request that leaves one out, as `tap_malformed`.

Component order differs between them, so rebuild the base from the order in `Signature-Input`, as the example on [Verify a signed request](/docs/verify-a-signed-request.md) does.

The label is only the name that ties `Signature-Input` to `Signature`, and it differs by path. A request an agent signs with `attest_http_request` and sends to your API itself carries `sig2`, and that's the only label the example verifier accepts. A built-in verified task carries `sig1`, and only reaches a marketplace that's in Visa CLI's built-in task tools. If yours is, accept `sig1` as well, with the same tag and components.

Discovery and other unsigned reads aren't signed, and nothing attaches a signature to browsing automatically. `sign_action` is a separate wallet message signature and isn't TAP. See [Message signing](/docs/message-signing.md).

Visa CLI's built-in marketplace tools sign gated identity requests on a device with its own key, and for a hosted connection with its hosted key, the one its payments use. A hosted signature is made only for a claim, upload or submission whose card the owner approved, and it's labelled `sig1` as on a device. A hosted connection can also call `attest_http_request` directly.

## Signing if you're not a Visa CLI agent

Partner-run signing isn't available through these routes today. [`POST /agent/v1/keys/tap-sign`](/docs/reference/visa-cli/sign-a-laptop-merchant-request.md) needs a Visa CLI agent token, and [`POST /agent/v1/http-attestations`](/docs/reference/visa-cli/attest-a-hosted-agent-http-request.md) needs a Visa CLI OAuth or app token, so both serve Visa CLI's own agents and nobody else's keys.

If your agents hold their own keys, see [Build with an enabler](/docs/build-with-an-enabler.md), then sign as below.

<a id="own-key"></a>

## Sign with a key you hold

Once your key is registered and you have its `keyid`, sign each request yourself. `sign.mjs` uses only Node's `crypto`, handles Ed25519 and P-256, and returns the headers to add. It signs in Visa CLI's profile, `tap-http-request-v1`, which Visa CLI's example verifier checks. It's also in [verify-example.zip](/examples/verify-example.zip) and at [/examples/sign.mjs](/examples/sign.mjs). It signs the method, scheme, authority, path, query, `content-digest` and every application header in sorted order, including `signature-agent`, with the label `sig2`, the tag `agent-browser-auth`, a 60-second lifetime and a new 32-byte nonce each time.

```js title="sign.mjs"
import { createHash, createPrivateKey, randomBytes, sign } from 'node:crypto'

export function signRequest({ url, method = 'GET', headers = {}, body = '', keyId, privateKeyJwk, signatureAgent, lifetime = 60 }) {
  const target = new URL(url)
  const key = createPrivateKey({ key: privateKeyJwk, format: 'jwk' })
  const ecdsa = key.asymmetricKeyType === 'ec'
  const digest = `sha-256=:${createHash('sha256').update(body).digest('base64')}:`
  const app = Object.entries({ accept: '*/*', ...headers, ...(signatureAgent === undefined ? {} : { 'signature-agent': JSON.stringify(signatureAgent) }) })
    .map(([name, value]) => [name.toLowerCase(), String(value)])
    .sort(([a], [b]) => (a < b ? -1 : 1))
  const values = [
    ['@method', method.toUpperCase()],
    ['@scheme', target.protocol.slice(0, -1)],
    ['@authority', target.host],
    ['@path', target.pathname],
    ['@query', target.search || '?'],
    ['content-digest', digest],
    ...app,
  ]
  const created = Math.floor(Date.now() / 1000)
  const nonce = randomBytes(32).toString('base64')
  const params = `(${values.map(([name]) => `"${name}"`).join(' ')});created=${created};expires=${created + lifetime};keyid="${keyId}";alg="${ecdsa ? 'ecdsa-p256-sha256' : 'ed25519'}";nonce="${nonce}";tag="agent-browser-auth"`
  const base = [...values.map(([name, value]) => `"${name}": ${value}`), `"@signature-params": ${params}`].join('\n')
  const signature = sign(ecdsa ? 'sha256' : null, Buffer.from(base), ecdsa ? { key, dsaEncoding: 'ieee-p1363' } : key)
  return {
    ...Object.fromEntries(app),
    'content-digest': digest,
    'signature-input': `sig2=${params}`,
    signature: `sig2=:${signature.toString('base64')}:`,
  }
}
```

```js
const headers = signRequest({
  url: 'https://market.example/tasks/42/claim',
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body,
  keyId: process.env.AGENT_KEY_ID,
  privateKeyJwk: JSON.parse(process.env.AGENT_PRIVATE_KEY_JWK),
  signatureAgent: 'https://sbx.agenticdirectory.visa.com',
})
```

With an enabler, `signatureAgent` is the origin of the Visa Agent Directory for the environment your key is registered in: `"https://sbx.agenticdirectory.visa.com"` in sandbox and `"https://agenticdirectory.visa.com"` in production. Basis Theory's `201` answer has no `directoryUrl`, so set it from the environment. If a registration you made elsewhere returned a `directoryUrl`, use its origin. A verifier accepts only the `Signature-Agent` values on its allowlist, which by default are the Visa Agent Directory sandbox and the Visa Agent Directory (production). If you sign with any other origin, the verifier refuses your request as `tap_signature_agent_not_accepted` until its test configuration adds that quoted origin to `allowedSignatureAgents`, as [Rehearse it in sandbox](/docs/build-with-an-enabler.md#sandbox) shows. Sign for the verifier's public HTTPS origin, the one it pins, even when you send the request to a local address. Sign again for every attempt, since a nonce can't be reused.

Send every header `sign.mjs` returns, including `accept`. Node's and browsers' `fetch` add `accept: */*` when you don't set one, and with a UUID `keyid` this profile needs `accept` signed whenever it's sent, so a request with an unsigned `accept` is refused as `tap_malformed`. `sign.mjs` signs `accept: */*` unless you pass your own, named `accept` in lowercase, in `headers`, and returns it with the rest, so `fetch` sends the value you signed. If you write your own signer, set `accept` yourself and sign it.

Keep the private key out of your repository. Load it from your secret store or an environment variable when the process starts, and refuse to start without it. A key that's been committed is public, so register a new one.

## Testing on your laptop

The signature covers `@scheme: https` and your public host, so a local `http://` server can't be signed for directly. Ask for a signature on your public HTTPS address, send the request to your local server, and have your server rebuild the signature base from its configured public origin, not from the address it was reached on. That's why a verifier pins its origin in config. The [Test it yourself](/docs/add-verified-agents-to-a-marketplace.md#test-it-yourself) example runs this way.
