APIMaster.ai

DeepSeek R1 API 指南 — 推理模型存取 | APIMaster.ai

如何使用 Python 使用 DeepSeek 推理模型。涵蓋 DeepSeek R1 搜尋意圖、V4 思考模式、提示策略及 APIMaster.ai 存取。

DeepSeek R1 API 指南

DeepSeek R1 是 DeepSeek 推理能力的常見搜尋詞。對於目前的 API 整合,請使用 DeepSeek V4 Pro 思考模式;舊版的 deepseek-reasoner 相容性端點預計在 2026 年 7 月 24 日後退役。

DeepSeek R1 的與眾不同之處

與標準聊天模型不同,R1:

  1. 在回答前先推理:思考模式會將推理內容回傳在獨立的 reasoning_content 欄位中
  2. 擅長形式推理:數學證明、程式碼驗證、邏輯謎題
  3. 開放權重:基礎模型為開源(權重可在 HuggingFace 上取得)
  4. 具競爭力的效能:在許多基準測試上以更低成本媲美 o1

DeepSeek R1 API 快速入門

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_APIMASTER_KEY",
    base_url="https://apimaster.ai/v1",
)

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[
        {
            "role": "user",
            "content": "Prove that the square root of 2 is irrational.",
        }
    ],
    max_tokens=2048,  # R1 需要更多 token 進行推理
)

message = response.choices[0].message
print(getattr(message, "reasoning_content", ""))
print(message.content)

理解推理輸出

DeepSeek V4 思考模式通常會將推理與最終答案分開回傳:

message = response.choices[0].message
reasoning = getattr(message, "reasoning_content", "")
answer = message.content
print(answer)

DeepSeek R1 的提示策略

數學與證明

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[
        {
            "role": "user",
            "content": """Solve step by step:
Find all integer solutions to: x² - 5y² = 1

Show your reasoning."""
        }
    ],
    max_tokens=3000,
)

程式碼驗證

code = """
def merge_sort(arr):
    if len(arr) <= 1:
        return arr
    mid = len(arr) // 2
    left = merge_sort(arr[:mid])
    right = merge_sort(arr[mid:])
    return merge(left, right)
"""

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[
        {
            "role": "user",
            "content": f"Verify this merge sort implementation is correct:\n\n```python\n{code}\n```\n\nFind any bugs or edge cases."
        }
    ],
)

多步驟邏輯

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[
        {
            "role": "user",
            "content": """You have 3 boxes. One contains only apples, one only oranges, one both. All boxes are mislabeled. You can draw one fruit from one box. Which box do you pick and why?"""
        }
    ],
)

DeepSeek R1 與其他推理模型比較

模型 優勢 價格範圍 上下文長度
deepseek-v4-pro 數學、科學、複雜推理 即時定價 1M
o3 (OpenAI) 廣泛推理 200K
o4-mini 快速推理 128K
claude-opus-4-8 複雜分析 1M

DeepSeek 推理模型通常具有成本效益,但價格會因模型層級、快取命中率和輸出長度而異。

處理長推理輸出

R1 可能產生非常長的輸出——對於複雜任務,請將 max_tokens 設為較高值:

response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Solve this calculus problem: ..."}],
    max_tokens=4096,  # 複雜推理的高限制
)

# 檢查輸出是否被截斷
if response.choices[0].finish_reason == "length":
    print("Warning: Output truncated—increase max_tokens")

串流 R1 回應

為了在長推理任務上獲得更好的使用者體驗:

with client.chat.completions.stream(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Explain Gödel's incompleteness theorems."}],
    max_tokens=3000,
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

DeepSeek R1 API 定價

模型 輸入(每百萬 token) 輸出(每百萬 token)
DeepSeek V4 Pro $0.435 牌價 $0.87 牌價
DeepSeek V4 Flash $0.14 牌價 $0.28 牌價

請參閱 APIMaster 市集 以取得目前的折扣費率。

取得 DeepSeek R1 API 存取權

常見問題

什麼是 DeepSeek R1? DeepSeek R1 是使用者與 DeepSeek 推理相關聯的舊名稱。目前的 API 整合應使用 DeepSeek V4 思考模式,該模式透過 reasoning_content 公開推理過程。

何時應該使用 DeepSeek R1 而非 V4? 對於數學、形式邏輯、科學問題以及推理可提高準確性的任務,請使用 V4 Pro 思考模式。對於速度敏感的任務,請使用 V4 Flash 或非思考模式。

如何在 Python 中解析 DeepSeek R1 的思考輸出? 讀取 reasoning_content 以取得推理軌跡,讀取 content 以取得最終答案。對於目前的 API 整合,請避免依賴 思考 標籤解析。

DeepSeek R1 費用是多少? 價格因 V4 Flash/Pro 層級、快取命中率和輸出長度而異。請參閱 即時 APIMaster 定價

DeepSeek R1 是否可以透過 APIMaster 使用? 是的——使用模型 ID deepseek-v4-pro 搭配 APIMaster 的 OpenAI 相容端點。

開始使用 → · DeepSeek API 指南 → · DeepSeek 定價 →