How to Get a DeepSeek API Key: A Step-by-Step Guide
On this page
This guide shows you how to get a DeepSeek API key. You'll create a DeepSeek account, generate your key, and make your first API call, plus a free alternative for adding DeepSeek models to your web app.
Prerequisites
- An email address or phone number
- A payment method — DeepSeek's API is usage-based
- Basic familiarity with code (we'll show simple JavaScript examples)
Step 1: Create Your DeepSeek Account
Go to platform.deepseek.com. This is the API platform where you manage your keys, billing, and usage.
Sign up with your email or phone number. Once you're in, you'll land on the dashboard.
Before your API key will work, you need to add a payment method and top up your balance. Go to Top up and add credits. DeepSeek charges per token, and pricing varies by model.
Step 2: Generate Your API Key
In the left sidebar, click API keys, then click Create new API key.
Give your key a descriptive name like my-app-dev so you can identify it later, then confirm.
Important: Copy the key immediately. DeepSeek only shows it once. If you lose it, you'll need to generate a new one.
Store it somewhere safe — a password manager, an .env file, or your platform's secrets manager. Never commit API keys to a public repository.
Step 3: Make Your First API Call
DeepSeek uses an OpenAI-compatible API, so you can use the OpenAI SDK directly. Install it first:
npm install openai
Then make your first call:
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://api.deepseek.com",
apiKey: process.env.DEEPSEEK_API_KEY,
});
const completion = await openai.chat.completions.create({
model: "deepseek-chat",
messages: [{ role: "user", content: "Hello, world!" }],
});
console.log(completion.choices[0].message.content);
If you get a response back, everything is working. For the full set of endpoints and parameters, see DeepSeek's official API docs.
Can You Use the DeepSeek API for Free?
Creating an API key is free, but using it requires topping up your balance, and the API bills per token. New DeepSeek accounts receive a granted balance to test the API, and that granted balance is spent before any topped-up balance. The exact amount and validity window are set by DeepSeek and change, so check your balance on the platform after signing up rather than counting on it. Once it's used, billing switches to standard pay-per-token rates.
Puter.js offers a different model. With its User-Pays model, you can add DeepSeek models to your app for free: each user covers their own AI usage through their own Puter account, so your cost stays at $0 regardless of how many users you have, with no API key and no backend.
Add DeepSeek models with the browser script tag:
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("Explain quantum computing in simple terms", {
model: "deepseek/deepseek-v4-flash"
}).then(response => {
document.body.innerHTML = response.message.content;
});
</script>
or the npm package:
import { puter } from '@heyputer/puter.js';
const response = await puter.ai.chat("Explain quantum computing in simple terms", {
model: "deepseek/deepseek-v4-flash"
});
console.log(response.message.content);
This fits front-end apps where your users sign into Puter: usage is tied to their accounts, and Puter.js runs in the browser, so it does not replace a server-side key for a backend you control. For a backend, see the pricing below.
How Much Does the DeepSeek API Cost?
DeepSeek bills per token, with separate input and output rates, so cost scales with usage instead of a flat fee. The main model, DeepSeek V4 Flash, costs $0.14 per 1M input tokens and $0.28 per 1M output. The higher-capability DeepSeek V4 Pro is $1.74 per 1M input and $3.48 per 1M output. V4 Flash is among the cheapest frontier-class APIs available.
For the full breakdown, including automatic context caching, thinking-mode billing, and the per-model rates, see our DeepSeek API pricing guide.
Why Isn't My Key Working?
Most first-call failures trace back to a few errors:
- 401, Authentication Fails: the key is wrong, was revoked, or picked up a stray space or newline when copied. Regenerate it and paste again.
- 402, Insufficient Balance: the account has no balance left. Top up on the platform, then retry. This is behind most reports of a new key not working.
- 429, Rate Limit Reached: requests are going out too quickly. Slow the request rate, add retries with backoff, or briefly fall back to another provider.
- 400, Invalid Format: the request body is malformed. Fix it against the API docs per the error message hints.
- 422, Invalid Parameters: a parameter value is out of range or unsupported. Adjust it based on the error feedback.
Most of these come back to balance, so check that first. For the full list of status and error codes, see DeepSeek's error codes reference.
Conclusion
To get a DeepSeek API key: sign up at platform.deepseek.com, add a payment method and top up your balance, then go to API keys and click Create new API key. From there you can make your first API call, or skip the key entirely and add DeepSeek models to a web app for free with Puter.js.
Related
- DeepSeek API Pricing
- Free, Unlimited Claude API
- How to Get an OpenAI API Key
- How to Get an Anthropic (Claude) API Key
- How to Get a Gemini API Key
- How to Get a Grok (xAI) API Key
- How to Get an ElevenLabs API Key
- How to Get a Mistral API Key
- How to Get a MiniMax API Key
- How to Get a Moonshot AI (Kimi) API Key
- How to Get a Qwen API Key
- How to Get a Z.AI (GLM) API Key
- How to Get an OpenRouter API Key
- How to Get a FLUX (Black Forest Labs) API Key
- How to Get a Stability AI (Stable Diffusion) API Key
- How to Get a Kling API Key
- How to Get a Leonardo.Ai API Key
- How to Get a Together AI API Key
- How to Get a Cohere API Key
- How to Use OpenAI SDK with Puter
- Free, Unlimited OpenAI API
- Free, Unlimited Gemini API
- How to Use LangChain with Puter
- How to Use Vercel AI SDK with Puter
Ship a Full-Stack App with One Prompt
Build an AI chat app using Puter.js
Coding manually? see the guide