New to Rust? Grab our free Rust for Beginners eBook Get it free →
How to Use the DeepSeek API in 2026
The official DeepSeek API uses token billing, so an API key is not a permanent free resource. DeepSeek’s July 2026 documentation lists deepseek-v4-flash and deepseek-v4-pro, and it schedules deepseek-chat and deepseek-reasoner for deprecation on July 24, 2026. A provider can expose a temporary free model, but model availability and limits belong to that provider’s catalog rather than the DeepSeek API.
Choose the API route before you write code
DeepSeek’s direct endpoint is https://api.deepseek.com and it accepts an OpenAI-compatible chat-completions request, so the current OpenAI JavaScript SDK can send the request when its base URL points at DeepSeek.
| Route | When it fits | What to check |
|---|---|---|
| Direct DeepSeek API | You want DeepSeek’s documented endpoint and model names. | Token pricing and the key balance in the DeepSeek platform. |
| OpenRouter | You need one API surface for several providers. | The live model page for a free label, rate limits, and provider routing. |
Free labels and queue limits can change without an application-code change, so treat a provider free route as a testing option and put a spending limit or fallback path in any deployed application.
Create a DeepSeek API key and keep it on the server
Create your key at the DeepSeek API key page, then set it in the shell that starts your app and call the model from a server route, command-line script, or trusted backend because browser JavaScript exposes the key to every visitor.
export DEEPSEEK_API_KEY="your_key_here"
npm install openai
node deepseek-chat.mjs
Keep the environment variable out of Git, screenshots, and client-side JavaScript. If a key reaches a public repository, revoke it and create another one before sending more requests.
Send a current chat-completions request
Save the following file as deepseek-chat.mjs. The example uses deepseek-v4-flash, one of the model names on DeepSeek’s current quick-start page, and stops before the network call when the environment variable is missing.
import OpenAI from "openai";
const apiKey = process.env.DEEPSEEK_API_KEY;
if (!apiKey) {
throw new Error("Set DEEPSEEK_API_KEY before running this script.");
}
const client = new OpenAI({
apiKey,
baseURL: "https://api.deepseek.com"
});
const response = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [
{ role: "user", content: "Explain JavaScript optional chaining in two sentences." }
]
});
console.log(response.choices[0].message.content);
A local run with no key in the environment stops with Set DEEPSEEK_API_KEY before it attempts a request. That guard prevents an accidental request with an undefined credential and makes the setup failure easy to diagnose.

Update older model names before July 24
DeepSeek’s quick-start documentation schedules deepseek-chat and deepseek-reasoner for deprecation on July 24, 2026 at 15:59 UTC. Replace those names with deepseek-v4-flash after checking whether you need its non-thinking or thinking behavior, or select deepseek-v4-pro when the workload calls for it.
Code that still sends a retired name can fail after the cutoff even when its SDK and API key remain valid. Keep model selection in one configuration value so a model change does not require editing each request.
Use a free provider route with an explicit limit
OpenRouter documents a Free Models Router and can list DeepSeek free variants when they are available, but its model catalog decides the route because it states the model ID and any free label that applies when you send requests.
Use DeepSeek’s free chat options when you only need the hosted chat product. If your project needs an API key and repeatable request behavior, keep the direct API path above and read the Google Gemini API free-tier guide before choosing a provider with a published free allowance.
Check the live catalog before deployment
Run a small request first, watch token usage in the provider dashboard, and set a budget that fits the application. DeepSeek’s pricing page is the source for direct API rates. OpenRouter’s model page is the source for a provider-specific free route.
Model names and free availability change faster than an integration tutorial. Keep the endpoint, model name, and key outside browser code, then verify the live catalog on the day you ship.




