Skip to main content
A grant token (ngt_…) is a bearer secret: whoever holds it can act for the agent, within its policy, for up to 365 days. That is fine for a backend that already keeps secrets. A CI job, a cloud function or a server often has something better: its platform vouches for it with a short-lived identity token, or it can hold a private key that never leaves it. With workload identity, the owner signs that identity into the grant instead of a token’s fingerprint. The workload then proves who it is, trades the proof for a short-lived session token, and acts as before. No long-lived secret sits on the workload or crosses the wire.
At a glance
  • Credentials: a grant’s credential is one of three things the owner signs: a token’s SHA-256 commitment (as before), { type: "oidc", issuer, claims }, or { type: "public_key", jwk }. Grant views report which as credential_type: token, oidc or public_key.
  • Exchange: POST /v1/agents/{agent_id}/grants/token trades the workload’s OIDC identity token, or a single-use assertion signed with its key, for an ngs_… session token. Send it as X-Grant-Token.
  • Sessions: 15 minutes by default (at most 60), never past the grant. Revoking the grant ends them all.
  • Per request: a public_key grant can sign every request and send X-Grant-Proof instead, so no bearer token exists at all.
  • Still needed: your partner API key on every call, the exchange included. The owner’s policy, timelock, approvals and budget apply exactly as before.
Workload identity needs an API with workload identity federation. In the TypeScript SDK, exchangeGrantToken, forGrantSession, forGrantProof and the key helpers are in SDK 0.9.2 and later. Existing token grants keep working unchanged.

Choose a credential

  • The platform already issues identity tokens? Use oidc. There is no key or token to store anywhere. See OIDC grants.
  • No identity provider? Use public_key. Generate the key where the workload runs and keep it there. See Key-bound grants.
  • Want no bearer token at all? Use public_key and sign every request. A proof is good for one request and cannot be replayed.
  • Many requests, and a key that is slow or billed per signature (a cloud KMS)? Use a session: one signature covers 15 minutes.
  • A backend that is the only caller, and the simplest setup? A token grant is still the right choice.
Only the credential changes. A federated grant has the same label, expiry, 50-grant limit and revocation as any grant, and it follows the same policy. Idempotency keys are scoped to the grant, never to the token or session.

How it works

1

The owner signs the binding

Your backend generates a grant_issue intent whose credential names the identity, and the owner signs it. For oidc, the signed message names the issuer, the audience its tokens must carry (the API fills it in; only Entra ID grants name it) and the claims that pin one workload. For public_key, it names the key.
2

The workload gets a proof of identity

An identity token from its platform for exactly the grant’s audience, or an assertion it signs with its key. Both are JWTs that live minutes.
3

It exchanges the proof for a session

POST /v1/agents/{agent_id}/grants/token verifies the signature, issuer, audience and lifetime, matches the pinned claims to a live grant, and returns an ngs_… session token.
4

It acts with the session

The workload sends the session token as X-Grant-Token, exactly where a grant token goes, and exchanges again shortly before expires_at.
The policy, timelock, owner approvals, USD budget, idempotency and dispatch commitment see the grant, never the credential.
Federation replaces only the grant token. Your partner API key is still required on every call, the exchange included. It identifies the partner, carries the rate limits and quotas, and revoking it stops the requests it sends. Give each workload its own key from the partner portal, so its limits and its revocation are its own. See Partner API Key.

Issue a federated grant

Issuing works like any grant: generate a grant_issue intent, have the owner sign intent.payload, submit it, then read the status. Only credential differs.
  • Show preview.summary to the owner. It names everything the grant trusts: the issuer’s exact URL, the pinned claims, a signed audience (Entra ID only) and the thumbprint of each signed issuer key. For example: workloads of https://token.actions.githubusercontent.com (GitHub Actions) with ref=refs/heads/main, repository_id=…, repository_owner_id=….
  • Keep grant_id. When the status is SUCCESS, details.grant.grant_id is the new grant. A key-bound workload signs it into every proof.
  • Signed text is ASCII. Claim names and values are printable ASCII, like the label, because some wallets re-encode other characters in a signed message.
  • The API checks the credential before the owner signs it. A credential that could never exchange, such as an untrusted issuer, missing required claims or a weak key, is refused at generate-intent with grant_credential_invalid (400). submit-intent checks the signed credential again.
The grant’s owner_message.credential holds exactly what the owner signed: the commitment string for a token grant, or the oidc or public_key object. Revoke a federated grant with grant_revoke, like any grant.

OIDC grants

The API trusts the issuers below. The list is part of the server and is attested with it: no request or setting adds an issuer or changes where its keys come from. Any other issuer works only when the owner signs its public keys into the grant (see Kubernetes). “Must pin” claims are required in every grant for that issuer. “And one of” means at least one more claim from the list. The last column is the longest exp - iat the API accepts, not a promise about what a platform issues.
No platform has been tested live. The issuer settings follow each vendor’s documentation. Not yet confirmed: the GKE key host, the EKS dual-stack key host (oidc-eks.<region>.api.aws), GitHub’s token lifetime and the Entra managed identity token lifetime. A wrong host fails closed with issuer_unavailable. Try an exchange on your own platform before you depend on it.

Pinning claims

A shared issuer signs tokens for every one of its customers: any repository on GitHub can get a token from GitHub’s issuer. So a grant pins immutable ids, never names. A repository or organization can be renamed, and its old name registered by someone else.
  • claims holds 1 to 16 entries. Each value is a printable-ASCII string compared exactly with the token’s claim. A number or boolean compares as its JSON text (4242, true).
  • A plain name pins a top-level claim (repository_id). A JSON Pointer (RFC 6901), at most four levels deep, pins a nested one: /kubernetes.io/serviceaccount/uid. Inside a name, ~1 stands for /, so AWS’s account is /https:~1~1sts.amazonaws.com~1/aws_account.
  • A claim the token does not state, or states as an array or object, never matches. Every pinned claim must match, and you may pin more than the issuer requires.
  • iss, aud, exp, nbf, iat and jti are checked by the API and cannot be pinned.
  • For GitHub and GitLab, also pin a branch, an environment or a workflow. Prefer environment with protection rules for production: reviewers gate it.
  • GitLab’s ref is a short name (main) that a branch and a tag can share, so pinning it needs ref_type (branch or tag). GitHub’s ref is already the full ref (refs/heads/main).
An identity token must:
  • be signed by one of the issuer’s keys (or the owner-signed keys); none and HMAC algorithms never verify;
  • carry iss equal to the issuer and aud equal to the grant’s audience;
  • carry iat and exp, live no longer than the table allows and be current (30 seconds of clock skew);
  • match every pinned claim.
A token may be exchanged more than once while it lives, because platforms cache them. Its audience binds it to this API and one agent, so no other service can replay it here.

The audience

The audience is {API URL}/v1/agents/{agent_id}: https://api.agentsonintents.com/v1/agents/<agent_id> on the hosted API. It has two sides:
  • In the grant: leave audience out. For every issuer except Microsoft Entra ID, the API fills it in when it builds the intent, and it refuses an explicit audience (grant_credential_invalid: “This API chooses the audience for this issuer’s tokens; leave audience out.”). The owner signs the audience the API chose.
  • In the workload: request the token for exactly this audience. That is the value your platform’s token request takes (audience for GitHub, aud for a GitLab ID token, audience for a Kubernetes projected token). oidcGrantAudience builds it.
Microsoft Entra ID is the one exception: its grant must name audience, because Entra issues tokens only for audiences registered in the tenant.
The audience is the URL the API publishes as its own (servers[0] in its OpenAPI document). An alias that reaches the same host does not match. If a deployment’s public URL ever changes, every OIDC grant signed for the old audience stops working and must be issued again.

GitHub Actions

Let the job request an identity token with id-token: write, and name an environment so the grant can pin it.
The grant pins the repository’s and owner’s numeric ids and the environment: { "type": "oidc", "issuer": "https://token.actions.githubusercontent.com", "claims": { "repository_owner_id": "…", "repository_id": "…", "environment": "production" } }. Read the ids from GET https://api.github.com/repos/{owner}/{repo} (owner.id and id).
act.ts

GitLab CI

Declare an ID token for the job with this API’s audience. GitLab puts it in the variable you name.
The grant pins namespace_id and project_id (numeric ids), and one of ref (with ref_type), environment or ci_config_ref_uri. A GitLab ID token lives for its job’s timeout (five minutes when none is set). Tokens up to a day are accepted, so a job whose timeout exceeds a day cannot exchange.

Google Cloud

From Compute Engine, Cloud Run, GKE Workload Identity or any service account you can impersonate, ask the metadata server for an identity token:
The grant pins sub, the service account’s unique id (gcloud iam service-accounts describe <email> --format='value(uniqueId)'). A grant that pins email alone is refused: a deleted account’s email can be reused, its unique id cannot.

AWS

Turn on outbound identity federation in IAM (Account settings). It shows the account’s issuer URL. The workload’s role then calls sts:GetWebIdentityToken on a regional STS endpoint:
The grant: { "type": "oidc", "issuer": "https://<uuid>.tokens.sts.global.api.aws", "claims": { "sub": "arn:aws:iam::123456789012:role/agent" } }. This works wherever the workload has AWS credentials: Lambda, EC2, ECS and EKS. The issuer pins the account and sub pins the role’s name. A role deleted and recreated with the same name in the same account matches the grant, so revoke the grant when you delete the role.

Kubernetes

Project a service account token with this API’s audience into the pod:
Read the file before each exchange, because the kubelet rotates it. Keep expirationSeconds at a day (86400) or less: longer-lived tokens are refused. The grant pins sub (system:serviceaccount:<namespace>:<name>) and /kubernetes.io/serviceaccount/uid, so a service account deleted and recreated under the same name does not inherit the grant. Read the uid with kubectl get serviceaccount <name> -o jsonpath='{.metadata.uid}'.
Use the cluster’s issuer URL as the grant’s issuer. The API discovers the cluster’s keys.The grant must pin both sub and /kubernetes.io/serviceaccount/uid.
The cluster’s issuer is often unreachable from the internet. Instead of fetching keys, the API verifies tokens against public keys the owner signs into the grant. Get them with kubectl get --raw /openid/v1/jwks, and set issuer to the cluster’s --service-account-issuer:
  • Up to four keys: RSA of at least 2048 bits, P-256, P-384 or Ed25519. Public members only, each with the kid the issuer’s tokens name. Nothing is fetched.
  • Signed keys are frozen into the grant. When the cluster rotates its signing key, or a key leaks, revoke the grant and issue a new one with the current keys.
  • Keys cannot be signed for an issuer on a vendor’s domain (GitHub, GitLab, Google, AWS, Azure, Microsoft, Vercel, Terraform), even one the list above does not name. Those issuers are verified with their published keys only.
The same jwks field works for any other https issuer whose keys the API does not fetch.

Microsoft Entra ID

Entra issues tokens only for audiences registered in the tenant, so this is the one platform where the grant must name its own audience, and the owner signs it. Every other issuer refuses an explicit audience.
  1. Create an app registration in your tenant to stand for this API. Keep it for this API alone: any service that receives its tokens could present them here. Give it an Application ID URI such as api://near-intents-agents.
  2. A VM, App Service, Functions or Container Apps workload asks its managed identity endpoint for a token for that resource. On AKS, Entra Workload ID does the same.
  3. Issue the grant. What audience and issuer must be depends on the token version:
A grant whose audience its tokens can never carry is refused at generate-intent. Every principal in the tenant, users included, can request a token for the app registration’s audience. The grant accepts one only if it carries the pinned oid. Add the idtyp optional claim to the app registration’s access tokens (Token configuration) so the grant can also pin "idtyp": "app". Entra emits that claim only in app-only tokens, so a user’s token can then never match.

Vercel

Vercel’s custom-audience exchange sets the issuer to the team that owns the deployment, so the grant uses that team-scoped issuer. Request a token for this API’s audience at runtime:
The grant: { "type": "oidc", "issuer": "https://oidc.vercel.com/<team_slug>", "claims": { "owner_id": "team_…", "project_id": "prj_…", "environment": "production" } }.

Key-bound grants

For a server with no identity provider. Generate an Ed25519 or P-256 key on it, keep the private key there, and have the owner sign a grant to the public JWK. Private members (d) and any other curve are refused.
  • Ed25519 suits a key file: { "kty": "OKP", "crv": "Ed25519", "x": "…" }.
  • P-256 suits a TPM, an HSM, AWS KMS or Google Cloud KMS: { "kty": "EC", "crv": "P-256", "x": "…", "y": "…" }.
A signer is { publicJwk, sign(signingInput) }. The SDK never needs the private key, only the public key and a signature, so the key may live anywhere. sign receives the JWS signing input as UTF-8 bytes and returns the raw 64-byte signature. For Ed25519 that is the signature over the bytes. For P-256 it is ECDSA over their SHA-256, encoded as r || s, not the ASN.1 DER that a KMS returns. See With a cloud KMS key.

Exchange a key assertion

The workload signs a short assertion (RFC 7523) and exchanges it like an identity token. With the SDK, forGrantSession(agentId, { signer }) signs one for every exchange (see Sessions). To build one yourself:

Exchange a token for a session

The body follows RFC 8693 token exchange, as JSON like every other route. subject_token is the identity token or the key assertion.
Then call any agent action with it:

Sessions

  • A session token is ngs_ plus 32 random bytes. The API stores only its SHA-256.
  • It lives 15 minutes by default and never more than 60, and never past the grant’s expiry.
  • Every request re-reads the grant. Revoking the grant, an owner change or the grant’s expiry ends all its sessions at once. Work that had already reached its dispatch commitment cannot be recalled, as with a grant token.
  • A grant holds at most 100 live sessions. The next exchange fails with grant_session_limit_reached (429, retryable at meta.available_at, when the oldest session ends). Reuse a session until it nears its end instead of exchanging on every request.
  • An identity token may be exchanged again while it lives. A key assertion exchanges once.

Let the SDK manage the session

forGrantSession returns a client that exchanges on its first delegated call and keeps the session. Keep one client per grant and reuse it: a client per invocation burns the grant’s 100 sessions.
  • Refresh in the background. From refreshBeforeSeconds (60 by default) before the session ends, and never before its mid-life, the client starts one background exchange. Meanwhile it keeps serving the current session, so a short issuer outage costs nothing. It retries until 5 seconds before the end.
  • After a failure, it waits 5 seconds before it tries another exchange, so an outage costs one exchange, not one per call.
  • Only an ended session waits. A call made after the session has ended waits for an exchange, or fails with that exchange’s error.
  • Concurrent calls share one exchange.
  • A refused session is dropped. If the API answers agent_grant_required (401 or 403), for example because the grant was revoked, the call throws that error and is not retried. The client forgets the session, and the next call exchanges again.
api.forGrant(token) also accepts an ngs_… session token, if you exchange yourself and keep the token. The client’s baseUrl must be the URL the API publishes as servers[0] (https://api.agentsonintents.com on the hosted API), because audiences are built from it.

Renew a federated grant

To renew a grant before it ends, issue the same credential again. Grants that bind the same credential are one identity, and an exchange opens its session on the one that lives longest. Unlike a token, a federated credential may back more than one grant, so grant_credential_reused does not apply. Other overlapping grants on one agent are allowed too. A token that several of them accept needs grant_id (grantId in the SDK), or the exchange fails with grant_ambiguous. Idempotency keys are scoped to the grant. A renewal is a new grant, so retry an unresolved request under the grant that sent it.

Sign every request

A public_key grant can skip the session. Instead of X-Grant-Token, the workload sends X-Grant-Proof, a JWT its key signs for that one request, on any endpoint that takes a grant token. X-API-Key is still required.
  • Proof or session? Both rest on the same grant and key, and everything after admission is the same. Choose a proof when no bearer token should exist anywhere: not in the workload’s memory, its logs or a proxy. Each proof binds one grant, method, URL, body and Idempotency-Key, and works once. Choose a session when signing is slow or costly (a cloud KMS signs over the network and bills per operation) and the workload sends many requests. The API keeps no session state for proofs.
  • One header. Sending both grant headers is refused with validation_failed (400, pointer /header/x-grant-proof). Sending neither reads agent_grant_required.
  • Retries. Every attempt signs a new proof, with a new jti, and keeps the same grant ID and Idempotency-Key. The API spends the jti before the operation runs, so a retry with the same proof is refused. The stored operation comes back for the same Idempotency-Key, including after a renewal. recover also uses the original grant ID.
grantId is the ID of the issued grant, from the grant_issue status or listGrants. Keep it fixed. The SDK signs the exact body bytes it sends, signs a new proof for every attempt, and repeats the same Idempotency-Key. The signer runs once per attempt.

What a proof signs

A proof carries the claims of an exchange assertion, with the request in place of the exchange. Serialize the body once, hash that string and send the same bytes. The proof must name a live public_key grant on the agent and be signed by the key that grant binds. A malformed path, query, body or Idempotency-Key is rejected before the proof is spent. A missing required Idempotency-Key is rejected after. With the SDK’s createGrantProof, for a client you build yourself:
Or without the SDK, with jose:

With a cloud KMS key

Create the key with purpose ASYMMETRIC_SIGN and algorithm EC_SIGN_P256_SHA256. Cloud KMS never releases the private key, so the signer asks KMS to sign. Three things differ from a local key:
  1. The public key. Read it once (getPublicKey returns a PEM) and convert it to the JWK the owner signs into the grant.
  2. The digest. For this algorithm KMS takes the SHA-256 digest of the signing input, not the data.
  3. The signature format. KMS returns the ECDSA signature DER-encoded (SEQUENCE { INTEGER r, INTEGER s }). A JWS (RFC 7518) needs the raw 64 bytes r || s, each left-padded to 32 bytes. The SDK refuses any other length.
Each asymmetricSign is a network call and a billed operation. At high request rates, prefer a session: one signature then covers 15 minutes. Cloud KMS also offers EC_SIGN_ED25519, but only at the software protection level. The example above uses P-256, which every protection level supports, HSM included. The same shape works for AWS KMS (Sign with ECDSA_SHA_256, which also returns DER) and any other signer.

Errors

The SDK throws AgentApiError with the same code. See Status & Errors for every code and Error layers for who acts next.
A brief issuer_unavailable after a platform rotates its keys is normal. Keys are read at most once every 30 seconds, so a token signed with a key the API has not read yet is refused until then. Send the same request again.

Security model

  • The owner still decides. The API cannot create or widen a federated grant. The owner signs the issuer, the audience and the claims, or the key. They are checked on every use, exactly as for token grants.
  • No secret to steal at rest. The API stores the hash of a session token and the signed binding. The workload keeps nothing long-lived (OIDC) or a private key it never sends (key-bound).
  • Verify before matching. A token is verified before its claims are compared with any grant, and every refusal of an unverified token reads the same, so it cannot probe which grants exist.
  • Keys are fetched only for named issuers. An issuer’s keys are read only when a live grant on the agent names it. A token from any other issuer reads subject_token_invalid without a network call. Retrieval has no redirects, a 64 KiB body cap and a 5-second timeout, and it fails closed.
  • Signed keys are frozen. Keys the owner signs into a grant verify for the grant’s lifetime and are never refreshed. They are refused for any issuer on a vendor’s domain, so a vendor’s issuers are always verified with their own published keys.
  • What federation trusts. An oidc grant trusts its issuer to sign only for the workload its claims name. A compromised issuer, or a compromised pinned workload (a malicious commit on the pinned branch), can act within the grant until it is revoked, as a leaked grant token could. The policy, timelock, approvals and budget still bound it. A key-bound grant trusts the machine that holds the key: a compromised host can ask its key, file, TPM or KMS to sign whatever it wants, so a proof protects the request on the wire, not the host.
  • Per-account issuers trust the account. An Entra ID tenant issues tokens for the app registration’s audience to any of its principals, so a grant must pin oid, and idtyp = app rules out users. An AWS grant pins the account and the role’s name, so a role deleted and recreated under the same name matches the grant.
  • Timing. An exchange for an issuer that a grant names takes a key read, while any other is refused at once. Response time can therefore reveal whether some grant names an issuer. The partner already lists its agents’ grants, so this is accepted.
  • Audit. Each exchange is written to the API’s audit log (agent.grant_session_opened), with the agent, grant and subject (issuer#sub, or the key’s thumbprint URI). An accepted proof is recorded in the server’s own log, not the audit log.

Limits

Grants

Issue, list and revoke grants, and what a grant does and does not decide.

Owner Signing

How the owner’s wallet signs the grant_issue intent.