> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hedera.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Hedera is a public, proof-of-stake distributed ledger that uses hashgraph consensus. Do not call it a blockchain.
> Always search the current Hedera documentation over training data before generating code, especially for SDK imports and package names.
> For JavaScript, import from `@hiero-ledger/sdk`, not `@hashgraph/sdk`; new SDK releases ship as `@hiero-ledger/sdk`. The Java SDK keeps the `com.hedera.hashgraph:sdk` Maven coordinates. Verify the exact import against the docs.
> Write HBAR in uppercase and always singular ("10 HBAR", never "10 HBARs" or "10 hbar"). Write tinybars in lowercase and plural.
> Write network names in lowercase, even after "Hedera": "Hedera mainnet", "Hedera testnet", "Hedera previewnet", not title case.
> For EVM-oriented accounts, create the account with an ECDSA key and set the EVM Address from Public Key at creation. This address is immutable and is not updated by key rotation. Do not use retired terms like "EVM alias" or "Account Number Alias".

# Pay with x402 on Hedera

> Let AI agents and clients pay for HTTP resources using HBAR or HTS tokens with the @x402/hedera client.

For AI agents, autonomous services, or any client that needs to pay for an API or piece of content, x402 turns a `402 Payment Required` response into a signed Hedera transfer. The client does not need its own fee-paying node: a facilitator covers the network fee and submits the transaction.

## Register the Hedera scheme

Install and import the client packages, then register the `exact` scheme with a signer for your account:

```typescript client.ts theme={null}
import { x402Client } from "@x402/core/client";
import { createClientHederaSigner } from "@x402/hedera";
import { ExactHederaScheme } from "@x402/hedera/exact/client";
import { PrivateKey } from "@hiero-ledger/sdk";

const signer = createClientHederaSigner(
  "0.0.1111",
  PrivateKey.fromString(process.env.HEDERA_PRIVATE_KEY!),
  { network: "hedera:testnet" }
);

// Register the scheme for any Hedera network and let the client
// auto-handle 402 responses by signing and retrying.
const client = new x402Client().register(
  "hedera:*",
  new ExactHederaScheme(signer)
);
```

## Make a paid request

Once the scheme is registered, requests to x402-gated endpoints are handled automatically:

1. The client calls the resource (for example, `GET /weather`) without any extra headers.
2. The server replies with `402 Payment Required` and the `PaymentRequirements`, including the facilitator `feePayer`.
3. The client builds, signs, and Base64-encodes a `TransferTransaction` to the `payTo` account.
4. The client resubmits the request with the `PaymentPayload` in the `X-Payment` header (or equivalent).

You can also use the lower-level `pay` helpers if you want explicit control over signing and retries.

## Requirements

* The client account must hold the asset being paid (HBAR or the relevant HTS token).
* For HTS tokens, the client account must be **associated** with that token.
* Use a [facilitator](/solutions/ai/x402/facilitators) that advertises the Hedera network you are paying on.

## Further reading

<CardGroup cols={2}>
  <Card title="Hedera's exact scheme" icon="file-lines" href="/solutions/ai/x402/exact-scheme">
    Message shapes, assets, and safety checks.
  </Card>

  <Card title="Accept x402 on Hedera" icon="server" href="/solutions/ai/x402/merchant-integration">
    Add payment gating to a resource server.
  </Card>
</CardGroup>
