DEV Community

Jinze Wang
Jinze Wang

Posted on

Use DeepSeek with the OpenAI Python SDK by Changing One URL

If your application already uses the OpenAI Python SDK, testing another model does not have to mean rewriting the integration. An OpenAI-compatible endpoint lets you keep the familiar client, messages format, and response handling.

This tutorial shows a minimal DeepSeek request through JinzeAI's public beta endpoint.

1. Install the SDK

python -m pip install openai
Enter fullscreen mode Exit fullscreen mode

2. Store the API key safely

Do not hard-code an API key or commit it to Git.

On macOS or Linux:

export JINZEAI_API_KEY="your_api_key_here"
Enter fullscreen mode Exit fullscreen mode

On PowerShell:

$env:JINZEAI_API_KEY="your_api_key_here"
Enter fullscreen mode Exit fullscreen mode

3. Create the client

import os

from openai import OpenAI

client = OpenAI(
    base_url="https://jinzeai.cc/v1",
    api_key=os.environ["JINZEAI_API_KEY"],
)
Enter fullscreen mode Exit fullscreen mode

The important change is base_url. The rest of the SDK remains familiar.

4. Send a request

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {
            "role": "user",
            "content": "Explain API gateways in one sentence.",
        }
    ],
)

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

Common errors

HTTP 401

Confirm that the API key is active and that your client sends it as a bearer token. If a key was ever exposed publicly, rotate it instead of continuing to use it.

HTTP 404

Confirm that the base URL is exactly:

https://jinzeai.cc/v1
Enter fullscreen mode Exit fullscreen mode

Chat requests must use POST /chat/completions.

Slow first test

Start with a short prompt and a new conversation. Large message histories can add substantial input tokens and latency.

Try the public beta

JinzeAI is inviting early beta testers outside mainland China. The beta may include a limited free test credit, and no payment is required to test it.

Model availability and usage limits may change during beta. I would especially value feedback about setup clarity, latency, and SDK compatibility.

Top comments (0)