API reference

cn2.ai exposes two types of endpoints: proxy endpoints (for buyers making API calls) and platform endpoints (for sellers managing keys and configuration).

Proxy endpoints

Every supported provider has a subdomain that mirrors the upstream API. Send the same request you would send to the provider, but to the cn2.ai subdomain instead. Payment is handled via MPP.

# Instead of:
POST https://api.openai.com/v1/chat/completions

# Use:
POST https://openai.cn2.ai/v1/chat/completions

Request headers

HeaderRequiredDescription
AuthorizationOn retryPayment <credential> — MPP payment credential from the 402 challenge
X-CN2-PoolOptionalSet to premium for premium pool routing (25% higher cost, higher reliability)
Content-TypeYesapplication/json for most endpoints

Response headers

HeaderWhenDescription
WWW-Authenticate402 responsePayment challenge with pricing and accepted methods
Payment-ReceiptSuccessful paid requestProof of payment — save this for dispute submissions

Platform API

Sellers use the platform API to manage keys, view earnings, and configure webhooks. All platform endpoints require authentication via a bearer token from Supabase Auth.

Keys

POST/api/keysCreate a new key listing
GET/api/keysList all your keys
GET/api/keys/:idGet key details
PATCH/api/keys/:idUpdate key configuration
DELETE/api/keys/:idRemove a key listing
POST/api/keys/:id/rotateStart key rotation
POST/api/keys/importBulk CSV import

Marketplace (public)

GET/api/marketplace/providersList providers with pool stats

Webhooks

GET/api/webhooksList webhook endpoints
POST/api/webhooksCreate webhook endpoint
PATCH/api/webhooks/:idUpdate endpoint
DELETE/api/webhooks/:idDelete endpoint

Disputes (buyer)

POST/api/disputesSubmit a dispute
GET/api/disputesList your disputes

Discovery

GET/openapi.jsonOpenAPI 3.1 spec (per subdomain)
GET/.well-known/mcp.jsonMCP Server Card (per subdomain)
GET/.well-known/agent-card.jsonA2A Agent Card (per subdomain)
GET/.well-known/api-catalogRFC 9727 API catalog (root domain)

See error codes for the full list of error responses.