API Documentation

XHuoAPI exposes a fully OpenAI-compatible API surface with access to 500+ mainstream AI models.

Base URL

https://api.xhuoapi.ai

Quick Start

  1. Sign up at the console
  2. Create an API key in the console
  3. Point your Base URL to https://api.xhuoapi.ai
  4. Start making requests

Authentication

Every request must include your API key in the HTTP header:

Authorization: Bearer YOUR_API_KEY

⚠️ Security notice: never expose your API key in client-side code. Proxy requests through your own backend instead.

Chat Completions

Create a chat completion. Works with every model on the platform.

POST /v1/chat/completions

Parameters

Parameter Type Required Description
model string Model ID, e.g. gpt-4o
messages array List of conversation messages
temperature number Sampling temperature (0-2), defaults to 1
max_tokens integer Maximum number of tokens to generate
stream boolean Stream partial results, defaults to false

Example Request

curl https://api.xhuoapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "Hello, introduce yourself"
      }
    ],
    "temperature": 0.7
  }'

Example Response

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I am an AI assistant..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 20,
    "total_tokens": 32
  }
}

List Models

Retrieve the list of every model available to your key.

GET /v1/models

Example Request

curl https://api.xhuoapi.ai/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"

Popular Models

gpt-4o

OpenAI's latest multimodal model

claude-3-5-sonnet-20241022

Anthropic Claude 3.5 Sonnet

gemini-2.0-flash-exp

Google Gemini 2.0 Flash

deepseek-chat

DeepSeek V3 chat model

Streaming

Set stream: true to receive tokens as they are generated.

Example Request

curl https://api.xhuoapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Tell me a joke"}],
    "stream": true
  }'

Response Format

Streamed responses use Server-Sent Events (SSE). Every line is prefixed with data:

data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"Hel"}}]}

data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"lo"}}]}

data: [DONE]

Error Handling

The API uses conventional HTTP status codes to indicate the result of a request.

Status Code Description
200 Success
400 Invalid request parameters
401 API key missing or invalid
429 Rate limit exceeded
500 Internal server error

Example Error Response

{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

Code Examples

Python

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.xhuoapi.ai/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Hello"}
    ]
)

print(response.choices[0].message.content)

Node.js

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://api.xhuoapi.ai/v1'
});

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Hello' }]
});

console.log(response.choices[0].message.content);

cURL

curl https://api.xhuoapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Need help? Open the console or reach us on Telegram

© 2024 XHuoAPI. All rights reserved.