Skip to content

DeepSeek V4

DeepSeek V4 is available through the OpenAI-compatible Chat Completions API. It supports long context, reasoning, streaming, and function calling. Both input and output are text-only.

Endpoint

http
POST /v1/chat/completions

Supported Models

ModelDescription
deepseek-v4-proGeneral DeepSeek V4 Pro version
deepseek-v4-pro-0813Stable 2026-08-13 snapshot for applications that require a fixed model version

The models support a context window of approximately one million tokens. Actual availability and context limits depend on your account permissions and platform configuration.

Basic Request

bash
curl https://cubicspaces.cloud/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro-0813",
    "messages": [
      { "role": "system", "content": "You are a precise and concise technical assistant." },
      { "role": "user", "content": "Explain idempotency in one sentence." }
    ],
    "max_completion_tokens": 2048,
    "stream": false
  }'

Reasoning Mode

DeepSeek V4 enables reasoning by default. Use these fields to control it:

ParameterTypeDescription
enable_thinkingbooleanSet to true to enable reasoning or false to disable it
reasoning_effortstringUse high or max; max generally produces deeper and longer reasoning
json
{
  "model": "deepseek-v4-pro-0813",
  "messages": [
    { "role": "user", "content": "Analyze the race conditions in this concurrency design." }
  ],
  "enable_thinking": true,
  "reasoning_effort": "high",
  "max_completion_tokens": 8192
}

In a non-streaming response, reasoning text is returned in choices[0].message.reasoning_content, while the final answer is returned in choices[0].message.content.

json
{
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning_content": "First, inspect the shared state and lock scope...",
        "content": "The primary issue is a race window between the check and the write."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 42,
    "completion_tokens": 318,
    "total_tokens": 360
  }
}

If your application only displays the final answer, you can ignore reasoning_content.

Streaming

bash
curl https://cubicspaces.cloud/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "messages": [
      { "role": "user", "content": "List three common reasons why a database index is not used." }
    ],
    "enable_thinking": true,
    "reasoning_effort": "high",
    "stream": true,
    "stream_options": {
      "include_usage": true
    }
  }'

Streaming responses use SSE. Parse these fields separately:

  • choices[0].delta.reasoning_content: reasoning chunks.
  • choices[0].delta.content: final-answer chunks.
  • usage: usually returned near the end when stream_options.include_usage is enabled.
  • data: [DONE]: end-of-stream marker.

Function Calling

DeepSeek V4 supports OpenAI-compatible function calling.

json
{
  "model": "deepseek-v4-pro-0813",
  "messages": [
    { "role": "user", "content": "Check the current weather in Tokyo." }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the weather for a city",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string" }
          },
          "required": ["city"]
        }
      }
    }
  ],
  "tool_choice": "auto"
}

When finish_reason is tool_calls:

  1. Read choices[0].message.tool_calls.
  2. Execute the requested tools.
  3. Append each result as a role: "tool" message.
  4. Continue with the same model to obtain the final answer.

Each tool result's tool_call_id must exactly match its corresponding tool_calls[].id.

Python SDK

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://cubicspaces.cloud/v1",
)

response = client.chat.completions.create(
    model="deepseek-v4-pro-0813",
    messages=[
        {"role": "user", "content": "Explain idempotency in one sentence."}
    ],
    max_completion_tokens=2048,
    extra_body={
        "enable_thinking": True,
        "reasoning_effort": "high",
    },
)

message = response.choices[0].message
print(message.content)

Parameters

ParameterTypeDescription
modelstringdeepseek-v4-pro or deepseek-v4-pro-0813
messagesarrayOpenAI Chat message array
max_completion_tokensintegerMaximum output tokens; preferred for reasoning models
enable_thinkingbooleanWhether to enable reasoning mode
reasoning_effortstringReasoning effort; use high or max
streambooleanWhether to stream the response
stream_optionsobjectStreaming options such as include_usage
toolsarrayFunction definitions
tool_choicestring/objectTool selection policy

Notes

  • DeepSeek V4 accepts text input only. Do not include images or videos in messages.
  • The model does not support top_k; omit that parameter.
  • Reasoning and final-answer tokens may both count toward output usage, so set a suitable output limit.
  • Tool definitions must use valid JSON Schema, and function names must be unique.
  • Use deepseek-v4-pro-0813 when you need a fixed model version; use deepseek-v4-pro for the general version.
  • If the model is unavailable, verify that it is enabled for your account.