DeepSeek's API is widely used for customer support, writing, coding, and data analysis because of its low price and strong Chinese-language capability. This article from ZSQH AI Gateway explains how to get a key, how to top up, how to call the API with the OpenAI SDK, and what to do when you hit rate limits.

This article uses the OpenAI-compatible interface as an example. DeepSeek's official interface is also compatible with the OpenAI SDK, but the Base URL and model names differ. Do not mix them.

1. What the DeepSeek API can do

Common uses:

  • Chinese Q&A and customer support bots.
  • Long-document summarization, translation, and rewriting.
  • Code generation and code explanation.
  • Data analysis and structured extraction.
  • Reasoning nodes in agents and workflows.

Common DeepSeek models include deepseek-chat and deepseek-reasoner. For the specific available model names, context lengths, and prices, refer to the model pricing page.

2. Registration and key creation

  1. Open the ZSQH AI Gateway, register, and sign in.
  2. Go to the "API Keys" page and click Create.
  3. Name it deepseek-test or deepseek-prod.
  4. Set a spending limit and expiration time.
  5. Copy the key and store it somewhere safe.

We recommend separate keys for testing and production. Do not put production keys in front-end code.

3. Top-up

Top up on the "Wallet" page. Once the payment is credited, the console shows the balance.

If this is your first time, start with a small amount and adjust based on actual usage after the integration works. DeepSeek's prices are relatively low, but long contexts and batch jobs can still consume the balance quickly.

4. Base URL and model names

ZSQH's OpenAI-compatible endpoint:

https://ai.zhongshangqihang.com/v1

Example model names:

deepseek-chat
deepseek-reasoner

Notes:

  • Model names are subject to the pricing page; do not copy old model names straight from official documentation.
  • If you use the official DeepSeek interface, the Base URL is https://api.deepseek.com; with the gateway, use the address above.
  • Do not mix the two Base URLs, or you will get 401/404 errors.

5. Calling from Python

pip install openai
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["DEEPSEEK_API_KEY"],
    base_url="https://ai.zhongshangqihang.com/v1",
)

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "system", "content": "You are a concise technical assistant."},
        {"role": "user", "content": "Explain what a vector database is in three sentences"},
    ],
)

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

If you need the reasoning process, switch to deepseek-reasoner. Note that reasoning models are usually slower and more expensive; they suit hard problems, not every request.

6. Calling with curl

export DEEPSEEK_API_KEY="sk-your-key"

curl "https://ai.zhongshangqihang.com/v1/chat/completions" \
  -H "Authorization: Bearer $DEEPSEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "messages": [
      {"role": "user", "content": "Write a Python example that reads a CSV file"}
    ]
  }'

7. Rate limits and stability

DeepSeek may rate-limit or slow down during peak hours. In practice:

  1. Set timeouts and retries: do not wait indefinitely; use exponential backoff for 429/5xx.
  2. Control concurrency: do not max out batch jobs all at once.
  3. Prepare a backup model: critical workloads can be configured with a backup model or channel.
  4. Monitor error rates: count 401/429/5xx hourly and switch channels when they spike.
  5. Split long text: very long contexts are slow and expensive; summarize or chunk first.

8. Common errors

Error Cause What to do
401 Wrong key or missing Bearer Check the key and request headers
404 Wrong Base URL Use the gateway address ending in /v1
model not found Wrong model name Copy it from the pricing page
429 Rate limited Reduce concurrency, retry, switch to the backup channel
insufficient quota Insufficient balance Top up
Very slow response Peak hours or long context Shorten the context, switch models, retry

9. DeepSeek official vs. gateway

Item Official direct ZSQH Gateway
Access Depends on the network environment Unified entry point, usually more stable
Payment Payment methods supported by the official site Top-up on site
Models DeepSeek only Claude, GPT, Gemini, and others
Billing Official dashboard Unified console
Switching Changing providers requires code changes Change the model name

If you only use DeepSeek, your usage is stable, and official access works fine, direct access is an option. If you need multiple models, unified billing, or stable access from China, a gateway is a better fit.

10. Security recommendations

  • Do not put keys in front-end code or public repositories.
  • Create separate keys for testing and production.
  • Set spending limits to prevent abnormal calls.
  • Review usage logs regularly and disable keys promptly if something looks wrong.
  • Delete old keys when employees leave or machines are replaced.

FAQ

Is the DeepSeek API free?

There are usually new-user credits or promotions, but long-term use requires a top-up. Refer to the official and on-site policies for specifics.

Can one key call Claude?

On the ZSQH Gateway, one key can call multiple enabled models; specify the model in the request parameters. See the pricing page for details.

Why is the same model sometimes fast and sometimes slow?

It can be affected by upstream load, context length, concurrency, and network conditions. For production, add timeouts, retries, and a backup model.

Next steps

First register for the ZSQH AI Gateway, create a deepseek test key, verify it with curl, and then connect your application. Prices and model names are subject to model pricing.

Related reading: