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
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.
Create a new account. You will receive a JWT token, an API key, and 1,000,000 free tokens.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Your email address |
password | string | Yes | Min 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."
}
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).
List all your API keys. Full keys are masked for security.
curl https://apihub4u.com/api-keys \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
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"
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.
Send a chat completion request. Authenticate with your API key.
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (e.g. deepseek-chat, qwen-turbo, glm-4-flash) |
messages | array | Yes | Array of message objects with role and content |
stream | boolean | No | Enable SSE streaming. Default: false |
max_tokens | integer | No | Maximum tokens in the response |
temperature | float | No | Sampling 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.
Returns a list of all available models. No authentication required.
curl https://apihub4u.com/v1/models
Available Models
| Model ID | Provider | Price / 1M tokens | Streaming |
|---|---|---|---|
deepseek-chat | DeepSeek | $0.25 | ✓ |
deepseek-reasoner | DeepSeek | $0.55 | ✓ |
qwen-turbo | Alibaba Qwen | $0.10 | ✓ |
qwen-plus | Alibaba Qwen | $0.20 | ✓ |
qwen-max | Alibaba Qwen | $0.30 | ✓ |
glm-4-flash | Zhipu GLM | $0.15 | ✓ |
Billing
Check your balance and view usage history. All billing endpoints support both JWT and API Key authentication.
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"}
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.
| Status | Code | Description |
|---|---|---|
| 400 | Bad Request | Invalid parameters or missing required fields |
| 401 | Unauthorized | Missing or invalid API key / JWT token |
| 402 | Payment Required | Insufficient token balance. Top up from your dashboard. |
| 404 | Not Found | Resource not found (e.g., invalid API key ID) |
| 429 | Too Many Requests | Rate limit exceeded. Retry after the specified time. |
| 500 | Internal Error | Server error. Contact support if it persists. |
| 502 | Bad Gateway | Upstream 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.