Skip to main content

Version: latest

Route Traffic to DeepSeek Models

DeepSeek provides high-performance language models at competitive pricing through an OpenAI-compatible API. API7 Gateway includes a dedicated DeepSeek driver, so you do not need to use the generic openai-compatible provider. This guide shows how to route traffic to DeepSeek through API7 Gateway using the ai-proxy plugin.

Prerequisites

  • Install Docker.

  • Install cURL to send requests to the services for validation.

  • Have a running API7 Enterprise Gateway instance.

  • Obtain the Admin API key. Save it to an environment variable:

    export ADMIN_API_KEY=your-admin-api-key   # replace with your API key
  • Obtain the ID of the service you want to configure. Save it to an environment variable:

    export SERVICE_ID=your-service-id         # replace with your service ID

Obtain a DeepSeek API Key

Create an account at platform.deepseek.com and generate an API key. Save the key to an environment variable:

export DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx   # replace with your API key

Configure the AI Proxy for DeepSeek

Create a route with the ai-proxy plugin:

curl "http://127.0.0.1:7080/apisix/admin/routes?gateway_group_id=default" -X PUT \
-H "X-API-KEY: $ADMIN_API_KEY" \
-d '{
"id": "deepseek-route",
"service_id": "$SERVICE_ID",
"paths": ["/deepseek"],
"plugins": {
"ai-proxy": {
"provider": "deepseek",
"auth": {
"header": {
"Authorization": "Bearer '"$DEEPSEEK_API_KEY"'"
}
},
"options": {
"model": "deepseek-chat"
}
}
}
}'

❶ Set the provider to deepseek. This uses the dedicated DeepSeek driver.

❷ Attach the DeepSeek API key in the Authorization header.

❸ Set the model to deepseek-chat. Other available models include deepseek-reasoner.

Multi-Model Routing with DeepSeek

DeepSeek models offer significantly lower per-token pricing than many alternatives. Use ai-proxy-multi to route most traffic to DeepSeek while keeping a premium provider as fallback:

curl "http://127.0.0.1:7080/apisix/admin/routes?gateway_group_id=default" -X PUT \
-H "X-API-KEY: $ADMIN_API_KEY" \
-d '{
"id": "deepseek-multi-route",
"service_id": "$SERVICE_ID",
"paths": ["/deepseek"],
"plugins": {
"ai-proxy-multi": {
"fallback_strategy": ["http_429", "http_5xx"],
"instances": [
{
"name": "deepseek-primary",
"provider": "deepseek",
"auth": { "header": { "Authorization": "Bearer '"$DEEPSEEK_API_KEY"'" } },
"options": { "model": "deepseek-chat" },
"weight": 1,
"priority": 1
},
{
"name": "openai-fallback",
"provider": "openai",
"auth": { "header": { "Authorization": "Bearer '"$OPENAI_API_KEY"'" } },
"options": { "model": "gpt-4o-mini" },
"weight": 1,
"priority": 2
}
]
}
}
}'

fallback_strategy enables automatic failover on HTTP 429 (rate limited) or 5xx (server error).

❷ Set DeepSeek as the primary instance with highest priority.

❸ Set OpenAI as the fallback with lower priority. Traffic routes here only when DeepSeek is unavailable.

For more routing strategies, see Multi-LLM Routing and Fallback.

Validate the Configuration

Send a chat completion request:

curl "http://127.0.0.1:9080/deepseek" -X POST \
-H "Content-Type: application/json" \
-d '{
"messages": [
{ "role": "user", "content": "What is the Fibonacci sequence?" }
]
}'

You should receive a response similar to the following:

{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, typically starting with 0 and 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, ..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 48,
"total_tokens": 58
}
}

To enable streaming responses, set "stream": true in the request body. Use the proxy-buffering plugin to disable NGINX proxy_buffering to avoid server-sent events (SSE) being buffered.

Next Steps

You have learned how to route traffic to DeepSeek through API7 Gateway. See the DeepSeek API documentation for more details about available models.

API7.ai Logo

The digital world is connected by APIs,
API7.ai exists to make APIs more efficient, reliable, and secure.

Sign up for API7 newsletter

Product

API7 Gateway

SOC2 Type IIISO 27001HIPAAGDPRRed Herring

Copyright © APISEVEN PTE. LTD 2019 – 2026. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the Apache Software Foundation