Skip to content
d

DeepSeek V4 Pro

Text Generationdeepseek

DeepSeek V4 Pro is a high-capability reasoning model from DeepSeek, served via Fireworks infrastructure for production-grade inference.

Model Info
Context Window131,072 tokens
More informationlink
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
const response = await env.AI.run(
'deepseek/deepseek-v4-pro',
{
messages: [{ content: 'What is the capital of France?', role: 'user' }],
model: 'deepseek/deepseek-v4-pro',
},
)
console.log(response)
The capital of France is **Paris**.

Examples

With System Message — Using a system message to set context
TypeScript
const response = await env.AI.run(
'deepseek/deepseek-v4-pro',
{
messages: [
{ content: 'You are a helpful coding assistant specializing in Python.', role: 'system' },
{ content: 'How do I read a JSON file in Python?', role: 'user' },
],
model: 'deepseek/deepseek-v4-pro',
temperature: 0.3,
},
)
console.log(response)
To read a JSON file in Python, you use the built-in `json` module. The most common approach is `json.load()` which reads directly from a file object.

### Basic example
```python
import json

with open('data.json', 'r', encoding='utf-8') as f:
    data = json.load(f)

print(data)
```

### Key points
- **`json.load(file)`** – parses JSON from a file-like object.
- **`json.loads(string)`** – parses JSON from a string (useful if you already have JSON data in memory).
- Always open the file in read mode (`'r'`) and specify the correct encoding (usually `'utf-8'`).
- The result is a Python dictionary (if the JSON is an object) or a list (if it’s an array).

### Handling errors
Wrap the loading in a `try`/`except` to catch malformed JSON or file issues:
```python
import json

try:
    with open('data.json', 'r', encoding='utf-8') as f:
        data = json.load(f)
except FileNotFoundError:
    print("File not found.")
except json.JSONDecodeError as e:
    print(f"Invalid JSON: {e}")
```

### Reading from a string
If you already have a JSON string:
```python
json_string = '{"name": "Alice", "age": 30}'
data = json.loads(json_string)
```

That’s it! Let me know if you need help with writing JSON or more advanced usage.
Streaming Response — Enable streaming for real-time output
TypeScript
const response = await env.AI.run(
'deepseek/deepseek-v4-pro',
{
messages: [{ content: 'Explain the concept of recursion with a simple example.', role: 'user' }],
model: 'deepseek/deepseek-v4-pro',
stream: true,
},
)
console.log(response)
Recursion is a programming technique where a function calls itself to solve a smaller version of the same problem. Each recursive call works on a simpler input, and there’s always a **base case** that stops the recursion, preventing an infinite loop.

### The Two Essential Parts
1. **Base case** – the simplest scenario that can be answered directly (no more recursive calls).
2. **Recursive case** – the function calls itself with a smaller/simpler argument, moving toward the base case.

### Simple Example: Factorial
The factorial of a non-negative integer `n` (written `n!`) is the product of all positive integers up to `n`.  
Definition:  
- `0! = 1` (base case)  
- `n! = n × (n−1)!` for `n > 0` (recursive case)

#### Python implementation
```python
def factorial(n):
    if n == 0:          # base case
        return 1
    else:               # recursive case
        return n * factorial(n - 1)
```

#### How it works step-by-step for `factorial(3)`
```
factorial(3)
  → 3 * factorial(2)           # waiting for factorial(2)
        → 2 * factorial(1)     # waiting for factorial(1)
              → 1 * factorial(0)
                    → 0 == 0? → return 1   # base case reached
              → 1 * 1 = 1
        → 2 * 1 = 2
  → 3 * 2 = 6
```
The calls "stack up" until the base case is hit, then they resolve in reverse order, multiplying as they go.

### Key Takeaways
- Recursion breaks a problem into self-similar subproblems.
- Every recursive function needs a stopping condition (base case).
- Without a base case, you get infinite recursion (eventually a stack overflow).
- It’s especially natural for problems with a recursive structure (trees, sorting, divide-and-conquer, etc.).

Parameters

frequency_penalty
numbermaximum: 2minimum: -2
max_completion_tokens
numberexclusiveMinimum: 0
max_tokens
numberexclusiveMinimum: 0
presence_penalty
numbermaximum: 2minimum: -2
response_format
stream
boolean
temperature
numbermaximum: 2minimum: 0
tool_choice
top_p
numbermaximum: 1minimum: 0

API Schemas (Raw)

Input
Output