x402factory.ai · gpt
Base GPT wrapper API using x402 payments. Default direct call: model gpt-5-mini, max_output_tokens=2000, fixed price 0.01 USDC for up to 1000 input tokens. For all other settings the price is computed per model as (input_tokens * input_price_per_million + max_output_tokens * output_price_per_million) / 1,000,000, with a minimum of 0.001 USDC and always rounded up to 6 decimals. Optional max_input_tokens lets you cap the input tokens used for pricing; if the message is longer than this cap the server returns an error instead of under-pricing. Optional action=message (or omitting action) performs a direct GPT call with the given message. Optional action=create creates a custom agent with the given message as preprompt for 0.001 USDC (no OpenAI call), stores a base_price_usdc using (max_input_tokens_for_agent or 1000) + preprompt + max_output_tokens, and returns a custom_id. Optional action=list lists up to 100 recent custom agents for the paying wallet for 0.001 USDC without calling OpenAI. Custom agents can be called via POST /base/llm/gpt with custom_id, or POST /base/llm/gpt/{custom_id}. Each custom agent has a fixed price per call based on its stored preprompt, model, max_output_tokens and max_input_tokens; if the runtime message is longer than max_input_tokens the server returns an error. This specific request uses model gpt-5-mini with max_output_tokens=2000. Pricing mode: default. Prepaid price (x402) for this request: 0.010000 USDC.
HTTP 402 with machine-readable payment
terms, your agent pays the $0.01 USDC in USDC on-chain, and retries automatically. Pays to 0x402FaCcC3fAeb72351CC2b68C7966faF5f22B0d4.Call it in 30 seconds
// npm i x402-fetch viem
import { wrapFetchWithPayment } from "x402-fetch";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
const account = privateKeyToAccount(process.env.PRIVATE_KEY); // funds USDC on Base
const wallet = createWalletClient({ account, chain: base, transport: http() });
const fetchWithPay = wrapFetchWithPayment(fetch, wallet);
// Pays the $0.01 USDC automatically on the 402, then returns the real response:
const res = await fetchWithPay("https://x402factory.ai/base/llm/gpt", { method: "POST" });
console.log(await res.json());
# pip install x402 eth-account httpx
import os, asyncio
from eth_account import Account
from x402.clients.httpx import x402HttpxClient
account = Account.from_key(os.environ["PRIVATE_KEY"]) # funds USDC on Base
async def main():
async with x402HttpxClient(account=account) as client:
# x402 handles the 402 -> pay ($0.01 USDC) -> retry automatically
r = await client.get("https://x402factory.ai/base/llm/gpt")
print((await r.aread()).decode())
asyncio.run(main())
# 1) An unpaid request returns HTTP 402 with the exact payment terms:
curl -i -X POST "https://x402factory.ai/base/llm/gpt" \
-H 'content-type: application/json' \
-d '{"action": {"description": "Optional action. Use 'message' (or omit action) for a direct GPT call, 'create' to create a custom agent with a preprompt, or 'list' to list your custom agents without calling OpenAI.", "enum": ["message", "create", "list"], "required": false, "type": "string"}, "custom_id": {"description": "Optional custom agent ID returned from action=create. When set, the preprompt + model from that agent are used. Can also be provided via URL: /base/llm/gpt/{custom_id}.", "required": false, "type": "string"}, "max_input_tokens": {"description": "Optional hard ceiling on input tokens used for pricing. For normal calls this caps the user message tokens. For custom agents this caps the user message tokens on top of the fixed preprompt. If the actual message is longer than this value, the server returns an error instead of under-pricing.", "required": false, "type": "number"}, "max_output_tokens": {"description": "Maximum number of output tokens. Default 2000. Higher limits increase the prepaid price because x402 payments are upfront.", "required": false, "type": "number"}, "message": {"description": "User message for the LLM. Required for normal GPT calls. For action=create this becomes the preprompt that is stored for the custom agent.", "required": false, "type": "string"}, "model": {"description": "Logical model name. One of: gpt-5.1, gpt-5-mini (default), gpt-5-nano, gpt-5-pro. Pricing is per model using per-million token rates.", "enum": ["gpt-5.1", "gpt-5-mini", "gpt-5-nano", "gpt-5-pro"], "required": false, "type": "string"}}'
# 2) Paying + retrying requires an x402 client that can sign the USDC
# authorization (curl alone cannot). See the JS / Python tabs below.
New to x402? Read the 5-minute quickstart →