Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

PowerTokens Python Examples

Python examples for building AI applications with the PowerTokens unified AI API.

Unified API for Chinese AI models — no Chinese account required. OpenAI-compatible.

Get started · Docs · Models

Examples

Example Model Path
MiniMax chat MiniMax-M3 chat/minimax_m3.py
Qwen chat qwen3-max chat/qwen3_max.py
GLM chat glm-5.2 chat/glm_5_2.py

Requirements

  • Python 3.9+
  • A PowerTokens API key
  • The OpenAI Python SDK

Install

pip install openai

Quickstart

Base URL for OpenAI-compatible SDKs: https://api.powertokens.ai/v1

export POWERTOKENS_API_KEY=your_key
python chat/minimax_m3.py
# or: python chat/qwen3_max.py
# or: python chat/glm_5_2.py
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["POWERTOKENS_API_KEY"],
    base_url="https://api.powertokens.ai/v1",
)

resp = client.chat.completions.create(
    model="MiniMax-M3",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Describe Paris in one sentence."},
    ],
    temperature=0.3,
)
print(resp.choices[0].message.content)

Create an API key in the dashboard.

FAQ (common search questions)

How do I call Qwen API without a Chinese account?

Use PowerTokens as an OpenAI-compatible gateway: set base_url to https://api.powertokens.ai/v1, use your PowerTokens API key, and pick a Qwen model id from the catalog (for example qwen3-max). You do not need a mainland China phone / Alibaba account.

What is the OpenAI-compatible base URL for GLM / MiniMax / DeepSeek?

https://api.powertokens.ai/v1

Example model ids (always confirm in the live catalog):

  • GLM: glm-5.2
  • MiniMax: MiniMax-M3
  • DeepSeek: deepseek-v3-2-251201
client = OpenAI(
    api_key=os.environ["POWERTOKENS_API_KEY"],
    base_url="https://api.powertokens.ai/v1",
)
resp = client.chat.completions.create(
    model="deepseek-v3-2-251201",
    messages=[{"role": "user", "content": "Hello"}],
)

PowerTokens vs OpenRouter for China-origin models?

Both can be OpenAI-compatible gateways. PowerTokens focuses on China-origin model families (Qwen, GLM, MiniMax, DeepSeek, Seed, video stacks) with no Chinese mainland account required and one unified key. Use the model catalog for current ids and pricing; see also awesome-chinese-model-apis for a neutral gateway comparison.

How do I call DeepSeek V3.2 with the OpenAI Python SDK?

Run pip install openai, create the client with your PowerTokens API key and base_url="https://api.powertokens.ai/v1", then pass model="deepseek-v3-2-251201" to chat.completions.create. The code is the same as chat/qwen3_max.py with only the model id changed.

Do I need a separate API key for each model?

No. One PowerTokens API key works for every model in the catalog, with no per-model binding, so switching between Qwen, GLM, MiniMax and DeepSeek V3.2 only means changing the model string (create a key).

Does PowerTokens work with Claude Code or Codex?

Yes. Besides OpenAI Chat Completions (/v1/chat/completions), PowerTokens serves the Anthropic Messages format (/v1/messages) used by Claude Code and the OpenAI Responses format (/v1/responses) used by Codex; GLM models are not available on the Responses path (protocol guide). The docs have setup guides for Claude Code, opencode, Kilo Code, Hermes Agent and OpenClaw.

How do I pay for PowerTokens?

Add Credits on the Billing page with a credit card or PayPal; no Chinese bank account or payment app is needed. See the quickstart.

Why PowerTokens

  • One API: video, image, audio, and LLM model families
  • OpenAI-compatible: reuse familiar OpenAI SDK patterns
  • No Chinese mainland account required

Useful links

Start building — powertokens.ai. New-user bonus Credits are offered only while a promotion is running; otherwise add Credits on the Billing page.

Maintained by @uselesssoso for PowerTokens.

About

Python examples for Chinese AI models (Qwen, GLM, MiniMax, DeepSeek V3.2) with the OpenAI SDK via PowerTokens' OpenAI-compatible API. No Chinese account required.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages