Pay with x402 or MPP (for agents)
Fluence accepts balance top-ups over two HTTP payment protocols: x402 with USDC on Base, and MPP with USDC.e on Tempo mainnet. An HTTP client pays for a top-up, and Fluence credits the amount to a balance in the same request. When you pay without Fluence credentials, the paying wallet is the account. You need no signup, email, or visit to the Fluence Console.
An AI agent or a script works with Fluence in four steps:
- Top up the balance over x402 or Tempo MPP. The first anonymous payment from a wallet creates a Fluence account for that wallet.
- Sign in with the same wallet through Sign-In with Ethereum (SIWE) or over MPP to get an access token.
- Call the Fluence API with that token, or create an API key with it.
- Rent compute with the balance.
Supported rails and limits
Both protocols share the same top-up endpoint (POST /v2/x402/top-up?amountUsd=N). Both credit 1 USDC or 1 USDC.e as 1 USD and accept amounts in whole cents (at most two decimal places).
| Parameter | x402 (Base) | MPP (Tempo) |
|---|---|---|
| Network | Base mainnet (eip155:8453) | Tempo mainnet (eip155:4217, chain ID 4217) |
| Token | USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) | USDC.e (0x20c000000000000000000000b9537d11c60e8b50) |
| Minimum top-up | 10 USD | 10 USD |
| Maximum top-up | 1000 USD per request | 2500 USD per request |
| Payment header | PAYMENT-SIGNATURE (handled by the x402 client) | Payment-Authorization |
| Settlement mode | The x402 facilitator submits the transfer (no ETH needed for gas) | Pull mode only (supportedModes: ["pull"]); Fluence broadcasts and settles the signed transfer |
| Wallet sign-in | POST /v1/auth/siwe | POST /v1/auth/mpp |
Without payment, POST /v2/x402/top-up?amountUsd=N returns 402 Payment Required. For 10 USD to 1000 USD, the response includes both an x402 challenge and a WWW-Authenticate: Payment Tempo MPP challenge. For amounts above 1000 USD and up to 2500 USD, the response includes only the Tempo MPP challenge.
Requirements
To pay and sign in with x402 on Base, you need the following:
- An EVM wallet controlled by a private key (an externally owned account). Smart-contract wallets cannot sign in with SIWE.
- USDC on Base mainnet: network
eip155:8453, token0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913. You do not need ETH for gas. The x402 facilitator submits the transfer. - An x402 v2 client. The
@x402/*packages (@x402/fetchor@x402/axios, with@x402/evmfor EVM payments) speak v2. The unscopedx402-fetchandx402-axiospackages are the older v1 line and cannot read the Fluence payment challenge.
The x402 examples below are JavaScript modules for Node.js 20 or later. Install the packages they use:
npm install @x402/fetch @x402/evm viem
Save an example as a .mjs file and run it with node. Pass the wallet key in the EVM_PRIVATE_KEY environment variable.
To pay and sign in with MPP on Tempo, you need the following:
- A Tempo wallet private key (passed in
TEMPO_PRIVATE_KEY) or an access key authorized on chain by your Tempo wallet. - USDC.e on Tempo mainnet: network
eip155:4217, token0x20c000000000000000000000b9537d11c60e8b50. Signing in atPOST /v1/auth/mppcosts nothing and works with zero balance. - The
tempoCLI, or another MPP client that supports Tempo pull mode and thePayment-Authorizationheader.
Endpoints
Base URL: https://api.fluence.dev
| Method | Path | Credentials | What it does |
|---|---|---|---|
GET | /v2/x402/payment-info?amountUsd=N | None | Returns the x402 payment challenge for N USD without paying |
POST | /v2/x402/top-up?amountUsd=N | Optional | Without a payment, returns 402 Payment Required with x402 and Tempo MPP challenges (Tempo MPP only above 1000 USD). With a payment, settles it and credits N USD. |
GET | /v1/auth/siwe/nonce | None | Issues a single-use SIWE sign-in nonce |
POST | /v1/auth/siwe | None | Exchanges a signed Sign-In with Ethereum message for an access token |
POST | /v1/auth/mpp | None | Issues a zero-amount Tempo MPP sign-in challenge (402) and exchanges a signed proof for an access token |
GET | /v3/account/balances | Access token or API key | Returns your balance |
GET | /v3/top-ups | Access token or API key | Lists your top-ups, including x402 and Tempo MPP top-ups |
GET | /v3/account | Access token or API key | Returns your account and its permissions |
POST | /v3/api-keys | Access token or API key | Creates an API key |
All endpoints above are also documented in the API reference and the OpenAPI document.
Step 1: Top up
Choose either x402 on Base or MPP on Tempo. Both call POST /v2/x402/top-up?amountUsd=N.
If you already have a Fluence account, send your API key in the X-API-KEY header, or an access token in Authorization: Bearer, with the top-up request. Fluence then credits that account instead of a wallet account.
Top up with x402 on Base
Wrap fetch with an x402 client and call the top-up endpoint. The client handles the exchange: it gets the 402 challenge, signs the payment, and sends the request again.
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY);
const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }],
// @x402/fetch refuses to pay more than $1 per payment unless you raise the cap.
spendControls: { maxAmountPerPayment: "$10" },
});
const response = await fetchWithPayment(
"https://api.fluence.dev/v2/x402/top-up?amountUsd=10",
{ method: "POST" },
);
console.log(response.status, await response.json());
Set maxAmountPerPayment to at least the amount you top up. With the default cap of $1, the client refuses to sign, and nothing is paid.
A successful x402 top-up returns 200:
{
"amountUsd": "10",
"network": "eip155:8453",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"transaction": "0x...",
"payer": "0x..."
}
transaction is the Base transaction hash, and amountUsd is a decimal string. The PAYMENT-RESPONSE header carries the x402 settlement response.
Other x402 responses:
| Status | Meaning | What to do |
|---|---|---|
400 | The amount is out of range or has more than two decimal places, or the payment is malformed | Fix the request |
402 | Payment required, or the payment was rejected, for example because the wallet has too little USDC. The error field of the challenge says why. | Fix the cause and pay again |
409 | The payment was submitted and is under review | Do not sign a new payment: the transfer may already be on chain. Contact support@fluence.ai with the payer address. |
503 | Top-ups are unavailable, or the payment did not reach the facilitator. Nothing was charged. | Retry later |
Top up with MPP on Tempo
Call POST /v2/x402/top-up?amountUsd=N with an MPP client. The server returns 402 Payment Required with a WWW-Authenticate: Payment challenge. The challenge specifies Tempo mainnet (chainId: 4217), pull mode (supportedModes: ["pull"]), and the Payment-Authorization header. The client signs the transfer and retries with the credential in Payment-Authorization, and Fluence broadcasts and settles it.
Because the MPP credential uses Payment-Authorization, the Authorization and X-API-KEY headers stay free for crediting an existing Fluence account.
To credit an existing account with an access token, pass --bearer:
TEMPO_PRIVATE_KEY=0x... tempo request --network mainnet --max-spend 10.5 \
-X POST --bearer "<ACCESS_TOKEN>" \
'https://api.fluence.dev/v2/x402/top-up?amountUsd=10'
To pay anonymously and create or credit the paying wallet's account, omit --bearer:
TEMPO_PRIVATE_KEY=0x... tempo request --network mainnet --max-spend 10.5 \
-X POST 'https://api.fluence.dev/v2/x402/top-up?amountUsd=10'
A successful Tempo MPP top-up returns 200:
{
"amountUsd": "10.00",
"network": "eip155:4217",
"asset": "0x20c000000000000000000000b9537d11c60e8b50",
"transaction": "0x...",
"payer": "0x..."
}
transaction is the Tempo transaction hash, and amountUsd is a decimal string. The response includes a Payment-Receipt header with status: "success", method: "tempo", and reference set to the transaction hash.
The credited balance appears in GET /v3/account/balances shortly after settlement (observed within about 30 seconds) and in top-up history at GET /v3/top-ups.
Other Tempo MPP responses:
| Status | Meaning | What to do |
|---|---|---|
400 | The amount is outside 10 USD to 2500 USD, has more than two decimal places, or the request is malformed | Fix the request |
402 | Payment required, or nothing moved (refused before broadcast, reverted, or closed unpaid) | Fix the cause and pay again |
409 | The transfer was broadcast, is still settling, or is held for review | Do not pay again. Retry the same credential later, or contact support@fluence.ai with the payer address and transaction hash. |
503 | The verification check could not run | Retry the same credential later |
Step 2: Sign in with the wallet
Sign in with the paying wallet to get an access token. Use SIWE for a standard EVM wallet, or MPP sign-in for a Tempo wallet. Both endpoints return the same {accessToken, refreshToken, userData} JSON payload for the same wallet-bound account.
Sign in with Ethereum (SIWE)
Request a nonce, sign a Sign-In with Ethereum message with the wallet that paid, and exchange it for an access token.
import { privateKeyToAccount } from "viem/accounts";
import { createSiweMessage } from "viem/siwe";
const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY);
const { nonce } = await (await fetch("https://api.fluence.dev/v1/auth/siwe/nonce")).json();
const message = createSiweMessage({
domain: "api.fluence.dev",
address: account.address,
uri: "https://api.fluence.dev",
version: "1",
chainId: 8453,
nonce,
});
const signature = await account.signMessage({ message });
const login = await fetch("https://api.fluence.dev/v1/auth/siwe", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message, signature }),
});
const { accessToken, userData } = await login.json();
Keep these SIWE rules in mind:
- The message
domainmust be exactlyapi.fluence.dev. The API rejects any other domain. - A nonce works once and expires 10 minutes after it is issued. The nonce response has the time in
expiresAt. - Send the message exactly as signed.
Sign in over MPP (Tempo)
Call POST https://api.fluence.dev/v1/auth/mpp with an MPP client. Without a credential, the API returns 402 Payment Required with a zero-amount WWW-Authenticate: Payment challenge (chainId: 4217, realm: "api.fluence.dev"). Nothing is charged.
The client signs the challenge and retries with the proof in Payment-Authorization (or in Authorization with the Payment scheme). Each challenge is single-use.
TEMPO_PRIVATE_KEY=0x... tempo request --network mainnet --max-spend 0 \
-X POST https://api.fluence.dev/v1/auth/mpp
A regular private key (TEMPO_PRIVATE_KEY) works immediately with zero balance. The response is 200 with {accessToken, refreshToken, userData} for the wallet-bound account (wallet-<address>@x402.invalid).
An access key authorized on chain by a Tempo wallet signs in to the entire Fluence account, regardless of its on-chain spending limit. Publish the access key on chain before signing in. The API rejects an unpublished pending access key with 401.
Account identity and token lifetime
Both SIWE and MPP sign-in share these details:
userDataholds the accountidand a placeholder emailwallet-<address>@x402.invalid. The wallet address is the identity of the account.- The access token expires after a few minutes. The response also has a
refreshToken, but the public API has no endpoint that accepts it. When the access token expires, sign in again, or create an API key once and use it instead.
Step 3: Use the API
Send the access token as a bearer token. For example, check the balance:
curl https://api.fluence.dev/v3/account/balances \
-H "Authorization: Bearer <ACCESS_TOKEN>"
GET /v3/top-ups lists your top-ups, including x402 and Tempo MPP top-ups.
Create an API key
A long-running agent can create an API key once and send it in the X-API-KEY header. This example gives the key every scope your account has:
SCOPES=$(curl -s https://api.fluence.dev/v3/account \
-H "Authorization: Bearer <ACCESS_TOKEN>" | jq -c '.permissions')
curl -X POST https://api.fluence.dev/v3/api-keys \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d "{\"name\": \"my-agent\", \"scopes\": $SCOPES, \"expiresAt\": \"<YYYY-MM-DD>T00:00:00Z\"}"
The request takes three fields:
name: 1 to 25 characters, lowercase letters, digits, and hyphens.scopes: what the key may do. A key can only get scopes that your account has.GET /v3/accountlists them inpermissions. A call outside the key's scopes returns403.expiresAt: an RFC 3339 time in the future.
The response is 201 with the key in value and its id. The API shows the key only once, so store it. To delete a key, send DELETE /v3/api-keys/<id>.
Creating a key has no Idempotency-Key. If the response is lost, a repeated request creates a second key. List your keys with GET /v3/api-keys and delete the one whose value you did not receive.
An agent can also use the API key with the Fluence MCP server. See Connect an AI client through MCP.
Step 4: Rent compute
To run a CPU VM, follow CPU Cloud API: Create a VM:
- Choose a cluster with
GET /v3/clusters, and a configuration withGET /v3/clusters/<cluster_id>/vm-offerings. - Choose an OS image with
GET /v3/images. - Add your SSH public key with
POST /v3/ssh-keys. - Create a draft with
POST /v3/vmsand anIdempotency-Key. Add a public interface to reach the VM from the internet. - Check the price with
GET /v3/vms/<vm_id>/estimate. - Start the VM with
POST /v3/vms/<vm_id>/provision. - Read
GET /v3/vms/<vm_id>/interfacesuntil the public interface has an address inassignedIps, then connect withssh <username>@<address>.
For GPU containers, VMs, and bare metal servers, see the GPU Cloud API.
Billing for agents
Keep these billing rules in mind when running compute from a wallet account:
- CPU resources are billed per second and charged from the balance as they run. Nothing is reserved up front.
- Fluence starts a CPU VM only if the balance can keep all your resources, including the new ones, running for at least 6 hours.
- Terminating a VM stops billing for the VM only. Delete its disks with
DELETE /v3/storages/<storage_id>and its public IP address withDELETE /v3/public-ips/<public_ip_id>to stop paying for them. - A wallet account has no email address, so it gets no low-balance warnings. Watch
GET /v3/account/balancesand top up before the balance runs out. - If the balance runs out and the debt exceeds 5 USD or stays unpaid for 3 days, Fluence removes your VMs. Your disks and public IP addresses stay. If the debt then reaches 20 USD or stays unpaid for 10 more days, Fluence deletes all your resources, including disks and public IP addresses.
- GPU instances are billed from the moment they start running, by the billing step of their offer, with a minimum charge. When the balance runs out, Fluence ends them within minutes. See GPU Cloud billing.