Skip to Content
APIAPI Overview

API Overview

HaoAI offers four API protocol families: OpenAI-compatible, Anthropic native, Grok / xAI, and Gemini native.

Base URL

ProtocolBase URLDescription
OpenAI Compatiblehttps://api.hao.ai/v1Compatible with OpenAI SDK, supports all models
Anthropic Nativehttps://api.hao.ai/anthropicCompatible with Anthropic SDK, native Claude experience
Grok / xAI Protocolhttps://api.hao.ai/grokGrok / xAI route with an xAI OpenAI-compatible text JSON/SSE shape
Gemini Nativehttps://api.hao.ai/geminiCompatible with Google GenAI SDK

Authentication

All protocols use a unified HaoAI API Key, but the header format varies by protocol:

ProtocolHeaderFormat
OpenAIAuthorizationBearer sk-xxx
Anthropicx-api-keysk-xxx
Grok / xAIAuthorizationBearer sk-xxx
Geminix-goog-api-keysk-xxx

See the Authentication guide for details.

Available Endpoints

OpenAI Compatible Protocol

EndpointMethodDescription
/v1/chat/completionsPOSTCreate chat completion
/v1/modelsGETList available models
/v1/models/{model_id}GETGet model details
/v1/images/generationsPOSTGenerate images

Anthropic Native Protocol

EndpointMethodDescription
/anthropic/v1/messagesPOSTCreate Messages

Grok / xAI Protocol

EndpointMethodDescription
/grok/v1/chat/completionsPOSTCreate a Grok chat completion. See Chat Completions
/grok/v1/responsesPOSTCreate a Grok Responses API response. See Responses
/grok/v1/modelsGETList available Grok models. See Models
/grok/v1/models/{model_id}GETGet a Grok model detail

Gemini Native Protocol

EndpointMethodDescription
/gemini/v1beta/models/{model}:generateContentPOSTGenerate content
/gemini/v1beta/models/{model}:streamGenerateContentPOSTStream generate content

HaoAI OpenAPI (Platform)

Protocol-agnostic platform endpoints; see each endpoint’s documentation for its authentication method.

EndpointMethodDescription
/v1/user/balanceGETBalance query, compatible with cc-switch, authenticated with the HaoAI API Key
hao.ai/api/provider/pricingGETReal-time pricing, hvoy-compatible, HMAC-signed or public access

Rate Limits

HaoAI uses pay-as-you-go pricing with a unified rate policy for all users:

LimitQuota
RPM (requests/minute)100 (team-aggregated)
TPM (tokens/minute)Unlimited

RPM is aggregated at the team level — multiple API Keys under the same team share a single quota. If you need a higher RPM quota, contact support@hao.ai to request an adjustment.

When rate-limited, the API returns 429 Too Many Requests with the following response headers:

x-ratelimit-limit-requests: 100 x-ratelimit-remaining-requests: 0 x-ratelimit-reset-requests: 1s

Error Codes

All protocols return unified HTTP status codes:

Status CodeDescriptionCommon Causes
200Success
400Bad RequestInvalid parameters, missing required fields
401UnauthorizedInvalid or expired API Key
403ForbiddenAccount lacks access to the model
404Not FoundIncorrect model ID
429Rate LimitedExceeded rate limit
500Server ErrorInternal error, please retry
502Upstream ErrorModel provider service issue
503Service UnavailableUnder maintenance

Error Response Format

{ "error": { "code": "invalid_api_key", "message": "The provided API Key is invalid. Please check and try again.", "type": "authentication_error" } }

HaoAI Extension Parameters

HaoAI provides extension parameters on top of standard protocols for advanced routing and fallback control:

{ "model": "openai/gpt-4o", "messages": [...], "provider": { "routing": "cost", "fallback": ["anthropic/claude-sonnet-4.6", "grok/grok-4.5"] } }

See Provider Routing and Fallback for details.