API Documentation

OpenAI-compatible API. Use your existing SDK — just change the base URL.

Contents Quick Start Authentication Models & Pricing Chat Completions Error Codes Rate Limits SDK Examples

Quick Start

Base URL: https://api.tunanapi.com/v1
Compatibility: OpenAI API format — works with openai SDK, LangChain, CrewAI, etc.

Python

from openai import OpenAI

client = OpenAI(
    api_key="sk-YOUR_API_KEY",
    base_url="https://api.tunanapi.com/v1"
)

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

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

cURL

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

Node.js

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'sk-YOUR_API_KEY',
  baseURL: 'https://api.tunanapi.com/v1'
});

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

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

Authentication

Include your API key in the Authorization header:

Authorization: Bearer sk-YOUR_API_KEY

Get your API key at tunanapi.com — sign up with email and top up credits. New accounts get $0.50 free.

Models & Pricing

All prices per 1M tokens. Input = prompt tokens, Output = completion tokens.

ModelProviderInputOutputContext
deepseek-chatDeepSeek$0.20$0.40128K
deepseek-reasonerDeepSeek$2.50$5.00128K
qwen3.7-maxQwen$1.80$5.40128K
qwen3.7-plusQwen$0.58$1.74128K
qwen3.5-flashQwen$0.07$0.22128K
glm-4-plusGLM$1.80$5.40128K
glm-4-flashGLM$0.07$0.22128K
minimax-m2.5MiniMax$0.22$1.65197K
minimax-m2.7MiniMax$0.29$1.73205K
minimax-m3MiniMax$0.43$3.311M
Choosing a model? Use deepseek-chat for general tasks, deepseek-reasoner for complex reasoning, qwen3.5-flash or glm-4-flash for fast & cheap, and minimax-m3 for long-context (1M tokens).

Chat Completions

POST /v1/chat/completions

Create a chat completion. Compatible with OpenAI's chat completions API.

Parameters

ParameterTypeRequiredDescription
modelstringYesModel ID (see table above)
messagesarrayYesArray of message objects with role and content
temperaturenumberNo0-2, default 1. Higher = more random
max_tokensintegerNoMax tokens in completion
streambooleanNoStream partial results (SSE)
top_pnumberNoNucleus sampling, default 1

Streaming Example

from openai import OpenAI

client = OpenAI(
    api_key="sk-YOUR_API_KEY",
    base_url="https://api.tunanapi.com/v1"
)

stream = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "Write a haiku about coding"}],
    stream=True
)

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

Error Codes

CodeTypeDescription
400Bad RequestInvalid parameters or malformed request
401UnauthorizedInvalid or missing API key
402Insufficient QuotaNot enough credits. Top up at tunanapi.com
404Not FoundModel not available or endpoint doesn't exist
429Rate LimitedToo many requests. Slow down or contact us
500Server ErrorInternal error. Retry after a moment
503Service UnavailableUpstream provider temporarily down
Insufficient quota? Your balance is deducted per token. When credits run out, requests return 402. Top up at tunanapi.com.

Rate Limits

Default limits per API key:

LimitValue
Requests per minute60 RPM
Tokens per minute~500K TPM
Max contextDepends on model (see table above)

Need higher limits? Contact us.

SDK & Integration Examples

LangChain (Python)

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="deepseek-chat",
    api_key="sk-YOUR_API_KEY",
    base_url="https://api.tunanapi.com/v1"
)

response = llm.invoke("Explain quantum computing in one paragraph")
print(response.content)

OpenAI CLI

# Set environment variables
export OPENAI_API_KEY="sk-YOUR_API_KEY"
export OPENAI_BASE_URL="https://api.tunanapi.com/v1"

# Use the CLI
openai api chat_completions.create -m deepseek-chat -g user "Hello!"

Curl — Check Balance

# Check your remaining quota
curl https://api.tunanapi.com/api/user/self \
  -H "Authorization: Bearer sk-YOUR_API_KEY"