{"id":20523083,"url":"https://github.com/llm-red-team/spark-free-api","last_synced_at":"2025-10-14T12:04:14.706Z","repository":{"id":235546613,"uuid":"790897479","full_name":"LLM-Red-Team/spark-free-api","owner":"LLM-Red-Team","description":"🚀 讯飞星火大模型逆向API【特长：办公助手】，支持高速流式输出、智能体对话、联网搜索、AI绘图、长文档解读、图像解析、多轮对话，零配置部署，多路token支持，自动清理会话痕迹，仅供测试，如需商用请前往官方开放平台。。","archived":false,"fork":false,"pushed_at":"2024-12-04T09:07:08.000Z","size":875,"stargazers_count":135,"open_issues_count":1,"forks_count":50,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T19:11:21.817Z","etag":null,"topics":["chat-api","chatbot","chatgpt-api","iflytek","llm","spark","spark-ai"],"latest_commit_sha":null,"homepage":"https://xinghuo.xfyun.cn/sparkapi","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LLM-Red-Team.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-23T18:18:04.000Z","updated_at":"2025-03-22T15:57:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"9602d0f5-1903-4c1f-bb0a-e4ae68228a78","html_url":"https://github.com/LLM-Red-Team/spark-free-api","commit_stats":null,"previous_names":["llm-red-team/spark-free-api"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LLM-Red-Team%2Fspark-free-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LLM-Red-Team%2Fspark-free-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LLM-Red-Team%2Fspark-free-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LLM-Red-Team%2Fspark-free-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LLM-Red-Team","download_url":"https://codeload.github.com/LLM-Red-Team/spark-free-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242681,"owners_count":20907134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat-api","chatbot","chatgpt-api","iflytek","llm","spark","spark-ai"],"created_at":"2024-11-15T22:37:55.118Z","updated_at":"2025-10-14T12:04:09.661Z","avatar_url":"https://github.com/LLM-Red-Team.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spark AI Free 服务\n\n[![](https://img.shields.io/github/license/llm-red-team/kimi-free-api.svg)](LICENSE)\n![](https://img.shields.io/github/stars/llm-red-team/spark-free-api.svg)\n![](https://img.shields.io/github/forks/llm-red-team/spark-free-api.svg)\n![](https://img.shields.io/docker/pulls/vinlic/spark-free-api.svg)\n\n支持高速流式输出、支持多轮对话、支持智能体对话、支持AI绘图、支持长文档解读、图像解析，零配置部署，多路token支持，自动清理会话痕迹。\n\n与ChatGPT接口完全兼容。\n\n还有以下九个free-api欢迎关注：\n\nMoonshot AI（Kimi.ai）接口转API [kimi-free-api](https://github.com/LLM-Red-Team/kimi-free-api)\n\n阶跃星辰 (跃问StepChat) 接口转API [step-free-api](https://github.com/LLM-Red-Team/step-free-api)\n\n阿里通义 (Qwen) 接口转API [qwen-free-api](https://github.com/LLM-Red-Team/qwen-free-api)\n\n智谱AI (智谱清言) 接口转API [glm-free-api](https://github.com/LLM-Red-Team/glm-free-api)\n\n秘塔AI (metaso) 接口转API [metaso-free-api](https://github.com/LLM-Red-Team/metaso-free-api)\n\n字节跳动（豆包）接口转API [doubao-free-api](https://github.com/LLM-Red-Team/doubao-free-api)\n\nMiniMax（海螺AI）接口转API [hailuo-free-api](https://github.com/LLM-Red-Team/hailuo-free-api)\n\n深度求索（DeepSeek）接口转API [deepseek-free-api](https://github.com/LLM-Red-Team/deepseek-free-api)\n\n聆心智能 (Emohaa) 接口转API [emohaa-free-api](https://github.com/LLM-Red-Team/emohaa-free-api)\n\n## 目录\n\n* [免责声明](#免责声明)\n* [在线体验](#在线体验)\n* [效果示例](#效果示例)\n* [接入准备](#接入准备)\n  * [智能体接入](#智能体接入)\n  * [多账号接入](#多账号接入)\n* [Docker部署](#Docker部署)\n  * [Docker-compose部署](#Docker-compose部署)\n* [Render部署](#Render部署)\n* [Vercel部署](#Vercel部署)\n* [原生部署](#原生部署)\n* [推荐使用客户端](#推荐使用客户端)\n* [接口列表](#接口列表)\n  * [对话补全](#对话补全)\n  * [AI绘图](#AI绘图)\n  * [文档解读](#文档解读)\n  * [图像解析](#图像解析)\n  * [ssoSessionId存活检测](#ssoSessionId存活检测)\n* [注意事项](#注意事项)\n  * [Nginx反代优化](#Nginx反代优化)\n  * [Token统计](#Token统计)\n* [Star History](#star-history)\n## 免责声明\n\n**逆向API是不稳定的，建议前往讯飞星火官方 https://xinghuo.xfyun.cn/sparkapi 付费使用API，避免封禁的风险。**\n\n**本组织和个人不接受任何资金捐助和交易，此项目是纯粹研究交流学习性质！**\n\n**仅限自用，禁止对外提供服务或商用，避免对官方造成服务压力，否则风险自担！**\n\n**仅限自用，禁止对外提供服务或商用，避免对官方造成服务压力，否则风险自担！**\n\n**仅限自用，禁止对外提供服务或商用，避免对官方造成服务压力，否则风险自担！**\n\n## 在线体验\n\n此链接仅临时测试功能，不可长期使用，长期使用请自行部署。\n\nhttps://udify.app/chat/xsLvQf9U0QJRIkmN\n\n## 效果示例\n\n### 验明正身Demo\n\n![验明正身](./doc/example-0.png)\n\n### 多轮对话Demo\n\n![多轮对话](./doc/example-1.png)\n\n### 智能体对话Demo\n\n![智能体对话](./doc/example-6.png)\n\n### 联网搜索Demo\n\n![联网搜索](./doc/example-2.png)\n\n### AI绘图Demo\n\n![AI绘图](./doc/example-5.png)\n\n### 长文档解读Demo\n\n![长文档解读](./doc/example-3.png)\n\n### 图像解析Demo\n\n![图像解析](./doc/example-4.png)\n\n## 接入准备\n\n从 [xinghuo.xfyun.cn](https://xinghuo.xfyun.cn) 获取ssoSessionId \n\n进入Spark登录并发起一个对话，从Cookie获取 `ssoSessionId` 值，由于星火平台禁用F12开发者工具，请安装 `Cookie-Editor` 浏览器插件查看你的Cookie。\n\n![image](https://github.com/LLM-Red-Team/spark-free-api/assets/20235341/a075cde2-db70-415d-93a4-1114029c9ef8)\n\n这个值将作为Authorization的Bearer Token值：`Authorization: Bearer TOKEN`\n\n**注意：如果退出登录或重新登录将可能导致ssoSessionId失效！**\n\n### 智能体接入\n\n从[这里](https://xinghuo.xfyun.cn/iflygpt/bot/home/get)使用浏览器搜索功能找到你想要的智能体，复制它的`botId`作为`model`值。\n\n### 多账号接入\n\n你可以通过提供多个账号的ssoSessionId并使用`,`拼接提供：\n\n`Authorization: Bearer TOKEN1,TOKEN2,TOKEN3`\n\n每次请求服务会从中挑选一个。\n\n## Docker部署\n\n请准备一台具有公网IP的服务器并将8000端口开放。\n\n拉取镜像并启动服务\n\n```shell\ndocker run -it -d --init --name spark-free-api -p 8000:8000 -e TZ=Asia/Shanghai vinlic/spark-free-api:latest\n```\n\n查看服务实时日志\n\n```shell\ndocker logs -f spark-free-api\n```\n\n重启服务\n\n```shell\ndocker restart spark-free-api\n```\n\n停止服务\n\n```shell\ndocker stop spark-free-api\n```\n\n### Docker-compose部署\n\n```yaml\nversion: '3'\n\nservices:\n  spark-free-api:\n    container_name: spark-free-api\n    image: vinlic/spark-free-api:latest\n    restart: always\n    ports:\n      - \"8000:8000\"\n    environment:\n      - TZ=Asia/Shanghai\n```\n\n### Render部署\n\n**注意：部分部署区域可能无法连接spark，如容器日志出现请求超时或无法连接（新加坡实测不可用）请切换其他区域部署！**\n**注意：免费账户的容器实例将在一段时间不活动时自动停止运行，这会导致下次请求时遇到50秒或更长的延迟，建议查看[Render容器保活](https://github.com/LLM-Red-Team/free-api-hub/#Render%E5%AE%B9%E5%99%A8%E4%BF%9D%E6%B4%BB)**\n\n1. fork本项目到你的github账号下。\n\n2. 访问 [Render](https://dashboard.render.com/) 并登录你的github账号。\n\n3. 构建你的 Web Service（New+ -\u003e Build and deploy from a Git repository -\u003e Connect你fork的项目 -\u003e 选择部署区域 -\u003e 选择实例类型为Free -\u003e Create Web Service）。\n\n4. 等待构建完成后，复制分配的域名并拼接URL访问即可。\n\n### Vercel部署\n\n**注意：Vercel免费账户的请求响应超时时间为10秒，但接口响应通常较久，可能会遇到Vercel返回的504超时错误！**\n\n请先确保安装了Node.js环境。\n\n```shell\nnpm i -g vercel --registry http://registry.npmmirror.com\nvercel login\ngit clone https://github.com/LLM-Red-Team/spark-free-api\ncd spark-free-api\nvercel --prod\n```\n\n## 原生部署\n\n请准备一台具有公网IP的服务器并将8000端口开放。\n\n请先安装好Node.js环境并且配置好环境变量，确认node命令可用。\n\n安装依赖\n\n```shell\nnpm i\n```\n\n安装PM2进行进程守护\n\n```shell\nnpm i -g pm2\n```\n\n编译构建，看到dist目录就是构建完成\n\n```shell\nnpm run build\n```\n\n启动服务\n\n```shell\npm2 start dist/index.js --name \"spark-free-api\"\n```\n\n查看服务实时日志\n\n```shell\npm2 logs spark-free-api\n```\n\n重启服务\n\n```shell\npm2 reload spark-free-api\n```\n\n停止服务\n\n```shell\npm2 stop spark-free-api\n```\n\n## 推荐使用客户端\n\n使用以下二次开发客户端接入free-api系列项目更快更简单，支持文档/图像上传！\n\n由 [Clivia](https://github.com/Yanyutin753/lobe-chat) 二次开发的LobeChat [https://github.com/Yanyutin753/lobe-chat](https://github.com/Yanyutin753/lobe-chat)\n\n由 [时光@](https://github.com/SuYxh) 二次开发的ChatGPT Web [https://github.com/SuYxh/chatgpt-web-sea](https://github.com/SuYxh/chatgpt-web-sea)\n\n## 接口列表\n\n目前支持与openai兼容的 `/v1/chat/completions` 接口，可自行使用与openai或其他兼容的客户端接入接口，或者使用 [dify](https://dify.ai/) 等线上服务接入使用。\n\n### 对话补全\n\n对话补全接口，与openai的 [chat-completions-api](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) 兼容。\n\n**POST /v1/chat/completions**\n\nheader 需要设置 Authorization 头部：\n\n```\nAuthorization: Bearer [ssoSessionId]\n```\n\n请求数据：\n```json\n{\n    // 模型名称随意填写，如果使用智能体请填写botId，如1662\n    // 可以从这里全局搜索找到你想用的智能体https://xinghuo.xfyun.cn/iflygpt/bot/home/get\n    \"model\": \"spark\",\n    // 目前多轮对话基于消息合并实现，某些场景可能导致能力下降且受最大token数限制\n    // 如果您想获得原生的多轮对话体验，可以传入首轮消息获得的id，来接续上下文，注意如果使用这个，首轮必须传none，否则第二轮会出现[belongerr]！\n    // \"conversation_id\": \"331680774:cht000b6cfc@dx18f7a7ef0bab81c560\",\n    \"messages\": [\n        {\n            \"role\": \"user\",\n            \"content\": \"你是谁？\"\n        }\n    ],\n    // 如果使用SSE流请设置为true，默认false\n    \"stream\": false\n}\n```\n\n响应数据：\n```json\n{\n    // 如果想获得原生多轮对话体验，此id，你可以传入到下一轮对话的conversation_id来接续上下文\n    \"id\": \"331680774:cht000b6cfc@dx18f7a7ef0bab81c560\",\n    \"model\": \"spark\",\n    \"object\": \"chat.completion\",\n    \"choices\": [\n        {\n            \"index\": 0,\n            \"message\": {\n                \"role\": \"assistant\",\n                \"content\": \"您好，我是科大讯飞研发的认知智能大模型，我的名字叫讯飞星火认知大模型。我可以和人类进行自然交流，解答问题，高效完成各领域认知智能需求。\"\n            },\n            \"finish_reason\": \"stop\"\n        }\n    ],\n    \"usage\": {\n        \"prompt_tokens\": 1,\n        \"completion_tokens\": 1,\n        \"total_tokens\": 2\n    },\n    \"created\": 1715747089\n}\n```\n\n### AI绘图\n\n对话补全接口，与openai的 [images-create-api](https://platform.openai.com/docs/api-reference/images/create) 兼容。\n\n**POST /v1/images/generations**\n\nheader 需要设置 Authorization 头部：\n\n```\nAuthorization: Bearer [ssoSessionId]\n```\n\n请求数据：\n```json\n{\n    \"prompt\": \"画只猫\"\n}\n```\n\n响应数据：\n```json\n{\n    \"created\": 1711507449,\n    \"data\": [\n        {\n            \"url\": \"https://sgw-dx.xf-yun.com/api/v1/sparkdesk/multimodal_image_301306010U064624.jpg?authorization=c2ltcGxlLWp3dCBhaz1zcGFya2Rlc2s4MDAwMDAwMDAwMDE7ZXhwPTMyOTA5MjMwNjM7YWxnbz1obWFjLXNoYTI1NjtzaWc9WnBIdk52ZzJLMmpDbkYzOUU1N3RLVVVSdnkvamxydVgvUnE1SWxnRUdaST0=\u0026x_location=7YfQJjZB7uKO7jlRxIftd6Fbdo==\"\n        }\n    ]\n}\n```\n\n### 文档解读\n\n提供一个可访问的文件URL或者BASE64_URL进行解析。\n\n**POST /v1/chat/completions**\n\nheader 需要设置 Authorization 头部：\n\n```\nAuthorization: Bearer [ssoSessionId]\n```\n\n请求数据：\n```json\n{\n    // 模型名称随意填写，如果不希望输出检索过程模型名称请包含silent_search\n    \"model\": \"spark\",\n    \"messages\": [\n        {\n            \"role\": \"user\",\n            \"content\": [\n                {\n                    \"type\": \"file\",\n                    \"file_url\": {\n                        \"url\": \"https://mj101-1317487292.cos.ap-shanghai.myqcloud.com/ai/test.pdf\"\n                    }\n                },\n                {\n                    \"type\": \"text\",\n                    \"text\": \"文档里说了什么？\"\n                }\n            ]\n        }\n    ]\n}\n```\n\n响应数据：\n```json\n{\n    \"id\": \"296791588:cht000b6cfc@dx18f7a7ef0bab11c560\",\n    \"model\": \"spark\",\n    \"object\": \"chat.completion\",\n    \"choices\": [\n        {\n            \"index\": 0,\n            \"message\": {\n                \"role\": \"assistant\",\n                \"content\": \"文档中描述了几个不同的魔法咒语和仪式的步骤，以及它们的目的和效果。第一个咒语是关于纪念那些因暴力死亡的人，并希望这些英雄、角斗士和死者能够带来成功。第二个咒语则是召唤一个名为Tereous的女性，通过一系列的仪式动作和念诵咒语来达到目的。第三个咒语与阿佛洛狄忒的名字有关，如果一个人想要赢得美丽女性的青睐，需要进行三天的净化，并在乳香上呼唤这个名称。第四个咒语涉及到没药，并且要求在煤炭上提供这种香料时念出特定的咒语，目的是吸引特定女性的注意，并阻止她进行日常活动。\"\n            },\n            \"finish_reason\": \"stop\"\n        }\n    ],\n    \"usage\": {\n        \"prompt_tokens\": 1,\n        \"completion_tokens\": 1,\n        \"total_tokens\": 2\n    },\n    \"created\": 1713936102\n}\n```\n\n### 图像解析\n\n提供一个可访问的图像URL或者BASE64_URL进行解析。\n\n此格式兼容 [gpt-4-vision-preview](https://platform.openai.com/docs/guides/vision) API格式，您也可以用这个格式传送文档进行解析。\n\n**POST /v1/chat/completions**\n\nheader 需要设置 Authorization 头部：\n\n```\nAuthorization: Bearer [ssoSessionId]\n```\n\n请求数据：\n```json\n{\n    \"model\": \"spark\",\n    \"messages\": [\n        {\n            \"role\": \"user\",\n            \"content\": [\n                {\n                    \"type\": \"file\",\n                    \"file_url\": {\n                        \"url\": \"https://xinghuo.xfyun.cn/static/media/icon-api-qa.06576333e96568ce3a31.png\"\n                    }\n                },\n                {\n                    \"type\": \"text\",\n                    \"text\": \"图里说了什么？\"\n                }\n            ]\n        }\n    ],\n    \"stream\": false\n}\n```\n\n响应数据：\n```json\n{\n    \"id\": \"296795606:cht000b6cfc@dx18f7b7ef0bab81c53c\",\n    \"model\": \"spark\",\n    \"object\": \"chat.completion\",\n    \"choices\": [\n        {\n            \"index\": 0,\n            \"message\": {\n                \"role\": \"assistant\",\n                \"content\": \"该图片显示了一个蓝色的圆形标志，上面写着“星火API咨询”。\"\n            },\n            \"finish_reason\": \"stop\"\n        }\n    ],\n    \"usage\": {\n        \"prompt_tokens\": 1,\n        \"completion_tokens\": 1,\n        \"total_tokens\": 2\n    },\n    \"created\": 1713936328\n}\n```\n\n### ssoSessionId存活检测\n\n检测ssoSessionId是否存活，如果存活live为true，否则为false，请不要频繁（小于10分钟）调用此接口。\n\n**POST /token/check**\n\n请求数据：\n```json\n{\n    \"token\": \"409794b0-1dd1-...\"\n}\n```\n\n响应数据：\n```json\n{\n    \"live\": true\n}\n```\n\n## 注意事项\n\n### Nginx反代优化\n\n如果您正在使用Nginx反向代理spark-free-api，请添加以下配置项优化流的输出效果，优化体验感。\n\n```nginx\n# 关闭代理缓冲。当设置为off时，Nginx会立即将客户端请求发送到后端服务器，并立即将从后端服务器接收到的响应发送回客户端。\nproxy_buffering off;\n# 启用分块传输编码。分块传输编码允许服务器为动态生成的内容分块发送数据，而不需要预先知道内容的大小。\nchunked_transfer_encoding on;\n# 开启TCP_NOPUSH，这告诉Nginx在数据包发送到客户端之前，尽可能地发送数据。这通常在sendfile使用时配合使用，可以提高网络效率。\ntcp_nopush on;\n# 开启TCP_NODELAY，这告诉Nginx不延迟发送数据，立即发送小数据包。在某些情况下，这可以减少网络的延迟。\ntcp_nodelay on;\n# 设置保持连接的超时时间，这里设置为120秒。如果在这段时间内，客户端和服务器之间没有进一步的通信，连接将被关闭。\nkeepalive_timeout 120;\n```\n\n### Token统计\n\n由于推理侧不在spark-free-api，因此token不可统计，将以固定数字返回!!!!!\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=LLM-Red-Team/spark-free-api\u0026type=Date)](https://star-history.com/#LLM-Red-Team/spark-free-api\u0026Date)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllm-red-team%2Fspark-free-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fllm-red-team%2Fspark-free-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllm-red-team%2Fspark-free-api/lists"}