# deepseek-api **Repository Path**: cq0321/deepseek-api ## Basic Information - **Project Name**: deepseek-api - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-22 - **Last Updated**: 2026-05-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DeepSeek API Proxy Server Express 后端代理,将 Vue3 前端的请求转发到 [DeepSeek API](https://api.deepseek.com/v1/chat/completions)。响应格式与官方 OpenAI 兼容接口一致,前端只需改 base URL 和路径即可切换。 ## 快速开始 ```bash npm install cp .env.example .env # 编辑 .env,填入 DEEPSEEK_API_KEY npm run dev ``` 服务默认运行在 `http://localhost:3000`。 ## 环境变量 | 变量 | 说明 | |------|------| | `DEEPSEEK_API_KEY` | DeepSeek API Key(必填) | | `PORT` | 监听端口,默认 `3000` | | `CORS_ORIGIN` | 允许的前端源,逗号分隔;不设置则允许所有源 | ## API ### `POST /api/deepseek/chat` 请求体示例: ```json { "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Hello!" } ], "model": "deepseek-chat", "stream": false, "thinking": { "type": "enabled" }, "reasoning_effort": "high" } ``` - 非流式:返回 JSON,与 DeepSeek 官方响应相同。 - 流式:设置 `"stream": true`,返回 `text/event-stream` SSE。 ### `GET /health` 健康检查。 ## Vue3 前端切换示例 **直连 DeepSeek:** ```javascript const baseURL = "https://api.deepseek.com/v1"; const path = "/chat/completions"; const headers = { "Content-Type": "application/json", Authorization: `Bearer ${import.meta.env.VITE_DEEPSEEK_API_KEY}`, }; ``` **经本代理:** ```javascript const baseURL = "http://localhost:3000/api/deepseek"; const path = "/chat"; const headers = { "Content-Type": "application/json", // 无需在前端携带 API Key }; ``` 请求体字段(`messages`、`model`、`stream`、`thinking`、`reasoning_effort` 等)保持不变。 ```javascript async function chat(messages, { stream = false } = {}) { const res = await fetch(`${baseURL}${path}`, { method: "POST", headers, body: JSON.stringify({ messages, model: "deepseek-chat", stream, thinking: { type: "enabled" }, reasoning_effort: "high", }), }); if (!stream) return res.json(); // 处理 SSE ... return res; } ``` ## 项目结构 ``` src/ server.js # Express 入口、CORS、健康检查 routes/ deepseek.js # POST /chat 代理逻辑 ```