DEV Community

jianjun Liu
jianjun Liu

Posted on

TokenEase: One API Key for DeepSeek, GLM, Qwen, and Doubao — With Automatic Failover

"""# TokenEase: One API Key for DeepSeek, GLM, Qwen, and Doubao — With Automatic Failover

If you're building AI-powered applications, you probably know the pain: managing separate API keys for DeepSeek, Zhipu AI, Alibaba, and ByteDance — each with different endpoints, rate limits, and failure modes. One model goes down, your app breaks, and you're scrambling to switch keys.

TokenEase solves this by providing a single API gateway that routes your requests through the fastest available provider, automatically.

The Problem with Multiple API Providers

Each LLM provider has its own quirks:

  • DeepSeek goes down for maintenance at odd hours
  • Zhipu AI (GLM) has rate limits that catch you off guard
  • Alibaba (Qwen) sometimes rotates API keys without warning
  • ByteDance (Doubao) blocks requests from certain regions

The traditional solution is writing custom failover logic:

# The old way — manual failover hell
try:
    response = call_deepseek(messages)
except (DeepSeekError, TimeoutError):
    try:
        response = call_glm(messages)
    except (GLMError, TimeoutError):
        response = call_qwen(messages)
Enter fullscreen mode Exit fullscreen mode

This works, but it's fragile, hard to maintain, and you end up with try/catch spaghetti across your codebase.

TokenEase: One Key, All Models

With TokenEase, you make a single API call and let the gateway handle the rest:

import requests

response = requests.post(
    "https://tokenease.io/v1/chat/completions",
    headers={"Authorization": f"Bearer {TOKENEASE_KEY}"},
    json={
        "model": "deepseek",  # Primary model
        "messages": [{"role": "user", "content": "Explain quantum computing"}]
    }
)
Enter fullscreen mode Exit fullscreen mode

When DeepSeek is unavailable, TokenEase automatically routes to Tencent Cloud's DeepSeek endpoint (deepseek-tc). If that's also down, it falls back to Doubao Pro. Your code never changes.

How Automatic Failover Works

Your Request → TokenEase Gateway
                        ↓
               deepseek (primary)
                        ↓
                  Available? → ✅ Return response
                        ↓ (no)
               deepseek-tc (Tencent)
                        ↓
                  Available? → ✅ Return response
                        ↓ (no)
               doubao (ByteDance)
                        ↓
                  Available? → ✅ Return response
                        ↓ (no)
                     Error + retry hint
Enter fullscreen mode Exit fullscreen mode

The response includes metadata showing which model actually handled your request:

{
  "choices": [{"message": {"content": "Quantum computing is..."}}],
  "tokenease_meta": {
    "actual_model": "deepseek-tc",
    "latency_ms": 1342.5,
    "fallback": "auto"
  }
}
Enter fullscreen mode Exit fullscreen mode

Available Models

Model Provider Context Best For Price
DeepSeek V4 Flash DeepSeek / Tencent 64K General purpose $0.5/M tokens
DeepSeek V4 Pro DeepSeek 64K Complex reasoning $8/M tokens
GLM-5.1 Zhipu AI 128K Long context $8/M tokens
Qwen-Plus Alibaba 32K Chinese content $3/M tokens
Doubao Pro 32k ByteDance 32K Creative writing $1/M tokens

OpenAI Drop-in Replacement

If you're already using OpenAI, switching to TokenEase requires one line change:

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

# After (TokenEase) — only change the base_url
from openai import OpenAI
client = OpenAI(
    api_key="YOUR_TOKENEASE_KEY",
    base_url="https://tokenease.io"  # ← Just add this
)
Enter fullscreen mode Exit fullscreen mode

LangChain works the same way:

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="deepseek",
    openai_api_key="YOUR_TOKENEASE_KEY",
    openai_api_base="https://tokenease.io/v1"
)
Enter fullscreen mode Exit fullscreen mode

No other code changes required.

Real Test Results

I tested automatic failover by simulating DeepSeek unavailability:

[TokenEase] deepseek returned 503: Service Unavailable
[TokenEase] deepseek timeout (30s), switching to next...
[TokenEase] deepseek-tc returned 200: Success (1342ms)
Enter fullscreen mode Exit fullscreen mode

Final result: Response delivered with actual_model: "deepseek-tc" and fallback: "auto" in metadata.

Comparison with Alternatives

Feature TokenEase OpenRouter Portkey
Chinese models (DeepSeek/GLM/Qwen/Doubao) ✅ Full ❌ Limited ❌ Limited
Automatic failover ✅ Free ✅ Paid
Asia-Pacific latency ✅ Optimized
CNY payment
OpenAI drop-in
Free tier ✅ 1M tokens

Quick Start

  1. Sign up at tokenease.io — free 1M tokens
  2. Get your API key from the dashboard
  3. Make your first call:
curl https://tokenease.io/v1/chat/completions \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json" \\
  -d '{"model": "deepseek", "messages": [{"role": "user", "content": "Hello!"}]}'
Enter fullscreen mode Exit fullscreen mode

Use Cases

  • AI chatbots — never go offline due to model outages
  • Content generation pipelines — reliable batch processing
  • Customer service automation — always-on AI support
  • Code review tools — leverage DeepSeek's coding capabilities
  • Translation services — multi-model redundancy

Pricing

Plan Price Tokens Best For
Starter $9.9/mo 5M tokens Personal projects
Pro $29.9/mo 20M tokens Teams, startups
Enterprise $99.9/mo 100M tokens Production scale

No hidden fees. Pay only for what you use.


Disclosure: I'm the founder of TokenEase. But I've used similar multi-provider architectures professionally for years — this is the tool I wished existed.

Questions? Drop them in the comments or reach out at support@tokenease.io
""",
"tags": ["deepseek", "openai", "api", "python", "chatgpt"],
"description": "One API key for DeepSeek, GLM, Qwen, and Doubao with automatic failover. OpenAI-compatible, Asia-Pacific optimized.",
"canonical_url": "https://tokenease.io"
}

def publish_to_devto(api_key, article_data, as_draft=True):
"""发布文章到 Dev.to"""
if not api_key:
print("❌ API Key 未设置")
print("获取方式: Settings → Account → DEV API Keys → Generate")
return None

url = "https://dev.to/api/articles"
headers = {
    "api-key": api_key,
    "Content-Type": "application/json",
    "Accept": "application/vnd.forem.api-v1+json"
}

payload = {
    "article": {
        "title": article_data["title"],
        "body_markdown": article_data["body_markdown"],
        "published": not as_draft,  # False = 草稿, True = 发布
        "tags": article_data["tags"],
        "description": article_data["description"],
        "canonical_url": article_data.get("canonical_url", ""),
    }
}

print(f"📤 正在发布到 Dev.to...")
print(f"   标题: {article_data['title']}")
print(f"   标签: {article_data['tags']}")
print(f"   模式: {'直接发布' if not as_draft else '草稿模式'}")

resp = requests.post(url, headers=headers, json=payload, timeout=30)

if resp.status_code == 201:
    data = resp.json()
    print(f"✅ 成功!")
    print(f"   文章ID: {data['id']}")
    print(f"   URL: {data['url']}")
    return data
else:
    print(f"❌ 失败 ({resp.status_code}): {resp.text}")
    return None
Enter fullscreen mode Exit fullscreen mode

if name == "main":
as_draft = "--draft" in sys.argv or "-d" in sys.argv

if not DEV_TO_API_KEY:
    print("""
Enter fullscreen mode Exit fullscreen mode

❌ Dev.to API Key 未配置

请设置环境变量:
export DEVTO_API_KEY="你的API密钥"

或直接修改脚本中的 DEV_TO_API_KEY 变量。

获取 API Key:

  1. 登录 dev.to
  2. 进入 Settings → Account
  3. 滚动到 "DEV Community API Keys"
  4. 点击 "Generate API Key"
  5. 复制密钥并填入上方

Top comments (0)