API & SDKGuide
DeepSeek-V4-Flash API quickstart: long answers, streaming
Send a first request to DeepSeek-V4-Flash with the OpenAI SDK, set max_tokens for long answers, turn on streaming and estimate your cost.

On this page
This guide gets you from zero to a working DeepSeek-V4-Flash request, then shows how to ask for long answers, stream them and estimate what your workload will cost. It takes about ten minutes.
Which "DeepSeek Flash" are we talking about?#
Versions are easy to mix up right now. DeepSeek moved its official deepseek-flash alias to DeepSeek-V4.1-Flash-1017; the calling method did not change (source: DeepSeek API docs, checked 21 October 2026). We cover that release in DeepSeek-V4.1-Flash-1017 is out.
This guide is about a different, specific model: DeepSeek-V4-Flash, release 0731, available on CheapTokens under the gateway id deepseek-. It is not V4.1-Flash, and nothing about V4.1-Flash-1017 (its behaviour, benchmarks or limits) applies to it. Use the id exactly as written below.
What you get on CheapTokens with this model:
- 380K context window;
- up to 32,768 output tokens per answer, the longest answer in our lineup;
- OpenAI Chat Completions and Anthropic Messages compatible API;
- one balance for all models, fixed per-model prices and no peak-hour pricing.
Step 1. Get a key#
Create an account, top up the balance and create an API key in the dashboard. If you want the generic walkthrough first, see Your first API request with CheapTokens.
The base URL is https:/. Keep the key in an environment variable instead of pasting it into code:
export CHEAPTOKENS_API_KEY="your-key-here"Step 2. Send your first request#
With curl:
curl https://api.cheaptokens.dev/v1/chat/completions \
-H "Authorization: Bearer $CHEAPTOKENS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-ai/DeepSeek-V4-Flash-0731",
"messages": [{"role": "user", "content": "Explain what a token is in two sentences."}]
}'With the official OpenAI Python SDK, only base_url and the key change:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.cheaptokens.dev/v1",
api_key=os.environ["CHEAPTOKENS_API_KEY"],
)
resp = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[{"role": "user", "content": "Explain what a token is in two sentences."}],
)
print(resp.choices[0].message.content)
print(resp.usage)The usage field shows how many input and output tokens the call used, which you will need for the cost estimate. New to the term? Read What is a token in AI?.
Step 3. Ask for a long answer#
If an answer stops mid-sentence, the usual cause is the output limit, not the model "giving up". Set max_tokens explicitly and check finish_reason. The background is in Why does an AI answer stop mid-sentence?.
For this model the ceiling is 32,768 output tokens:
resp = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[{"role": "user", "content": "Write a detailed migration guide from REST to gRPC, with code samples."}],
max_tokens=32768,
)
choice = resp.choices[0]
print(choice.message.content)
if choice.finish_reason == "length":
print("Cut off by max_tokens - raise the limit or ask for the next part.")finish_ means the model finished on its own; "length" means it hit the limit. Remember that max_tokens only caps the answer: you pay for tokens actually generated, and your prompt plus the answer must fit into the 380K context.
A long limit is useful for long code files, documents, reports and translations. For short replies a small max_tokens keeps surprises down.
Step 4. Turn on streaming#
With stream=True you get the text in chunks as it is generated, so long answers appear immediately instead of after a long wait:
stream = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[{"role": "user", "content": "Write a long README for a small CLI tool."}],
max_tokens=32768,
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)This uses the standard OpenAI streaming parameters. For error handling and reading the final finish_reason from a stream, see Streaming responses in Python.
Step 5. Estimate the cost#
Billing is pay-as-you-go from a prepaid balance, priced per 1M tokens, separately for input and output. Current prices for MiniMax-M2.7, the same request format with the id MiniMaxAI/: $0.05 per 1M input tokens and $0.15 per 1M output tokens.
A worked example: a request with 2,000 input tokens and 8,000 output tokens costs $0.0013 on MiniMax-M2.7. The table below shows 1,000 such requests across the models, with an OpenRouter reference column:
| Model | Input $/1M | Output $/1M | Per request | 1,000 requests | OpenRouter, 1,000 requests |
|---|---|---|---|---|---|
| GLM-5.3-Flash | $0.02 | $0.04 | $0.00036 | $0.36 | $0.689 |
| DeepSeek-V4-Flash | $0.015 | $0.10 | $0.00083 | $0.83 | $1.35 |
| MiniMax-M2.7 | $0.05 | $0.15 | $0.0013 | $1.30 | $10.20 |
2,000 input and 8,000 output tokens per request. Prices per 1M tokens are current and change together with our tariffs; the OpenRouter column shows reference prices for the same workload.
To use it for your own workload, take typical usage. and usage. from a few real calls, then multiply by your daily request count. For a wider view of price planning, see DeepSeek API pricing in 2026.
When this model fits, and when another does#
DeepSeek-V4-Flash is a good fit when answers are long: code generation, reports, documentation, translations. On CheapTokens its output is cheaper than the OpenRouter reference price, and the blended price (3 input : 1 output) is lower too.
If your answers are short (classification, extraction, short Q&A), consider GLM-5.3-Flash: it has a 390K context and answers up to 8,192 tokens; compare both models' prices in the table above. Switching is just a change of the model id to zai-, and one balance covers both models. Not sure which to pick? See GLM vs DeepSeek vs MiniMax.
Quick checklist#
- Base URL:
https:/; model:/ api. cheaptokens. dev/ v1 deepseek-.ai/ DeepSeek- V4- Flash- 0731 - Set
max_tokens(up to 32,768) and checkfinish_reason. - Use
stream=Truefor long answers. - Read
usageand estimate with the cost table before scaling up.
Ready to try it? Get a key, top up your balance and run the first snippet above.



