API Documentation

API Hub provides an OpenAI-compatible API with listed model prices. Access DeepSeek, Qwen, and GLM through the same interface you already know.

Quick Start

Just change two lines in your existing OpenAI code:

# Before (OpenAI)
from openai import OpenAI
client = OpenAI(api_key="sk-your-openai-key")

# After (API Hub) - same SDK, listed prices
from openai import OpenAI
client = OpenAI(
    api_key="sk-your-apihub-key",
    base_url="https://apihub4u.com/v1",
)
🌐

Base URL

https://apihub4u.com/v1
🔑

Authentication

Include your API key in the Authorization header as Bearer sk-...

Authentication

Register an account, login to get a JWT token, then use the token to manage your API keys.

POST
/auth/register

Create a new account. Returns a JWT. When email verification is required, no API key is issued until you verify; trial credits are granted on verify, then create a key in the dashboard.

Request Body

FieldTypeRequiredDescription
emailstringYesYour email address
passwordstringYesMin 8 characters

Example

# Register
curl -X POST https://apihub4u.com/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"dev@example.com","password":"mypassword8"}'

# Response (email verification required)
{
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "balance": 0,
  "email_verified": false,
  "message": "Verify your email to claim trial credits, then create an API key."
}
POST
/auth/login

Login with your email and password to get a JWT token.

Example

curl -X POST https://apihub4u.com/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"dev@example.com","password":"mypassword"}'

# Response
{"token": "eyJhbGciOiJIUzI1NiIs...", "balance": 1000000}

API Keys

Manage your API keys. All requests require JWT authentication (Bearer token from login).

GET
/api-keys

List all your API keys. Full keys are masked for security.

curl https://apihub4u.com/api-keys \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
POST
/api-keys?name=my-key

Create a new API key. Optionally give it a name for identification.

curl -X POST "https://apihub4u.com/api-keys?name=production" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
DELETE
/api-keys/{key_id}

Deactivate an API key. The key can no longer be used for API calls.

curl -X DELETE https://apihub4u.com/api-keys/key_abc123 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Chat Completions

Fully OpenAI-compatible chat completions endpoint. Supports streaming, all models, and standard parameters.

POST
/v1/chat/completions

Send a chat completion request. Authenticate with your API key.

Parameters

FieldTypeRequiredDescription
modelstringYesModel ID (e.g. deepseek-chat, qwen-turbo, glm-4-flash)
messagesarrayYesArray of message objects with role and content
streambooleanNoEnable SSE streaming. Default: false
max_tokensintegerNoMaximum tokens in the response
temperaturefloatNoSampling temperature (0-2). Default: 1

Python

from openai import OpenAI

client = OpenAI(
    api_key="sk-your-apihub-key",
    base_url="https://apihub4u.com/v1",
)

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
)

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

Node.js

import OpenAI from "openai";

const client = new OpenAI({
    apiKey: "sk-your-apihub-key",
    baseURL: "https://apihub4u.com/v1",
});

const response = await client.chat.completions.create({
    model: "deepseek-chat",
    messages: [{role: "user", content: "Hello!"}],
});

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

cURL

curl https://apihub4u.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-apihub-key" \
  -d '{
    "model": "deepseek-chat",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Streaming

# Python streaming example
stream = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

Images & Video

Generate images and videos via Bailian Wan / Qwen models. Authenticate with your API key. Image sync models return URLs immediately; async image/video jobs return a task id — poll until succeeded.

POST
/v1/images/generations

Text-to-image. Sync models (e.g. wan2.6-t2i) return OpenAI-style data[].url. Async models (e.g. wanx-v1) return a task id.

curl https://apihub4u.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-apihub-key" \
  -d '{
    "model": "wan2.6-t2i",
    "prompt": "A product photo of wireless earbuds on marble, soft studio light",
    "size": "1280*1280",
    "n": 1
  }'
POST
/v1/videos/generations

Text-to-video / image-to-video / video edit. Always async — returns task id. For i2v pass image_url; for edit pass video_url.

curl https://apihub4u.com/v1/videos/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-apihub-key" \
  -d '{
    "model": "wan2.6-t2v",
    "prompt": "Ocean waves at sunset, cinematic camera drift",
    "duration": 5,
    "resolution": "720P"
  }'
GET
/v1/tasks/{task_id}

Poll an async image or video job. status: pending | processing | succeeded | failed. On success, URLs are in data[].url (video also has video_url).

curl https://apihub4u.com/v1/tasks/TASK_ID \
  -H "Authorization: Bearer sk-your-apihub-key"

Speech (TTS & ASR)

Text-to-speech and speech-to-text via CosyVoice / Qwen ASR. Same API key. ASR accepts a public HTTPS file_url or OpenAI-style multipart file upload.

POST
/v1/audio/speech

TTS. Returns MP3/WAV bytes (OpenAI-compatible). Pass return_url=true to get a JSON URL instead.

curl https://apihub4u.com/v1/audio/speech \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-apihub-key" \
  -d '{
    "model": "cosyvoice-v3-flash",
    "input": "你好,欢迎使用 API Hub。",
    "voice": "longanyang",
    "response_format": "mp3"
  }' --output speech.mp3
POST
/v1/audio/transcriptions

ASR. Sync models return {text}. Async fun-asr returns a task id — poll GET /v1/tasks/{id} (text is filled in when ready). Pass file_url or multipart file.

curl https://apihub4u.com/v1/audio/transcriptions \
  -H "Authorization: Bearer sk-your-apihub-key" \
  -F model=qwen3-asr-flash \
  -F file=@./sample.mp3

# Or JSON with a public URL
curl https://apihub4u.com/v1/audio/transcriptions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-apihub-key" \
  -d '{
    "model": "qwen3-asr-flash",
    "file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"
  }'

Models

List all available models and their capabilities.

GET
/v1/models

Returns a list of all available models. No authentication required.

curl https://apihub4u.com/v1/models

Available Models

Model IDProviderCategoryUse CasesPrice / 1M tokensStreaming

Billing

Check your balance and view usage history. All billing endpoints support both JWT and API Key authentication.

GET
/billing/balance

Get your current token balance. Returns balance and email.

curl https://apihub4u.com/billing/balance \
  -H "Authorization: Bearer sk-your-apihub-key"

# Response
{"balance": 985000, "email": "dev@example.com"}
GET
/billing/usage?limit=50

View recent usage records. Returns model, tokens consumed, cost, and timestamp for each call.

curl "https://apihub4u.com/billing/usage?limit=10" \
  -H "Authorization: Bearer sk-your-apihub-key"

Error Codes

Standard HTTP status codes. Errors use OpenAI-compatible JSON: {"error":{"message":"...","type":"...","code":"..."}}.

StatusCodeDescription
400Bad RequestInvalid parameters or missing required fields
401UnauthorizedMissing or invalid API key / JWT token
402insufficient_balanceInsufficient balance. Top up from your dashboard to continue.
404Not FoundResource not found (e.g., invalid API key ID)
429Too Many RequestsRate limit exceeded. Retry after the specified time.
500Internal ErrorServer error. Contact support if it persists.
502Bad GatewayUpstream provider error. The request could not be proxied.

Frequently Asked Questions

Is the API really OpenAI-compatible?+

Yes for common chat completions, streaming, function calling, and JSON mode. Change base_url and api_key in your existing code to get started.

How is billing calculated?+

Chat models are billed per token. Image/video models are billed per request (or by estimated duration). See the Models table. Your balance is deducted after each call. No monthly fees.

Do you support streaming?+

Yes for chat completions. Set "stream": true. Image, video, and some audio endpoints are request/response (or async task polling), not SSE token streams.

What is the rate limit?+

Free tier: 60 requests per minute. Paid plans: higher limits based on your tier. Contact us for custom limits.

Can I use multiple API keys?+

Yes. Create separate keys for development, staging, and production. All keys share the same token balance. You can deactivate keys at any time.