Skip to main content

DeepSeek

Connect AISIX AI Gateway to DeepSeek so applications can call DeepSeek V4 models through the gateway's OpenAI-compatible API. AISIX keeps the DeepSeek credential on the gateway side. It authorizes model access with caller API keys and allowlists, and applies the same rate-limit and usage-accounting controls as other model aliases.

DeepSeek exposes an OpenAI-compatible API, so it uses the openai adapter with a DeepSeek api_base.

Prerequisites

The following examples use a self-hosted AISIX gateway. Before configuring the upstream, prepare the following:

Configure the DeepSeek Upstream

Create a provider key, model alias, and caller API key for the DeepSeek-backed chat-completions route.

Create a Provider Key

Create the provider key that stores the DeepSeek credential and API root:

# Replace with your values
export AISIX_ADMIN_KEY="YOUR_ADMIN_KEY"
export DEEPSEEK_API_KEY="YOUR_PROVIDER_API_KEY"

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/provider_keys" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"display_name": "deepseek-prod",
"provider": "deepseek",
"adapter": "openai",
"secret": "${DEEPSEEK_API_KEY}",
"api_base": "https://api.deepseek.com"
}
EOF

provider is deepseek.

adapter is openai, because DeepSeek accepts OpenAI chat-completions requests.

secret stores the DeepSeek API key. It follows the credential-handling behavior in Provider Credentials.

api_base is required. For any provider other than openai, AISIX does not fall back to api.openai.com; it errors if api_base is empty. AISIX appends the endpoint path to api_base, so use the vendor root https://api.deepseek.com without a trailing /chat/completions.

Copy the returned provider key ID.

Create a Model

Create the model alias callers will send in requests:

# Replace with your values
export PROVIDER_KEY_ID="YOUR_PROVIDER_KEY_ID"

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/models" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"display_name": "deepseek-v4-flash-prod",
"provider": "deepseek",
"model_name": "deepseek-v4-flash",
"provider_key_id": "${PROVIDER_KEY_ID}"
}
EOF

display_name is the alias callers send in model.

model_name is the DeepSeek model ID, for example deepseek-v4-flash or deepseek-v4-pro.

provider_key_id attaches the alias to the DeepSeek provider key.

Create a Caller API Key

Choose the caller API key value that the application will send to AISIX, then hash it for the admin resource:

# Replace with your values
export AISIX_API_KEY="YOUR_CALLER_API_KEY"

CALLER_KEY_HASH=$(printf '%s' "${AISIX_API_KEY}" | shasum -a 256 | awk '{print $1}')

Create the caller API key resource that can access the model alias:

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/apikeys" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"key_hash": "${CALLER_KEY_HASH}",
"allowed_models": ["deepseek-v4-flash-prod"]
}
EOF

The allowed_models value must match the model alias you created.

Verify the Provider Connection

Send a chat-completions request through the AISIX proxy:

curl -sS -X POST "http://127.0.0.1:3000/v1/chat/completions" \
-H "Authorization: Bearer ${AISIX_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash-prod",
"messages": [
{
"role": "user",
"content": "Say hello from DeepSeek."
}
]
}'

The gateway returns an OpenAI-compatible response that echoes the caller-facing alias deepseek-v4-flash-prod. Confirm the request on the DeepSeek platform usage page. If the request fails, check the provider key secret, api_base, and the DeepSeek model ID in model_name.

Use Thinking Mode

DeepSeek V4 uses thinking mode by default. To disable it for a request, add the following field to the chat-completions request body:

{
"thinking": {
"type": "disabled"
}
}

AISIX forwards the thinking controls to DeepSeek and preserves returned reasoning in the reasoning_content field for streaming and non-streaming responses.

Next Steps

You have now connected AISIX to DeepSeek and verified the model alias. Continue with these guides: