# DeepSeek V4 Pro > Open-weight (MIT) thinking model at 1.6T parameters for hard reasoning and competitive-grade coding, with a 1,000,000-token context, tool calling and streaming over an OpenAI-compatible chat endpoint. ## Overview - **Endpoint**: `https://queue.modelrunner.run/deepseek/v4` - **Model ID**: `deepseek/v4` - **Category**: text-to-text - **Kind**: inference - **Tags**: deepseek, deepseek-v4, deepseek-v4-pro, llm, text-to-text, chat, chat-completions, openai-compatible, reasoning, thinking, chain-of-thought, agentic, agentic-coding, coding, code-generation, competitive-programming, long-context, million-token-context, open-weight, open-source, mit-license, mixture-of-experts, streaming, tool-calling, json-mode ## Pricing - **Input tokens**: $2.4 per 1M - **Cached input tokens**: $0.2 per 1M - **Output tokens**: $4.8 per 1M ## Request Lifecycle This model runs on the ModelRunner **asynchronous queue API** — a single POST does not return the output. Every call requires an `Authorization: Key $MODEL_RUNNER_KEY` header. Run three steps: 1. **Submit** — `POST https://queue.modelrunner.run/deepseek/v4` with a JSON body holding the input fields at the top level. The body may also include a reserved top-level `metadata` object — a flat string map (max 16 keys, key ≤64 / value ≤512 chars) stored on the request for your own tagging. It is never sent to the model; filter your request history with `GET https://queue.modelrunner.run/requests?metadata=` (exact key=value matches, AND-ed). The response carries request handles only (no output yet): ```json { "status": "IN_QUEUE", "request_id": "<21-char id>", "status_url": "https://queue.modelrunner.run/deepseek/v4/requests//status", "response_url": "https://queue.modelrunner.run/deepseek/v4/requests/", "cancel_url": "https://queue.modelrunner.run/deepseek/v4/requests//cancel" } ``` 2. **Poll status** — `GET ` until `status` is `COMPLETED`. Possible values are `IN_QUEUE`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, `CANCELLED`. A `FAILED` request responds with HTTP 400 and an `error` field. 3. **Read result** — `GET `. Returns the finished request, including the generated `output`: ```json { "id": "", "status": "COMPLETED", "output": ..., "input": ... } ``` The JavaScript and Python SDKs below perform steps 2–3 for you. In any language without an SDK (Swift, Go, Kotlin, etc.) you must implement the polling loop and the final result fetch yourself — see the cURL example for the full flow. ### Input Schema - **`seed`** (`integer`, _optional_): Best-effort determinism hint. - **`stop`** (`unknown`, _optional_): Up to 4 stop sequences. - **`tools`** (`array`, _optional_): OpenAI-format tool definitions the model may call. - **`stream`** (`boolean`, _optional_): Return the reply as a Server-Sent Events stream of deltas terminated by \`data: \[DONE\]\`. The chain of thought arrives on the same stream in a \`reasoning_content\` delta field. - Default: `false` - **`messages`** (`array`, _required_): OpenAI-style conversation history. Each item is an object with a \`role\` (\`system\`, \`user\`, \`assistant\` or \`tool\`) and \`content\`. Text only — this model accepts no image, audio or document parts. - **`max_tokens`** (`integer`, _optional_): Upper bound on generated tokens. \`max_tokens\` and the thinking budget share one 393,216-token ceiling, so a long chain of thought consumes the room left for the visible answer — allow generous headroom. - Range: `1` to `"+inf"` - **`tool_choice`** (`unknown`, _optional_): \`auto\`, \`none\`, \`required\`, or a specific tool. - **`response_format`** (`object`, _optional_): Structured-output control. Set its \`type\` to \`json_object\` to force a JSON reply. - **`reasoning_effort`** (`ReasoningEffortEnum`, _optional_): How hard the model thinks before answering. Defaults to \`high\`. Lowering it does not cut cost on this endpoint: \`low\` and \`medium\` behave as \`high\` and \`xhigh\` behaves as \`max\`, so \`high\` is the cheapest reachable setting. Thinking tokens bill as output tokens. - Default: `"high"` - Options: `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"` ### Output Schema - **`id`** (`string`, _optional_): - **`model`** (`string`, _optional_): - **`usage`** (`object`, _optional_): - **`object`** (`string`, _optional_): - **`choices`** (`array`, _optional_): - **`created`** (`integer`, _optional_): ## Default Example **Input** ```json { "model": "deepseek/v4", "messages": [ { "role": "user", "content": "Given an array of n integers, find the length of the longest subsequence such that every two consecutive elements in the subsequence have an absolute difference of exactly 1. State the time and space complexity of your solution, then implement it in Python." } ], "max_tokens": 8000, "reasoning_effort": "high" } ``` **Output** ```json { "id": "chatcmpl-vwj8FIOoF6Qwqo0tXflBS", "model": "deepseek/v4", "usage": { "total_tokens": 2632, "prompt_tokens": 54, "completion_tokens": 2578, "prompt_tokens_details": { "cached_tokens": 0 }, "completion_tokens_details": { "reasoning_tokens": 2327 } }, "object": "chat.completion", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "**Time Complexity:** O(n) – We iterate through the array once, performing constant-time hash map operations per element. \n**Space Complexity:** O(n) – In the worst case, the hash map stores one entry per unique element, which is bounded by n.\n\n```python\nfrom typing import List\n\ndef longest_subsequence_diff_one(arr: List[int]) -> int:\n \"\"\"\n Returns the length of the longest subsequence where every two consecutive\n elements have an absolute difference of exactly 1.\n \"\"\"\n if not arr:\n return 0\n\n # length_map[x] = length of longest valid subsequence ending with value x\n length_map = {}\n max_len = 0\n\n for x in arr:\n # We can extend a subsequence that ended with x-1 or x+1\n best = max(length_map.get(x - 1, 0), length_map.get(x + 1, 0)) + 1\n # Keep the best length for subsequences ending with x\n length_map[x] = max(length_map.get(x, 0), best)\n max_len = max(max_len, length_map[x])\n\n return max_len\n```", "reasoning_content": "We need to find the length of the longest subsequence (not necessarily contiguous) where every two consecutive elements have absolute difference of exactly 1. The array has n integers. We need to output the length, and state time and space complexity, then implement Python code.\n\nEssentially, we need to find the longest subsequence where adjacent elements in the subsequence differ by 1. This is similar to finding the longest \"consecutive\" sequence in terms of a subsequence with difference 1, but order matters? Since it's a subsequence, we can pick elements in any order? Wait, subsequence means we maintain the original order of elements in the array. But the problem says \"every two consecutive elements in the subsequence have an absolute difference of exactly 1\". Usually subsequence means we pick elements in the same order as they appear in the array. But wait, if we can reorder, it's a subset, not a subsequence. The problem says \"subsequence\", which implies maintaining relative order.\n\nLet's read carefully: \"Given an array of n integers, find the length of the longest subsequence such that every two consecutive elements in the subsequence have an absolute difference of exactly 1.\" This is a classic dynamic programming problem: longest subsequence with adjacent difference 1. But we can also think of it as a graph problem where we can transition from a value to value ± 1, but we need to maintain order. Typically, DP[i] = length of longest subsequence ending at index i with difference 1. Then DP[i] = 1 + max(DP[j] for j < i where |arr[i] - arr[j]| == 1). This is O(n^2) time, O(n) space. But we can optimize to O(n) using a hash map storing the longest subsequence ending with a particular value? Wait, if we need to maintain the original order, we can iterate through the array, and for each element x, we can update the longest subsequence ending with value x. But we need to consider that the subsequence ending with x can be formed by appending x to a subsequence ending with x-1 or x+1. However, does the order matter? If we just keep the maximum length ending with value x seen so far, we are effectively building subsequences in the order of appearance. For each element x in array order, we can compute best = max(length[x-1], length[x+1]) + 1, and then update length[x] = max(length[x], best). This works because we only append x to subsequences that ended with x-1 or x+1, and those subsequences ended at some index before the current index. Since we process in order, we maintain the correct order. This yields O(n) time and O(n) space (or O(unique values) space). This is a known solution for \"Longest subsequence with difference 1\" (also known as \"Longest Harmonious Subsequence\"? No, harmonious is difference exactly 1 between max and min? Actually, there's \"Longest Arithmetic Subsequence\" with difference 1, but that's different. The problem is similar to \"Longest Subsequence with difference 1\" on GeeksforGeeks.). Let's verify: For array [1, 2, 3, 2, 1], the longest subsequence? We can pick 1,2,3,2,1? Differences: |1-2|=1, |2-3|=1, |3-2|=1, |2-1|=1. That's length 5. So order is preserved. If we use hash map, length[x] after processing: \n1: length[1] = max(length[0], length[2]) + 1 = 1\n2: length[2] = max(length[1], length[3]) + 1 = 2\n3: length[3] = max(length[2], length[4]) + 1 = 3\n2: length[2] = max(length[1], length[3]) + 1 = max(1,3)+1=4 -> update length[2]=4\n1: length[1] = max(length[0], length[2]) + 1 = max(0,4)+1=5 -> length[1]=5\nMax is 5. Correct.\n\nBut wait, is there a catch? The subsequence must have consecutive elements differing by exactly 1. That means it can alternate between x and x+1, etc. The DP using hash map works because we only care about the last element's value. The order constraint is automatically satisfied because we process elements left to right, so any subsequence ending with a value is formed by picking elements in increasing index order. The hash map stores the maximum length of a valid subsequence ending with that value seen so far. When we see a new element with value x, the best we can do is append it to the best subsequence ending with x-1 or x+1. We don't need to worry about the internal order because we are just appending at the end. This is correct.\n\nTime complexity: O(n) because we do constant work per element.\nSpace complexity: O(n) for the hash map (or O(u) where u is number of unique values, but worst case O(n)).\n\nEdge cases: n=0? \"array of n integers\" n could be 0? Usually n>=1. If n=0, return 0. Negative numbers? Works fine.\n\nWe need to output the length, state time and space complexity, and implement in Python.\n\nLet's write the Python function:\n\ndef longest_subsequence_diff_one(arr):\n if not arr:\n return 0\n length_map = {}\n max_len = 0\n for x in arr:\n # length of subsequence ending with x-1 or x+1\n best = max(length_map.get(x-1, 0), length_map.get(x+1, 0)) + 1\n length_map[x] = max(length_map.get(x, 0), best)\n max_len = max(max_len, length_map[x])\n return max_len\n\nTest: arr = [1,2,3,2,1] -> 5.\narr = [1,1,1] -> 1? Wait, consecutive elements difference exactly 1. If all elements are same, difference is 0, so the longest subsequence with diff 1 is length 1? Because we can pick any single element, but we cannot pick two because difference 0 != 1. So answer should be 1. Our code: for x=1: best = max(0,0)+1=1; length[1]=1. Next x=1: best = max(0,0)+1=1; length[1]=max(1,1)=1. So max=1. Correct.\narr = [5,4,3,2,1] -> longest? 5,4,3,2,1 differences 1. Length 5.\narr = [1,3,5,7] -> length 1.\narr = [1,2,3,4,5,3,2,1] -> length 8? Let's check: 1,2,3,4,5,3,2,1? Differences: 1, 1, 1, 1, 1, 2? Wait, 5 to 3 diff is 2, not 1. So we cannot go 5->3. We need every adjacent difference exactly 1. So subsequence can be 1,2,3,4,5? Or 1,2,3,2,1? Length 5. Our DP: let's simulate:\n1: best=1, map[1]=1\n2: best=map[1]+1=2, map[2]=2\n3: best=map[2]+1=3, map[3]=3\n4: best=map[3]+1=4, map[4]=4\n5: best=map[4]+1=5, map[5]=5\n3: best=max(map[2], map[4])+1 = max(2,4)+1=5, map[3]=max(3,5)=5\n2: best=max(map[1], map[3])+1 = max(1,5)+1=6, map[2]=max(2,6)=6\n1: best=max(map[0], map[2])+1 = max(0,6)+1=7, map[1]=max(1,7)=7\nMax=7. But wait, is there a subsequence of length 7? Let's construct: indices: 0:1, 1:2, 2:3, 3:4, 4:5, 5:3, 6:2, 7:1.\nWe can pick: 1 (idx0), 2 (idx1), 3 (idx2), 4 (idx3), 5 (idx4), then we cannot pick 3 because diff 2. But we can skip 5 and pick 3 later? Actually the DP allows us to form a subsequence: 1,2,3,4,3,2,1? Check differences: 1-2=1, 2-3=1, 3-4=1, 4-3=1, 3-2=1, 2-1=1. That's length 7! Subsequence: indices 0:1, 1:2, 2:3, 3:4, 5:3, 6:2, 7:1. Yes, we can skip 5. So length 7 is correct. So DP works.\n\nWhat about array with duplicates? e.g., [1,2,2,1]. DP:\n1: map[1]=1\n2: map[2]=max(map[1],0)+1=2\n2: map[2]=max(map[1],0)+1=2 (since map[1]=1, best=2, map[2]=max(2,2)=2)\n1: map[1]=max(map[0], map[2])+1 = max(0,2)+1=3, map[1]=3.\nMax=3. Subsequence: 1 (idx0), 2 (idx1), 1 (idx3)? Diff: 1-2=1, 2-1=1. Length 3. Correct.\n\nSo the solution is O(n) time, O(n) space.\n\nWe need to state time and space complexity and implement in Python.\n\nImplementation details:\nFunction signature: def longest_subsequence(arr: List[int]) -> int:\nWe'll import List from typing.\n\nWe'll write a clean function.\n\nLet's prepare final answer." }, "logprobs": null, "finish_reason": "stop" } ], "created": 1787128396 } ``` ## Usage Examples ### cURL The queue API is asynchronous: submit the request, poll `status_url` until it is `COMPLETED`, then read the result from `response_url`. Requires `jq`. ```bash # 1. Submit the request (returns request handles, not the output) SUBMIT=$(curl --silent --request POST \ --url https://queue.modelrunner.run/deepseek/v4 \ --header "Authorization: Key $MODEL_RUNNER_KEY" \ --header "Content-Type: application/json" \ --data '{ "model": "deepseek/v4", "messages": [ { "role": "user", "content": "Given an array of n integers, find the length of the longest subsequence such that every two consecutive elements in the subsequence have an absolute difference of exactly 1. State the time and space complexity of your solution, then implement it in Python." } ], "max_tokens": 8000, "reasoning_effort": "high" }') STATUS_URL=$(echo "$SUBMIT" | jq -r '.status_url') RESPONSE_URL=$(echo "$SUBMIT" | jq -r '.response_url') # 2. Poll until the request leaves the queue / in-progress state while true; do STATUS=$(curl --silent --url "$STATUS_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" | jq -r '.status') echo "Status: $STATUS" case "$STATUS" in COMPLETED) break ;; FAILED|CANCELLED) echo "Request $STATUS"; exit 1 ;; esac sleep 1 done # 3. Read the finished request, including the generated output curl --silent --url "$RESPONSE_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" ``` ### JavaScript ```javascript import { modelrunner } from "@modelrunner/client"; const result = await modelrunner.subscribe("deepseek/v4", { input: { "model": "deepseek/v4", "messages": [ { "role": "user", "content": "Given an array of n integers, find the length of the longest subsequence such that every two consecutive elements in the subsequence have an absolute difference of exactly 1. State the time and space complexity of your solution, then implement it in Python." } ], "max_tokens": 8000, "reasoning_effort": "high" } }); console.log(result.data); ``` ### Python ```python import asyncio import modelrunner_ai async def main(): response = await modelrunner_ai.submit_async( "deepseek/v4", arguments={ "model": "deepseek/v4", "messages": [ { "role": "user", "content": "Given an array of n integers, find the length of the longest subsequence such that every two consecutive elements in the subsequence have an absolute difference of exactly 1. State the time and space complexity of your solution, then implement it in Python." } ], "max_tokens": 8000, "reasoning_effort": "high" } ) result = await response.get() print(result["output"]) asyncio.run(main()) ``` ## Additional Resources - [Playground](https://modelrunner.ai/models/deepseek/v4) - [OpenAPI Schema](https://modelrunner.ai/models/deepseek/v4/openapi.json) - [LLM Instructions](https://modelrunner.ai/models/deepseek/v4/llms.txt) - [GitHub](https://github.com/deepseek-ai) - [License](https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro/blob/main/README.md) - [Weights](https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro) - [Paper](https://arxiv.org/abs/2606.19348)