Build an Application with the DeepSeek-V4.io API
Use the DeepSeek-V4.io Chat Completions, Responses, and Anthropic Messages endpoints with streaming and tool calls.
Build an Application with the DeepSeek-V4.io API
This tutorial uses the API provided by this site. The endpoint, API key, balance, and usage records all belong to DeepSeek-V4.io; keys from DeepSeek Platform or another inference provider do not work here.
Before you start
Sign in, add a one-time usage pack, and create a key in the Developer dashboard. The free signup preview works only in the hosted chat and cannot create an API key.
Store the key in an environment variable:
export DEEPSEEK_V4_API_KEY="your-deepseek-v4-io-key"
The public model ID is deepseek-v4-flash. The legacy ID deepseek/deepseek-v4-flash is accepted for compatibility, but new code should use the shorter name.
Chat Completions quickstart
The standard OpenAI client can target the site’s compatible endpoint:
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.DEEPSEEK_V4_API_KEY,
baseURL: 'https://deepseek-v4.io/api/v1',
})
const response = await client.chat.completions.create({
model: 'deepseek-v4-flash',
messages: [
{ role: 'system', content: 'Answer with concise implementation advice.' },
{ role: 'user', content: 'Show a safe retry policy for HTTP 429.' },
],
})
console.log(response.choices[0]?.message.content)
Use stream: true to receive server-sent events. When streaming, read until the stream closes; the final usage-bearing event is used for billing.
Responses API quickstart
Responses is the preferred protocol for clients such as Codex that perform multi-turn tool loops:
const response = await client.responses.create({
model: 'deepseek-v4-flash',
input: 'List the files needed for a minimal TypeScript HTTP server.',
})
console.log(response.output_text)
For tool use, send a function definition in tools. When the model returns a function call, execute the function locally, then send the result in the next Responses request. Never execute model-supplied commands without your application’s own validation and approval policy.
Anthropic Messages quickstart
Claude Code and other Anthropic-compatible clients can use POST https://deepseek-v4.io/api/v1/messages:
curl https://deepseek-v4.io/api/v1/messages \
-H "Authorization: Bearer $DEEPSEEK_V4_API_KEY" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "deepseek-v4-flash",
"max_tokens": 512,
"messages": [{"role": "user", "content": "Return the word ready."}]
}'
Production checklist
- Keep the key in a server-side secret store; never expose it in browser code.
- Set timeouts and retry only transient failures such as
429or5xx. - Use an idempotency strategy around your own side effects. Retrying a model request can repeat a tool call.
- Validate every tool name and argument before execution.
- Record your own request ID and the HTTP status, but do not log keys, prompts, source code, tool arguments, or response bodies by default.
- Inspect usage in the Developer dashboard and keep enough paid balance for the largest allowed response.
Pick a ready-made agent integration
If you do not need to build a client, use one of the standalone guides for Claude Code, Codex, OpenCode, Pi, Cline, or OpenClaw. The complete protocol reference is in the API documentation.
Share this article
Help others discover this content
About the Author
DeepSeek-V4.io Team publishes independent setup guides and product research for DeepSeek-V4.io. DeepSeek-V4.io is not affiliated with DeepSeek or the publishers of the tools covered in this article.