DeepSeek

Integrate DeepSeek’s powerful reasoning models with ProtectMyAPI.

🧠

Reasoning Models: DeepSeek-R1 delivers GPT-4 level reasoning at a fraction of the cost

Features

  • ✅ Advanced reasoning (DeepSeek-R1)
  • ✅ Chat Completions
  • ✅ Code generation (DeepSeek-Coder)
  • ✅ Function Calling
  • ✅ JSON Mode
  • ✅ Long context (64K+)
  • ✅ Streaming responses

Setup

1. Add your API key to Secrets

In the ProtectMyAPI dashboard:

  1. Go to your app → Secrets
  2. Add a secret named DEEPSEEK_API_KEY
  3. Paste your DeepSeek API key as the value

2. Create an endpoint

Create an endpoint with:

  • Name: DeepSeek Chat
  • Slug: deepseek-chat
  • Target URL: https://api.deepseek.com/chat/completions
  • Method: POST
  • Auth Type: Bearer
  • Auth Value: {{DEEPSEEK_API_KEY}}

Code Examples

import ProtectMyAPI
 
// Standard chat
let response = try await ProtectMyAPI.shared.request(
    endpoint: "deepseek-chat",
    method: .POST,
    body: [
        "model": "deepseek-chat",
        "messages": [
            ["role": "user", "content": "Explain the theory of relativity"]
        ]
    ]
)
 
// Reasoning with DeepSeek-R1
let reasoningResponse = try await ProtectMyAPI.shared.request(
    endpoint: "deepseek-chat",
    method: .POST,
    body: [
        "model": "deepseek-reasoner",
        "messages": [
            ["role": "user", "content": "Solve: If 3x + 7 = 22, what is x? Show your reasoning."]
        ]
    ]
)
 
// Code generation
let codeResponse = try await ProtectMyAPI.shared.request(
    endpoint: "deepseek-chat",
    method: .POST,
    body: [
        "model": "deepseek-coder",
        "messages": [
            ["role": "system", "content": "You are an expert programmer."],
            ["role": "user", "content": "Write a Redis caching layer in Python"]
        ]
    ]
)
 
// JSON Mode
let jsonResponse = try await ProtectMyAPI.shared.request(
    endpoint: "deepseek-chat",
    method: .POST,
    body: [
        "model": "deepseek-chat",
        "messages": [
            ["role": "user", "content": "List the top 5 programming languages for 2024"]
        ],
        "response_format": ["type": "json_object"]
    ]
)

Models

ModelBest ForContext
deepseek-chatGeneral conversation64K
deepseek-reasonerMath, logic, analysis64K
deepseek-coderCode generation64K

Reasoning Model

DeepSeek-R1 excels at multi-step reasoning:

// Math problem solving
let mathResponse = try await ProtectMyAPI.shared.request(
    endpoint: "deepseek-chat",
    method: .POST,
    body: [
        "model": "deepseek-reasoner",
        "messages": [
            ["role": "user", "content": """
            A train travels from City A to City B at 60 mph.
            Another train travels from City B to City A at 40 mph.
            The cities are 200 miles apart.
            If both trains leave at the same time, when and where will they meet?
            """]
        ]
    ]
)

Code Generation

DeepSeek-Coder is optimized for programming:

let codeResponse = try await ProtectMyAPI.shared.request(
    endpoint: "deepseek-chat",
    method: .POST,
    body: [
        "model": "deepseek-coder",
        "messages": [
            ["role": "system", "content": "You are an expert Swift developer."],
            ["role": "user", "content": "Implement a thread-safe LRU cache"]
        ],
        "temperature": 0 // More deterministic for code
    ]
)

Function Calling

let response = try await ProtectMyAPI.shared.request(
    endpoint: "deepseek-chat",
    method: .POST,
    body: [
        "model": "deepseek-chat",
        "messages": [
            ["role": "user", "content": "Calculate the area of a circle with radius 5"]
        ],
        "tools": [
            [
                "type": "function",
                "function": [
                    "name": "calculate_area",
                    "description": "Calculate the area of a shape",
                    "parameters": [
                        "type": "object",
                        "properties": [
                            "shape": ["type": "string"],
                            "dimensions": [
                                "type": "object",
                                "properties": [
                                    "radius": ["type": "number"]
                                ]
                            ]
                        ],
                        "required": ["shape", "dimensions"]
                    ]
                ]
            ]
        ]
    ]
)

Cost Comparison

DeepSeek offers excellent value:

ProviderModel ClassInput CostOutput Cost
DeepSeekdeepseek-chat$0.14/1M$0.28/1M
OpenAIgpt-4o$2.50/1M$10.00/1M
Anthropicclaude-3.5$3.00/1M$15.00/1M

DeepSeek is ~95% cheaper than GPT-4 while maintaining competitive quality!