Deploy DeepSeek-V4 and DeepSeek-R1
Deploying DeepSeek models requires configuring the compute environment, loading the model, and optimizing inference. PAI Model Gallery supports one-click deployment. You can obtain a model service compatible with the OpenAI API in just a few steps and quickly integrate it into your applications.
Solution architecture
Core components
The solution is built on the PAI platform and consists of the following core components:
Model Gallery: the entry point for model distribution and deployment, providing preset DeepSeek models and deployment configurations.
Elastic Algorithm Service (EAS): the core service that hosts model deployment and inference. It automatically manages underlying compute resources, such as GPUs, and launches model service instances.
-
Inference acceleration engines (SGLang/vLLM/BladeLLM): optimize model inference performance.
SGLang/vLLM: provides interfaces that are fully compatible with the OpenAI API for migrating existing applications.
BladeLLM: an in-house high-performance inference framework that delivers better performance in specific scenarios.
API gateway: provides a secure channel for accessing model services. You can call the services by using the service endpoint and token.
Deployment method
For large-scale models, in addition to single-node deployment, Model Gallery also offers one-click deployment solutions such as distributed deployment and EP+PD separation.
For example, DeepSeek-V4-Pro-FP8 and DeepSeek-V4-Flash-FP8 can both be deployed by using the EP+PD separation method.
Quick deployment and validation
Step 1: Deploy the model service
Log on to the PAI console and select the target region in the upper-left corner. From the left-side navigation pane, go to Workspaces and select the target workspace.
In the workspace, navigate to QuickStart > Model Gallery.
Search for and select the target model in the model list, such as
DeepSeek-R1-Distill-Qwen-7B, and click the model card to go to the details page.-
Click Deploy in the upper-right corner of the page and configure the following parameters.
Deployment Template: By default, the card type is A10, the inference engine is SGLang, the deployment method is single-node, and the deployment scenario is balanced.
-
Deployment Resource: Select public resources or dedicated resources, and select an appropriate GPU specification based on the model requirements.
-
By default, public resources are used and a recommended specification is provided. If no specifications are available, try switching to another region.
ImportantWhen you deploy by using public resources, billing starts as soon as the instance is provisioned, and charges are based on the usage duration, even if there are no calls. Stop the service promptly after testing.
If you select Resource Quota, make sure to choose a matching inference engine and deployment template based on the instance type. For example, if you use Zhenwu PPU, you can select SGLang as the inference engine and PPU-810E as the card type in the deployment template.
An example of a recommended GPU specification is
ecs.gn7i-c16g1.4xlarge(16 vCPUs, 60 GiB, 1 × NVIDIA A10), which costs approximately CNY 11.1 per hour. -
-
After you confirm that all configurations are correct, click Deploy. The system begins to create the service.
NoteFor a large model, such as the full-version DeepSeek-R1, the model loading process might take 20 to 30 minutes.
-
You can view the status of the deployment job on the Model Gallery > Job Management > Deployment Jobs page. Click a service name to go to the service details page. You can also click in the upper-right corner to go to the model service details page in PAI-EAS for more information.
On the service details page, you can click View Deployment Events next to the Status field for more details, and click View Call Information in the Call Information field to obtain the service endpoint and token. You can also choose Elastic Algorithm Service (EAS) from the left-side navigation pane to go to the EAS service management page.
Step 2: Online debugging
On the Model Gallery > Job Management > Deployment Jobs page, click the name of the deployed service and switch to the Online Debugging tab, which supports both Conversation Debugging and API Debugging.
The official usage recommendations for the DeepSeek-R1 model series are as follows:
Set the temperature to a value between 0.5 and 0.7. The recommended value is 0.6 to prevent repetitive or incoherent output.
Do not add a system prompt. Put all instructions in the user prompt.
For math-related questions, include "Please reason step by step and put the final answer in a \boxed{}." in the prompt.
If only the API debugging page is available, the following example shows how to debug the chat API of a large language model (LLM) service:
-
Set the request method and path: On the debugging tab, select
POSTas the HTTP method and append/v1/chat/completionsto the address to form the complete request URL<EAS_ENDPOINT>/v1/chat/completions. In the URL,<EAS_ENDPOINT>is the service endpoint, which is usually pre-populated. The standard format ishttp://<uid>.<region-id>.pai-eas.aliyuncs.com/api/predict/<service-name>.For services deployed with SGLang/vLLM, you can find more supported APIs at
<EAS_ENDPOINT>/openapi.json. -
Construct the request body.
If the prompt is "What is 3 + 5?", the request body is formatted as follows.
The value of the model parameter is the model name obtained from the model list API
<EAS_ENDPOINT>/v1/models. This example uses DeepSeek-R1-Distill-Qwen-7B.In the Body section, select raw and enter the following JSON request body:
{ "model": "DeepSeek-R1-Distill-Qwen-7B", "messages": [ { "role": "user", "content": "What is 3 + 5?" } ] } -
Send the request.
Click Send Request. The Response section on the right shows the status code 200, and the Body section displays the model response in JSON format.
API call
-
Obtain the service endpoint and token.
On the Model Gallery > Job Management > Deployment Jobs page, click the name of the deployed service to go to the service details page.
Click View Call Information to obtain the endpoint and token used to call the service.
-
The following is an example of calling the chat API.
Replace <EAS_ENDPOINT> with the service endpoint and <EAS_TOKEN> with the service token.
OpenAI SDK
Notes:
You must append /v1 to the endpoint.
BladeLLM accelerated deployment does not currently support using client.models.list() to obtain the model list. You can set the value of model to "" for compatibility.
SGLang/vLLM accelerated deployment
from openai import OpenAI # 1. Configure the client # Replace <<EAS_ENDPOINT> and <EAS_TOKEN> with the actual service access address and Token. openai_api_key = "<EAS_TOKEN>" openai_api_base = "<EAS_ENDPOINT>/v1" client = OpenAI( api_key=openai_api_key, base_url=openai_api_base, ) # 2. Get the model name try: model = client.models.list().data[0].id print(model) except Exception as e: print(f"Failed to get the model list. Check the Endpoint and Token. Error: {e}") # 3. Construct and send the request stream = True chat_completion = client.chat.completions.create( messages=[ {"role": "user", "content": "Hello, please introduce yourself."} ], model=model, max_tokens=2048, stream=stream, ) if stream: for chunk in chat_completion: print(chunk.choices[0].delta.content, end="") else: result = chat_completion.choices[0].message.content print(result)BladeLLM accelerated deployment
from openai import OpenAI ##### API Configuration ##### # Replace <EAS_ENDPOINT> with the access address of the deployed service, and <EAS_TOKEN> with the Token of the deployed service. openai_api_key = "<EAS_TOKEN>" openai_api_base = "<EAS_ENDPOINT>/v1" client = OpenAI( api_key=openai_api_key, base_url=openai_api_base, ) # BladeLLM accelerated deployment currently does not support retrieving the model name via client.models.list(). You can directly set the value of model to "" for compatibility. model="" stream = True chat_completion = client.chat.completions.create( messages=[ {"role": "user", "content": "Hello, please introduce yourself."} ], model=model, max_tokens=2048, stream=stream, ) if stream: for chunk in chat_completion: print(chunk.choices[0].delta.content, end="") else: result = chat_completion.choices[0].message.content print(result)HTTP
SGLang/vLLM accelerated deployment
Replace <model_name> with the model name obtained from the model list API
<EAS_ENDPOINT>/v1/models.curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: <EAS_TOKEN>" \ -d '{ "model": "<model_name>", "messages": [ { "role": "user", "content": "hello!" } ] }' \ <EAS_ENDPOINT>/v1/chat/completionsimport json import requests # Replace <EAS_ENDPOINT> with the access address of the deployed service, and <EAS_TOKEN> with the Token of the deployed service. EAS_ENDPOINT = "<EAS_ENDPOINT>" EAS_TOKEN = "<EAS_TOKEN>" url = f"{EAS_ENDPOINT}/v1/chat/completions" headers = { "Content-Type": "application/json", "Authorization": EAS_TOKEN, } # Replace <model_name> with the model name obtained from the model list API <EAS_ENDPOINT>/v1/models. model = "<model_name>" stream = True messages = [ {"role": "user", "content": "Hello, please introduce yourself."}, ] req = { "messages": messages, "stream": stream, "temperature": 0.6, "top_p": 0.5, "top_k": 10, "max_tokens": 300, "model": model, } response = requests.post( url, json=req, headers=headers, stream=stream, ) if stream: for chunk in response.iter_lines(chunk_size=8192, decode_unicode=False): msg = chunk.decode("utf-8") if msg.startswith("data"): info = msg[6:] if info == "[DONE]": break else: resp = json.loads(info) print(resp["choices"][0]["delta"]["content"], end="", flush=True) else: resp = json.loads(response.text) print(resp["choices"][0]["message"]["content"])BladeLLM accelerated deployment
curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: <EAS_TOKEN>" \ -d '{ "messages": [ { "role": "user", "content": "hello!" } ] }' \ <EAS_ENDPOINT>/v1/chat/completionsimport json import requests # Replace <EAS_ENDPOINT> with the access address of the deployed service, and <EAS_TOKEN> with the Token of the deployed service. EAS_ENDPOINT = "<EAS_ENDPOINT>" EAS_TOKEN = "<EAS_TOKEN>" url = f"{EAS_ENDPOINT}/v1/chat/completions" headers = { "Content-Type": "application/json", "Authorization": EAS_TOKEN, } stream = True messages = [ {"role": "user", "content": "Hello, please introduce yourself."}, ] # With BladeLLM accelerated deployment, if the max_tokens parameter is not specified, the output is truncated at max_tokens=16 by default. We recommend that you adjust the max_tokens request parameter based on your actual needs. req = { "messages": messages, "stream": stream, "temperature": 0.6, "top_p": 0.5, "top_k": 10, "max_tokens": 300, } response = requests.post( url, json=req, headers=headers, stream=stream, ) if stream: for chunk in response.iter_lines(chunk_size=8192, decode_unicode=False): msg = chunk.decode("utf-8") if msg.startswith("data"): info = msg[6:] if info == "[DONE]": break else: resp = json.loads(info) if resp["choices"][0]["delta"].get("content") is not None: print(resp["choices"][0]["delta"]["content"], end="", flush=True) else: resp = json.loads(response.text) print(resp["choices"][0]["message"]["content"]) -
The calling method varies depending on the model and deployment framework. For more information, see the model introduction page in Model Gallery.
For example, the model introduction page for DeepSeek-R1-Distill-Qwen-7B in Model Gallery specifies the resource requirements for BladeLLM accelerated deployment (24 GB of GPU memory is required, and only ecs.gn7 and later instance families are supported), states that the model is compatible with the OpenAI
v1/completionsandv1/chat/completionsAPIs, and provides call examples using curl commands and Python scripts.
Third-party integration
To connect to Chatbox, Dify, or Cherry Studio, see Integrate third-party clients.
Local Web UI
See Build a local web UI.
Resource cleanup
When you deploy by using public resources, billing starts as soon as the instance is provisioned and is based on the duration of usage, with partial hours prorated by the minute. Stop or delete the instance promptly after you finish using it.
Go back to the Task Management > Deployment Tasks page.
-
Find the service that you want to stop and click Stop or Delete in the Actions column.
Stop: The service instance is released and billing stops, but the service configuration is retained and the service can be started again later.
Delete: Both the service configuration and the instance are permanently deleted.
Model and resource selection
The model you select determines the required compute resources and deployment costs. DeepSeek models are divided into full-version models and distilled version models, which differ significantly in resource requirements.
Development and testing: We recommend that you use a distilled version model, such as
DeepSeek-R1-Distill-Qwen-7B. These models have low resource requirements (typically a single GPU with 24 GB of GPU memory), can be deployed quickly at a low cost, and are suitable for rapid feature validation.Production environments: Evaluate both model performance and cost.
DeepSeek-R1-Distill-Qwen-32Bstrikes a good balance between performance and cost. If you need stronger model performance, you can choose a full-version model, but full-version models require multiple high-end GPUs (such as 8 GPUs with 96 GB of GPU memory each) and significantly increase costs.
The following table lists the minimum configurations required for different model versions and the maximum number of tokens supported when different instance types and inference engines are used.
Full-version models
|
Model |
Deployment method |
Maximum number of tokens (input + output) |
Minimum configuration |
|
|
SGLang (recommended) |
vLLM |
|||
|
DeepSeek-V4-Pro |
Single-node/Distributed |
1M |
1M |
Single-node with 8 × H20-3e (8 × 141 GB of GPU memory) |
|
DeepSeek-V4-Flash |
Single-node |
1M |
1M |
Single-node with 8 × H20-3e (8 × 141 GB of GPU memory) |
|
DeepSeek-V4-Pro-FP8 |
Single-node/PD separation |
1M |
/ |
Single-node with 8 × H20-3e (8 × 141 GB of GPU memory) |
|
DeepSeek-V4-Flash-FP8 |
Single-node/PD separation |
1M |
/ |
Single-node with 4 × H20-3e (4 × 141 GB of GPU memory) |
|
DeepSeek-V3 |
Single-node - NVIDIA GPU |
56,000 |
65,536 |
Single-node 8 × GU120 (8 × 96 GB of GPU memory) |
|
Single-node - Zhenwu PPU |
56,000 |
16,384 |
||
|
Distributed - PAI Lingjun Intelligent Computing Service |
163,840 |
163,840 |
||
|
DeepSeek-R1 |
Single-node - NVIDIA GPU |
56,000 |
65,536 |
Single-node 8 × GU120 (8 × 96 GB of GPU memory) |
|
Single-node - Zhenwu PPU |
56,000 |
16,384 |
||
|
Distributed - PAI Lingjun Intelligent Computing Service |
163,840 |
163,840 |
||
Single-node deployment instance type notes:
-
NVIDIA GPU:
ml.gu8v.c192m1024.8-gu120andecs.gn8v-8x.48xlarge: available as public resources, but their inventory might be limited.ecs.ebmgn8v.48xlarge: cannot be used as a public resource. You must purchase dedicated EAS resources.
Zhenwu PPU:
ml.gp7vf.16.40xlargeis a public resource and can be used only on a preemptible basis. If NVIDIA GPU resources are scarce, you can switch to the China (Ulanqab) region to find Zhenwu PPU resources. You must configure a VPC when you deploy.
Distributed deployment instance type notes (recommended when high performance is required):
Distributed deployment relies on high-speed networking. Therefore, you must use PAI Lingjun Intelligent Computing Service, which provides high-performance, elastic heterogeneous computing power, and configure a VPC during deployment. To use PAI Lingjun Intelligent Computing Service, switch the region to China (Ulanqab).
-
Lingjun public resources:
ml.gu7xf.8xlarge-gu108: requires four machines for a single-instance deployment and can be used only on a preemptible basis.Zhenwu PPU: requires two machines for a single-instance deployment.
Lingjun prepaid resources: You must be added to a whitelist to use these resources. Contact your sales manager or submit a ticket for consultation.
Distilled version models
|
Model |
Maximum number of tokens (input + output) |
Minimum configuration |
||
|
SGLang (recommended) |
vLLM |
BladeLLM |
||
|
DeepSeek-R1-Distill-Qwen-1.5B |
131,072 |
131,072 |
131,072 |
1 × A10 GPU (24 GB of GPU memory) |
|
DeepSeek-R1-Distill-Qwen-7B |
131,072 |
32,768 |
131,072 |
1 × A10 GPU (24 GB of GPU memory) |
|
DeepSeek-R1-Distill-Llama-8B |
131,072 |
32,768 |
131,072 |
1 × A10 GPU (24 GB of GPU memory) |
|
DeepSeek-R1-Distill-Qwen-14B |
131,072 |
32,768 |
131,072 |
1 × GPU L (48 GB of GPU memory) |
|
DeepSeek-R1-Distill-Qwen-32B |
131,072 |
32,768 |
131,072 |
2 × GPU L (2 × 48 GB of GPU memory) |
|
DeepSeek-R1-Distill-Llama-70B |
131,072 |
32,768 |
131,072 |
2 × GU120 (2 × 96 GB of GPU memory) |
DeepSeek-R1-0528-Qwen3-8B: a model distilled from DeepSeek-R1 into Qwen3-8B with 8 billion parameters. It supports only deployment and does not support fine-tuning or training.
PAI-optimized models
Model Gallery provides one-click deployment of the following PAI-optimized DeepSeek models:
DeepSeek-R1-PAI-optimized
DeepSeek-R1-0528-PAI-optimized
DeepSeek-V3-0324-PAI-optimized
Costs and risks
Cost breakdown
For services that use public resources, billing is calculated by the minute, starting from when an instance is provisioned until it is stopped or deleted. Bills are settled hourly. Charges accrue even when the service is idle. Stopping the service halts billing.
For more information, see Elastic Algorithm Service (EAS) billing.
Cost control
Clean up promptly: After development and testing, immediately stop or delete the service to control costs.
Use trial resources: If you are using EAS for the first time, go to Alibaba Cloud Free Tier to claim PAI-EAS trial resources. After you claim the resources, you can choose to deploy a model with a minimum configuration of A10, such as DeepSeek-R1-Distill-Qwen-7B, and change the resource specification to an instance type provided in the trial during deployment.
Select an appropriate model: In non-production environments, prioritize lower-cost distilled version models.
Use preemptible resources: For non-production tasks, you can enable the preemptible mode during deployment. Note that certain conditions must be met for a successful bid, and there is a risk of resource instability.
Long-term usage discounts: For long-running production services, you can reduce costs by purchasing a savings plan or prepaid resources.
Key risks
Unexpected costs: Forgetting to stop the service results in continuous billing. Always clean up resources immediately after use.
BladeLLM output truncation: When you use the BladeLLM engine, if
max_tokensis not specified in the API request, the output is truncated to 16 tokens, which might cause the feature to not work as expected.-
Incorrect API usage:
When you call a DeepSeek-R1 series model, including a
systemprompt inmessagesmight cause unexpected behavior.The API request URL must end with a path such as
/v1/chat/completions. Otherwise, a 404 error is returned.
Resource inventory: When you deploy large models (especially full-version models), the inventory of high-end GPU resources in specific regions might be tight, causing deployment failures or long waiting times. You can try switching to another region.
Model deployment FAQ
Choosing an inference engine
Recommended SGLang: It delivers high performance, is fully compatible with the OpenAI API standard, adapts to mainstream application ecosystems, and supports a longer maximum context length than vLLM in most scenarios.
Alternative vLLM: As a popular framework in the industry, it also provides good API compatibility.
For specific scenarios BladeLLM: Choose BladeLLM, the high-performance inference framework independently developed by Alibaba Cloud PAI, only if you require higher inference performance and can accept differences between its APIs and the OpenAI standard (for example,
client.models.list()is not supported, and themax_tokensparameter has default truncation behavior).
Service stuck waiting
Possible causes:
Insufficient machine resources in the current region.
Model loading takes a long time due to the large model size (20 to 30 minutes for models such as DeepSeek-R1 and DeepSeek-V3).
Wait patiently for a while. If the service still fails to start as expected, we recommend that you try the following steps:
-
Go to Job Management-Deployment Jobs to open the deployment job details page. Click in the upper-right corner of the page to go to the model service details page in PAI-EAS and view the service instance status.
If the Instance Status column shows Insufficient Inventory, the instance cannot be scheduled because of insufficient resources.
-
Stop the current service, switch to another region in the upper-left corner of the console, and deploy the service again.
NoteModels with an extremely large number of parameters, such as DeepSeek-R1 and DeepSeek-V3, require 8 GPUs to start the service (resource inventory is tight). You can choose to deploy smaller distilled models such as DeepSeek-R1-Distill-Qwen-7B (resource inventory is abundant).
Model call FAQ
API call returns 404
Check whether an OpenAI API suffix, such as v1/chat/completions, has been added to the URL. For more information, see the API call instructions on the model introduction page.
If you use a vLLM accelerated deployment, check that the model parameter in the request body of the chat API is set to the correct model name. You can obtain the model name from v1/models.
Request timeout
The default gateway request timeout for deployments is 180 seconds. To extend it, you can configure a dedicated gateway and submit a ticket to adjust the request timeout of the dedicated gateway. The timeout can be extended up to 600 seconds.
No "web search" feature
The "web search" feature is not enabled by deploying the model service alone; it requires building a separate AI application (agent) on top of the service.
You can use LangStudio, the LLM application development platform of PAI, to build a web search AI application. For more information, see Build a DeepSeek Web Search Application with LangStudio.
Model skips thinking
If the DeepSeek-R1 model sometimes skips the thinking process, use the updated chat template from DeepSeek that forces thinking:
-
Modify the startup command.
In the service configuration, edit the JSON configuration and modify the containers-script field to add "--chat-template /model_dir/template_force_thinking.jinja" (you can add it after "--served-model-name DeepSeek-R1").
For an already deployed service, go to Model Gallery > Job Management > Deployment Jobs, click the name of the deployed service, and then click Update service in the upper-right corner of the details page to go to the configuration page.
Modify the request body. In each request, add {"role": "assistant", "content": "<think>\n"} at the end of the message.
Disabling thinking mode
DeepSeek-R1 series models do not currently support disabling the thinking process.
Multi-turn conversations
The model service does not save conversation history. The client must store the conversation history and add it to the requests sent to the model. The following example shows a service deployed with SGLang.
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: <EAS_TOKEN>" \
-d '{
"model": "<model_name>",
"messages": [
{
"role": "user",
"content": "Hello"
},
{
"role": "assistant",
"content": "Hello! Nice to meet you. How can I help you?"
},
{
"role": "user",
"content": "What was my previous question?"
}
]
}' \
<EAS_ENDPOINT>/v1/chat/completions