Using the API

Learn how to integrate Flux programmatically.

Gateway Endpoint

All API requests go through the Flux gateway:

https://useflux.site/api/v2/gateway/{apiId}/{path}

Replace {apiId} with your API ID and {path} with your endpoint path.

AI Agent Discovery

Flux provides two endpoints for AI agents to discover and integrate APIs automatically:

OpenAPI 3.0 Specification

GET /api/v2/apis/{apiId}/openapi

Returns a complete OpenAPI 3.0 specification with:

  • All endpoints and parameters

  • Request/response schemas

  • Pricing information (x-flux-pricing)

  • Example prompts (x-flux-example-prompts)

  • Security schemes (FluxPayment + FluxSignature)

Example Response:

AI Agent Info

Returns human-readable metadata for AI agents:

  • API capabilities and descriptions

  • Integration guide with code examples

  • Payment flow instructions

  • Supported chains and tokens

Example Response:

Authentication

Every request requires two headers:

  1. Payment Transaction Hash - Proof of payment

  2. Wallet Signature - Proof of ownership

Required Headers

Payment Flow

1. Send Payment

Send ETH/tokens to the endpoint's recipient address:

2. Sign Message

Sign a message proving you own the wallet:

3. Make Request

Send your API request with the headers:

Complete Example (ETH Payment)

USDC Payments

Flux supports USDC and other ERC20 tokens. USDC uses 6 decimals (not 18 like ETH).

USDC Contract Addresses

USDC Payment Example (Thirdweb)

USDC Payment Example (ethers.js)

Important: USDC uses transfer() which transfers directly from your wallet. No approval needed!

Error Handling

Rate Limiting

Flux doesn't impose rate limits - you pay per request. However, the underlying API may have its own limits.

Best Practices

  1. Cache transaction hashes - Don't reuse the same payment

  2. Handle pending transactions - Wait for confirmation before calling

  3. Store signatures securely - Don't expose them publicly

  4. Monitor gas prices - Use appropriate gas for timely confirmation

Next Steps

Last updated