DEV Community

yanlong wang
yanlong wang

Posted on Originally published at aicreditsapi.com

Use DeepSeek V4 Flash & Pro With the OpenAI SDK in 5 Minutes

Use DeepSeek V4 Flash & Pro With the OpenAI SDK in 5 Minutes

Why DeepSeek V4 + OpenAI SDK Is a Match

DeepSeek V4 Flash and V4 Pro are two of the best-value coding models in 2026. Flash is the fast, cheap workhorse for everyday tasks; Pro is the deep-thinking model for complex reasoning. Both are OpenAI-compatible, which means you can use them with the openai Python SDK, the openai Node package, or any OpenAI-compatible HTTP client — usually by changing just the base_url.

Here's the shortest path from zero to a working DeepSeek V4 call.

Step 1: Get an API Key

You need a DeepSeek-compatible API key. Two options:

  • Official DeepSeek — needs a Chinese phone number and Alipay/WeChat top-up (not available to most developers outside China).
  • AiCredits — pay by credit/debit card (no Chinese phone, no PayPal), get a key in under 30 seconds, free 100K-token trial at /free-trial.

Step 2: Install the SDK

pip install openai
Enter fullscreen mode Exit fullscreen mode

Step 3: Point the SDK at DeepSeek V4

The only difference from OpenAI is the base_url. Everything else stays the same.

from openai import OpenAI

client = OpenAI(
    api_key="your-api-key",
    base_url="https://api.aicreditsapi.com/v1"
)

response = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "Write a Python function to check if a string is a palindrome."}]
)

print(response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

That's it. One base_url change and you're calling DeepSeek V4 Flash.

Step 4: Switch Between Flash and Pro

Both models share the same endpoint — just change the model string:

  • deepseek-v4-flash — fast, cheap, non-thinking mode (everyday coding, chat, batch)
  • deepseek-v4-pro — deep reasoning, better answers, higher credit consumption
# Pro for hard problems
response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Design a caching strategy for a high-traffic API."}]
)
Enter fullscreen mode Exit fullscreen mode

Use Flash for 80% of your traffic and escalate to Pro only where quality matters — it's the cheapest way to run production AI.

Step 5: Streaming (Bonus)

stream = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "Explain quantum computing simply."}],
    stream=True
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
Enter fullscreen mode Exit fullscreen mode

Node.js Version (Same Idea)

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "your-api-key",
  baseURL: "https://api.aicreditsapi.com/v1",
});

const res = await client.chat.completions.create({
  model: "deepseek-v4-flash",
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(res.choices[0].message.content);
Enter fullscreen mode Exit fullscreen mode

Common Gotchas

  1. Wrong model name — use deepseek-v4-flash / deepseek-v4-pro. The old deepseek-chat / deepseek-reasoner aliases retired on July 24, 2026.
  2. Forgetting base_url — without it, the SDK calls OpenAI and you get a 404 or auth error.
  3. Peak pricing — DeepSeek charges 2x during Beijing peak hours (9–12, 14–18). Schedule batch jobs off-peak.
  4. Don't hardcode keys — use environment variables.

You're now running DeepSeek V4 on your existing OpenAI SDK code. Total time: about 5 minutes.


Originally published on aicreditsapi.com.

Top comments (0)