API Reference

The AI Token API is fully compatible with the OpenAI API specification. Use your existing OpenAI SDK code with just two configuration changes.

Authentication

All API requests require authentication via a Bearer token in the Authorization header.

bash
Authorization: Bearer YOUR_API_KEY
⚠️ Keep your API key secure
Never expose your API key in client-side code or public repositories. Use environment variables.

Base URL

All API endpoints are relative to this base URL:

url
https://bb71d3f3506709ed-101-126-19-34.serveousercontent.com/v1

Request Format

All requests must include:

  • Content-Type: application/json header
  • Authorization: Bearer YOUR_API_KEY header
  • JSON body with required parameters

Streaming

Set "stream": true in your request body to receive responses as Server-Sent Events (SSE). Each chunk contains a partial response in the same format as the non-streaming response.

python
stream = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    messages=[{"role": "user", "content": "Write a poem"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

Chat Completions

POST /v1/chat/completions

Creates a model response for the given chat conversation. This is the primary endpoint for most use cases.

Request Parameters

ParameterTypeRequiredDescription
model string Required Model ID to use. See model list for all available models.
messages array Required A list of messages comprising the conversation. Each message has role (system/user/assistant) and content.
temperature number Optional Sampling temperature (0-2). Higher = more random. Default: 1.0
max_tokens integer Optional Maximum number of tokens to generate. Default: model-specific.
top_p number Optional Nucleus sampling parameter (0-1). Alternative to temperature. Default: 1.0
stream boolean Optional If true, stream response as Server-Sent Events. Default: false
stop string/array Optional Stop sequences. Generation stops when these are encountered.
frequency_penalty number Optional Penalize tokens based on frequency (-2 to 2). Default: 0
presence_penalty number Optional Penalize tokens based on presence (-2 to 2). Default: 0

Request Example

json
{
  "model": "deepseek-ai/DeepSeek-V4-Pro",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is the capital of France?"}
  ],
  "temperature": 0.7,
  "max_tokens": 500
}

Response Example

json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1699000000,
  "model": "deepseek-ai/DeepSeek-V4-Pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 8,
    "total_tokens": 32
  }
}

Completions (Legacy)

POST /v1/completions

Legacy text completion endpoint. For new applications, we recommend using Chat Completions instead.

Request Parameters

ParameterTypeRequiredDescription
modelstringRequiredModel ID
promptstring/arrayRequiredThe prompt(s) to generate completions for
max_tokensintegerOptionalMaximum tokens to generate. Default: 16
temperaturenumberOptionalSampling temperature (0-2). Default: 1.0

Request Example

bash
curl https://bb71d3f3506709ed-101-126-19-34.serveousercontent.com/v1/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-ai/DeepSeek-V3",
    "prompt": "Write a tagline for an AI startup:",
    "max_tokens": 50
  }'

Embeddings

POST /v1/embeddings

Creates embedding vectors for the given input text. Useful for semantic search, RAG pipelines, clustering, and classification.

Request Parameters

ParameterTypeRequiredDescription
modelstringRequiredEmbedding model ID (e.g., Qwen/Qwen3-Embedding-8B)
inputstring/arrayRequiredInput text to embed. Can be a string or array of strings.
encoding_formatstringOptionalFormat: float or base64. Default: float

Request Example

python
response = client.embeddings.create(
    model="Qwen/Qwen3-Embedding-8B",
    input="The quick brown fox jumps over the lazy dog"
)

print(response.data[0].embedding[:5])  # First 5 dimensions

Response

json
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [0.0023, -0.0094, 0.0159, ...]
    }
  ],
  "model": "Qwen/Qwen3-Embedding-8B",
  "usage": {
    "prompt_tokens": 10,
    "total_tokens": 10
  }
}

List Models

GET /v1/models

Returns a list of all available models.

bash
curl https://bb71d3f3506709ed-101-126-19-34.serveousercontent.com/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

json
{
  "object": "list",
  "data": [
    {
      "id": "deepseek-ai/DeepSeek-V4-Pro",
      "object": "model",
      "created": 1699000000,
      "owned_by": "deepseek"
    },
    ...
  ]
}

Error Codes

The API uses standard HTTP status codes. Error responses include a JSON body with details.

CodeMeaningDescription
200SuccessRequest completed successfully.
400Bad RequestInvalid request body or parameters.
401UnauthorizedInvalid or missing API key.
403ForbiddenAPI key does not have permission for this model.
404Not FoundModel not found or endpoint doesn't exist.
429Rate LimitedToo many requests. Wait and retry.
500Server ErrorInternal error. Retry with exponential backoff.
502Bad GatewayUpstream model provider error. Try another model.
503UnavailableModel temporarily unavailable. Retry later.

Error Response Format

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

Rate Limits

Rate limits vary by plan and model:

PlanRequests/minTokens/min
Starter (Free)2040,000
Pro60200,000
Business2001,000,000
EnterpriseCustomCustom
💡 Rate limit headers
Every response includes X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers.

Response Format

All responses follow the OpenAI response format, ensuring compatibility with existing integrations.

Usage Object

Every response includes a usage object with token counts:

json
"usage": {
  "prompt_tokens": 24,
  "completion_tokens": 150,
  "total_tokens": 174
}

🎁 Get ¥20 Free Credit

Use code DEVSTARTER20 when signing up to get started for free.

Sign Up Free →