FREE AI INDEX / 统一产品界面我的收藏提交资源 ↗

Free AI Index / 从零开始Getting started / DeepSeek API

FIRST API CALL / deepseek

DeepSeek:跑通第一次 API 调用Make your first DeepSeek API call

先确认注册与免费条件,再按步骤获取密钥、安装依赖并验证返回结果。教程只使用环境变量读取密钥。Check signup and free terms first, then create a key, install dependencies and validate the response. Examples read credentials from environment variables.

官方文档复核Official docs reviewed: 2026-10-07独立 API 实测Independent API test: 尚未记录Not recorded

注册与网络前提Signup and network requirements

网络 / 地区
调用地址为 api.deepseek.com;大陆网络连通性未由本指南实测,请在自己的网络环境先验证。
账号
DeepSeek Platform 账号和 API Key。
手机号
官方 API 快速开始页未说明统一手机号要求;以账号注册页面提示为准。
实名认证
官方 API 快速开始页未说明统一实名认证要求;以账号页面提示为准。
信用卡 / 付款方式
官方 API 按量计费,不是免费额度;调用前先确认账户余额和价格。付款方式要求未确认。

这些条件会因账号、地区和产品计划而变化。标注“待核验”表示 FreeLLM 尚未从当前链接的官方资料确认;不要据此推断为不需要。These requirements can vary by account, region and plan. “Unverified” means FreeLLM has not confirmed the condition from the linked official sources; it does not mean the requirement is absent.

获取并安全设置 API KeyGet and safely set your API key

在终端设置密钥Set the key in your terminal

以下命令只为当前终端会话设置环境变量。请在自己的电脑上把尖括号内容替换成真实密钥,不要把密钥发给 FreeLLM 或粘贴到公开代码。These commands set a variable for the current terminal session. Replace the angle-bracket text with your key on your own device; never send it to FreeLLM or commit it to source code.

Windows PowerShellWindows PowerShell

$env:DEEPSEEK_API_KEY = "<在此粘贴本地 API Key>"

macOS / LinuxmacOS / Linux

export DEEPSEEK_API_KEY="<在此粘贴本地 API Key>"

FreeLLM 资源记录FreeLLM resource records

详细操作步骤Detailed operation paths

每条路径都拆成前置条件、步骤、可复制命令和验证动作;免费条件仍以官方页面实时状态为准。curl 命令按 macOS / Linux shell 编写,Windows 用户可使用同页的 Python 或 Node.js 示例。Each path includes prerequisites, steps, copyable commands and a validation action; free terms still follow the provider's live official policy. The curl examples use a macOS/Linux shell; Windows users can run the Python or Node.js examples on this page.

DeepSeek 官方 API 第一次调用(按量计费)

api

EndpointEndpoint
https://api.deepseek.com
认证Authentication
Authorization: Bearer API key
额度与限制Limits

按量计费;价格、并发和限流规则按官方价格与 Rate Limit 页面为准。

前置条件Prerequisites

  • DeepSeek Platform 账号DeepSeek Platform
  • 已创建 API Key 并保存到 DEEPSEEK_API_KEY 环境变量API Key DEEPSEEK_API_KEY
  • 已查看官方价格并确认账户余额;此入口不是免费额度;

操作步骤Steps

  1. 创建 API Key 并查看价格

    在 DeepSeek Platform 创建密钥。官方 API 按量计费;先查看当前模型价格与账户余额,再发请求。

    操作Action:打开 https://platform.deepseek.com/

  2. 安装 OpenAI Python SDK

    官方 API 兼容 OpenAI Chat Completions 格式。建议使用 Python 3.9+ 虚拟环境。

    可复制命令Copyable command
    python -m pip install -U openai
  3. 发送第一条请求

    使用官方当前模型 ID deepseek-flash。该模型名替代已退役的旧 Flash 名称。

    可复制命令Copyable command
    export DEEPSEEK_API_KEY="你的 Key"
    curl https://api.deepseek.com/chat/completions -H 'Content-Type: application/json' -H "Authorization: Bearer $DEEPSEEK_API_KEY" -d '{"model":"deepseek-flash","messages":[{"role":"user","content":"用一句话解释 API 是什么。"}],"stream":false}'

    预期结果Expected:返回 choices[0].message.content;同时检查控制台余额和用量记录。

  4. Python SDK 示例

    密钥从环境变量读取;不在代码中粘贴真实密钥。

    可复制命令Copyable command
    import os
    from openai import OpenAI
    
    client = OpenAI(
        api_key=os.environ["DEEPSEEK_API_KEY"],
        base_url="https://api.deepseek.com",
    )
    response = client.chat.completions.create(
        model="deepseek-flash",
        messages=[{"role": "user", "content": "用一句话解释 API 是什么。"}],
    )
    print(response.choices[0].message.content)

    预期结果Expected:终端打印模型回复。

  5. Node.js SDK 示例

    安装 OpenAI 官方 Node.js SDK;Node.js 20 LTS 或更新版本。

    可复制命令Copyable command
    npm install openai
    
    import OpenAI from "openai";
    
    const client = new OpenAI({
      apiKey: process.env.DEEPSEEK_API_KEY,
      baseURL: "https://api.deepseek.com",
    });
    const response = await client.chat.completions.create({
      model: "deepseek-flash",
      messages: [{ role: "user", content: "用一句话解释 API 是什么。" }],
    });
    console.log(response.choices[0].message.content);

    预期结果Expected:Node.js 打印模型回复;控制台可查看本次调用用量。

验证动作Validation

响应包含 choices 数组中的模型文本,并在控制台确认账户余额和用量变化。

常见问题Common issues
  • 401:检查 API Key 是否正确,且没有把 API URL 填进 Key 字段。401: API Key , API URL Key 。
  • 402:账户余额不足;停止重试并检查价格和余额。402: ; 。
  • 404:确认模型 ID 为当前官方模型名,例如 deepseek-flash。404: ID , deepseek-flash。
  • 429:降低请求频率并按官方建议等待后再重试。429: 。

官方来源Official sources