Guide · Developers

How to swap with the XAUConnect API

Written by XAUConnect Labs · Reviewed against live product behavior · Updated August 2026

The same quote and build pipeline the website uses is a public REST API at `https://xauconnect.com/api`. There is no API key required to compare routes. Your bot — or an LLM tool call — asks for a quote, receives unsigned transaction data, signs with its own key manager, then optionally records the hash for analytics.

This is a working walkthrough, not a marketing page: endpoints, the EVM vs Solana fork, identification headers, and the mistakes that drain test wallets.

Map the flow before you write code

1) Fetch supported chains and tokens to resolve chain keys and checksummed addresses. Never guess a USDC address. 2) Request a quote with chainKey, tokenIn, tokenOut, and amount. 3) If the quote looks right, request a build for the unsigned payload. 4) Sign locally. 5) Broadcast via your RPC on EVM, or submit already-signed Solana bytes through the relay endpoint. 6) Optionally record the hash so the trade shows in usage analytics. OpenAPI lives at `/openapi.json` and the human docs at `/developers/api/swap`.

Identify the agent

Send client identification headers (id, display name, and source) on every call if you want the admin API Agents tab to attribute traffic. These headers do not grant extra rate limit by themselves and they are not a custody handshake. Do not put secrets in them.

EVM: you broadcast, we do not

Build returns `{ to, data, value }`. Check ERC-20 allowance (`GET /swap/allowance`); if it is below the input amount, send an approve to the spender in the quote, wait for confirmation, then `sendTransaction` from viem/ethers/Turnkey. There is no `POST /swap/submit-evm` on purpose — a server that submits unsigned EVM txs would be a custodian. Always simulate. If simulation fails, do not retry blindly with higher gas; fix allowance, amount, or slippage first.

Solana: sign first, then relay

Build returns base64 unsigned VersionedTransaction bytes. Sign with a keypair, Phantom adapter, or custody provider. `POST /swap/submit-solana` broadcasts those signed bytes through the backend RPC (Helius in production) because some browser environments block public RPC. The server still never sees the private key.

Cross-chain from a bot

`POST /swap/cross-chain/quote` and `/build` add bridge status. Your agent must poll until destination funds arrive and must not treat source-chain success as the full trade. Timeouts and stuck messages are operational risk — budget them like you would an exchange withdrawal.

Rate limits and hygiene

Bursting quote every 50ms on an idle pair wastes everyone’s crawl of liquidity APIs and will get you throttled. Poll on a timer that matches your edge (1–5s for arb, slower for treasury rebalances). Cache token lists. Pin decimals from the token endpoint, not from a screenshot.

Errors you should treat as fatal vs retryable

Retryable: provider timeouts, empty route lists on a liquid pair, RPC 429s. Fatal until a human looks: unknown token address, impact above your policy cap, simulation revert that names a tax token, or a chainKey your allowlist does not include. A bot that retries fatal errors with higher slippage is how treasuries disappear. Log the quote id, the hop list, and the minimum received you almost signed. Support conversations without those three are guesswork. The OpenAPI examples in /developers/api/swap match this flow exactly — copy them rather than inventing a fourth client.

Legal

Risk disclosure

XAUConnect is a non-custodial swap aggregator. Digital assets are volatile and may lose value rapidly. Content on this page is educational and not investment advice. Verify every contract address on the official block explorer before approving a transaction.

Frequently asked questions

Do I need KYC to use the Swap API?

No. It is a non-custodial quote/build API. You still must follow the laws that apply to your bot and your jurisdiction. The API will not KYC you because it never holds the funds.

Can an LLM call this directly?

Yes, as a tool: quote is read-only; build still requires a signer the model does not control. Never paste a private key into a prompt. Use Turnkey, KMS, or a session signer with spending limits.

Where is the interactive spec?

https://xauconnect.com/developers/api and https://xauconnect.com/openapi.json

What if quote succeeds and build fails?

Liquidity moved or the provider rejected the size. Re-quote. Do not reuse calldata from a previous block.

Live execution

Trade on XAUConnect

Open the swap page to compare live routes, set slippage, and sign from your own wallet — fully non-custodial.

Continue exploring

Related markets, guides & networks

Curated next steps based on this topic — deepen your research before you trade.

Build programmatically

Swap via API for bots and AI agents — quotes, builds, and cross-chain routes.

Developer quickstart