API Documentation

API Hub provides an OpenAI-compatible API at 10x lower cost. 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, 10x cheaper
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. You will receive a JWT token, an API key, and 1,000,000 free tokens.

Request Body

FieldTypeRequiredDescription
emailstringYesYour email address
passwordstringYesMin 6 characters

Example

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

# Response
{
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "api_key": "sk-a1b2c3d4e5f6...",
  "balance": 1000000,
  "message": "Registration successful! 1,000,000 free tokens granted."
}
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="")

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 IDProviderPrice / 1M tokensStreaming
deepseek-chatDeepSeek$0.25
deepseek-reasonerDeepSeek$0.55
qwen-turboAlibaba Qwen$0.10
qwen-plusAlibaba Qwen$0.20
qwen-maxAlibaba Qwen$0.30
glm-4-flashZhipu GLM$0.15

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 are used. Error responses include a detail message.

StatusCodeDescription
400Bad RequestInvalid parameters or missing required fields
401UnauthorizedMissing or invalid API key / JWT token
402Payment RequiredInsufficient token balance. Top up from your dashboard.
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, 100%. We follow the OpenAI API specification exactly. Streaming, function calling, JSON mode, and all standard parameters work. Just change base_url and api_key in your existing code.

How is billing calculated?+

You are charged per token. Each model has a fixed price per 1 million tokens (see the Models table above). Your balance is deducted after each API call based on actual token usage. There are no monthly fees or hidden charges.

Do you support streaming?+

Yes. All models support SSE streaming. Set "stream": true in your request. The response uses standard Server-Sent Events format.

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.