├── src ├── service │ └── __init__.py ├── pool │ ├── __init__.py │ ├── fetcher.py │ └── session_pool.py ├── api │ ├── router.py │ └── endpoints │ │ ├── file.py │ │ └── chat.py ├── model │ ├── request.py │ └── response.py └── templates │ └── index.html ├── imgs ├── docs.png └── frontend-ui.png ├── requirements.txt ├── example.session.json ├── app.py └── .history ├── app_20250615211304.py ├── app_20250621131748.py ├── app_20250621134909.py ├── session_20250615180751.json ├── session_20250621131508.json ├── session_20250621131549.json ├── session_20250621131558.json ├── session_20250621131505.json ├── src └── templates │ ├── index_20250621140711.html │ └── index_20250615145302.html ├── README_20250615182852.md ├── README_20250621141103.md ├── README_20250621141104.md ├── README_20250621141108.md ├── README_20250621141113.md ├── README_20250621141114.md ├── README_20250621141135.md ├── README_20250621141134.md ├── README_20250621141137.md ├── README_20250621141138.md ├── README_20250621141140.md ├── README_20250621141147.md ├── README_20250621141149.md ├── README_20250621141150.md ├── README_20250621141152.md ├── README_20250621141157.md ├── README_20250621141313.md ├── README_20250621141316.md ├── README_20250621141158.md ├── README_20250621141200.md ├── README_20250621141202.md ├── README_20250621141204.md ├── README_20250621141325.md ├── README_20250621141327.md ├── README_20250621141329.md ├── README_20250621141207.md └── README_20250621141331.md /src/service/__init__.py: -------------------------------------------------------------------------------- 1 | from .doubao_service import * -------------------------------------------------------------------------------- /imgs/docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XilyFeAAAA/DoubaoFreeApi/HEAD/imgs/docs.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XilyFeAAAA/DoubaoFreeApi/HEAD/requirements.txt -------------------------------------------------------------------------------- /imgs/frontend-ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XilyFeAAAA/DoubaoFreeApi/HEAD/imgs/frontend-ui.png -------------------------------------------------------------------------------- /src/pool/__init__.py: -------------------------------------------------------------------------------- 1 | from .session_pool import DoubaoSession, SessionPool, session_pool 2 | 3 | __all__ = [ 4 | "DoubaoSession", 5 | "SessionPool", 6 | "session_pool" 7 | ] -------------------------------------------------------------------------------- /example.session.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "cookie": "", 4 | "device_id": "", 5 | "tea_uuid": "", 6 | "web_id": "", 7 | "room_id": "", 8 | "x_flow_trace": "" 9 | } 10 | ] -------------------------------------------------------------------------------- /src/api/router.py: -------------------------------------------------------------------------------- 1 | from fastapi import APIRouter 2 | from .endpoints import chat 3 | from .endpoints import file 4 | 5 | router = APIRouter() 6 | 7 | # 注册各个模块的路由 8 | router.include_router(chat.router, prefix="/chat", tags=["聊天"]) 9 | router.include_router(file.router, prefix="/file", tags=["文件"]) -------------------------------------------------------------------------------- /src/api/endpoints/file.py: -------------------------------------------------------------------------------- 1 | from fastapi import APIRouter, Body, Query, HTTPException 2 | from src.service import upload_file 3 | from src.model.response import UploadResponse 4 | 5 | 6 | router = APIRouter() 7 | 8 | 9 | @router.post("/upload", response_model=UploadResponse) 10 | async def api_upload(file_type: int = Query(), file_name: str = Query(), file_bytes: bytes = Body()): 11 | """上传图片或文件到豆包服务器""" 12 | try: 13 | return await upload_file(file_type, file_name, file_bytes) 14 | except Exception as e: 15 | raise HTTPException(status_code=500, detail=f"生成文件失败:{str(e)}") 16 | -------------------------------------------------------------------------------- /src/model/request.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel 2 | 3 | class CompletionRequest(BaseModel): 4 | prompt: str 5 | guest: bool 6 | attachments: list[dict] = [] 7 | conversation_id: str | None = None 8 | section_id: str | None = None 9 | use_deep_think: bool = False 10 | use_auto_cot: bool = False 11 | 12 | 13 | class AttachmentRequest(BaseModel): 14 | key: str 15 | name: str 16 | type: str 17 | file_review_state: int 18 | file_parse_state: int 19 | identifier: str 20 | option: dict | None = None 21 | md5: str | None = None 22 | size: int | None = None 23 | 24 | 25 | class UploadRequest(BaseModel): 26 | file_type: int 27 | file_name: str 28 | file_bytes: bytes -------------------------------------------------------------------------------- /src/model/response.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel 2 | import uuid 3 | 4 | 5 | class CompletionResponse(BaseModel): 6 | text: str 7 | img_urls: list[str] 8 | conversation_id: str 9 | messageg_id: str 10 | section_id: str 11 | 12 | 13 | class UploadResponse(BaseModel): 14 | key: str 15 | name: str 16 | type: str 17 | file_review_state: int 18 | file_parse_state: int 19 | identifier: str 20 | option: dict | None = None 21 | md5: str | None = None 22 | size: int | None = None 23 | 24 | 25 | class ImageResponse(BaseModel): 26 | key: str 27 | name: str 28 | option: dict 29 | type: str = "vlm_image" 30 | file_review_state: int = 3 31 | file_parse_state: int = 3 32 | identifier: str = str(uuid.uuid1()) 33 | 34 | 35 | class FileResponse(BaseModel): 36 | key: str 37 | name: str 38 | md5: str 39 | size: int 40 | type: str = "file" 41 | file_review_state: int = 1 42 | file_parse_state: int = 3 43 | identifier: str = str(uuid.uuid1()) 44 | 45 | 46 | class DeleteResponse(BaseModel): 47 | ok: bool 48 | msg: str -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI 2 | from fastapi.middleware.cors import CORSMiddleware 3 | from fastapi.staticfiles import StaticFiles 4 | from fastapi.templating import Jinja2Templates 5 | from fastapi.responses import HTMLResponse 6 | from fastapi import Request 7 | from src.api.router import router 8 | from src.pool import session_pool 9 | import uvicorn 10 | 11 | 12 | app = FastAPI( 13 | title="豆包API服务", 14 | description="轻量级豆包API代理服务", 15 | version="0.2.0" 16 | ) 17 | 18 | 19 | app.add_middleware( 20 | CORSMiddleware, 21 | allow_origins=["*"], 22 | allow_credentials=True, 23 | allow_methods=["*"], 24 | allow_headers=["*"], 25 | ) 26 | 27 | app.mount("/static", StaticFiles(directory="src/static"), name="static") 28 | templates = Jinja2Templates(directory="src/templates") 29 | 30 | @app.get("/", response_class=HTMLResponse) 31 | async def index(request: Request): 32 | return templates.TemplateResponse("index.html", {"request": request}) 33 | 34 | 35 | @app.on_event("startup") 36 | async def startup(): 37 | await session_pool.fetch_guest_session(0) 38 | print("成功获取游客Session") 39 | 40 | app.include_router(router, prefix="/api") 41 | 42 | if __name__ == "__main__": 43 | uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=False) 44 | -------------------------------------------------------------------------------- /.history/app_20250615211304.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI 2 | from fastapi.middleware.cors import CORSMiddleware 3 | from fastapi.staticfiles import StaticFiles 4 | from fastapi.templating import Jinja2Templates 5 | from fastapi.responses import HTMLResponse 6 | from fastapi import Request 7 | from src.api.router import router 8 | from src.pool import session_pool 9 | import uvicorn 10 | 11 | 12 | app = FastAPI( 13 | title="豆包API服务", 14 | description="轻量级豆包API代理服务", 15 | version="0.2.0" 16 | ) 17 | 18 | 19 | app.add_middleware( 20 | CORSMiddleware, 21 | allow_origins=["*"], 22 | allow_credentials=True, 23 | allow_methods=["*"], 24 | allow_headers=["*"], 25 | ) 26 | 27 | app.mount("/static", StaticFiles(directory="src/static"), name="static") 28 | templates = Jinja2Templates(directory="src/templates") 29 | 30 | @app.get("/", response_class=HTMLResponse) 31 | async def index(request: Request): 32 | return templates.TemplateResponse("index.html", {"request": request}) 33 | 34 | 35 | @app.on_event("startup") 36 | async def startup(): 37 | await session_pool.fetch_guest_session(1) 38 | print("成功获取游客Session") 39 | 40 | app.include_router(router, prefix="/api") 41 | 42 | if __name__ == "__main__": 43 | uvicorn.run("app:app", host="0.0.0.0", port=8001, reload=False) 44 | -------------------------------------------------------------------------------- /.history/app_20250621131748.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI 2 | from fastapi.middleware.cors import CORSMiddleware 3 | from fastapi.staticfiles import StaticFiles 4 | from fastapi.templating import Jinja2Templates 5 | from fastapi.responses import HTMLResponse 6 | from fastapi import Request 7 | from src.api.router import router 8 | from src.pool import session_pool 9 | import uvicorn 10 | 11 | 12 | app = FastAPI( 13 | title="豆包API服务", 14 | description="轻量级豆包API代理服务", 15 | version="0.2.0" 16 | ) 17 | 18 | 19 | app.add_middleware( 20 | CORSMiddleware, 21 | allow_origins=["*"], 22 | allow_credentials=True, 23 | allow_methods=["*"], 24 | allow_headers=["*"], 25 | ) 26 | 27 | app.mount("/static", StaticFiles(directory="src/static"), name="static") 28 | templates = Jinja2Templates(directory="src/templates") 29 | 30 | @app.get("/", response_class=HTMLResponse) 31 | async def index(request: Request): 32 | return templates.TemplateResponse("index.html", {"request": request}) 33 | 34 | 35 | @app.on_event("startup") 36 | async def startup(): 37 | await session_pool.fetch_guest_session(0) 38 | print("成功获取游客Session") 39 | 40 | app.include_router(router, prefix="/api") 41 | 42 | if __name__ == "__main__": 43 | uvicorn.run("app:app", host="0.0.0.0", port=8001, reload=False) 44 | -------------------------------------------------------------------------------- /.history/app_20250621134909.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI 2 | from fastapi.middleware.cors import CORSMiddleware 3 | from fastapi.staticfiles import StaticFiles 4 | from fastapi.templating import Jinja2Templates 5 | from fastapi.responses import HTMLResponse 6 | from fastapi import Request 7 | from src.api.router import router 8 | from src.pool import session_pool 9 | import uvicorn 10 | 11 | 12 | app = FastAPI( 13 | title="豆包API服务", 14 | description="轻量级豆包API代理服务", 15 | version="0.2.0" 16 | ) 17 | 18 | 19 | app.add_middleware( 20 | CORSMiddleware, 21 | allow_origins=["*"], 22 | allow_credentials=True, 23 | allow_methods=["*"], 24 | allow_headers=["*"], 25 | ) 26 | 27 | app.mount("/static", StaticFiles(directory="src/static"), name="static") 28 | templates = Jinja2Templates(directory="src/templates") 29 | 30 | @app.get("/", response_class=HTMLResponse) 31 | async def index(request: Request): 32 | return templates.TemplateResponse("index.html", {"request": request}) 33 | 34 | 35 | @app.on_event("startup") 36 | async def startup(): 37 | await session_pool.fetch_guest_session(0) 38 | print("成功获取游客Session") 39 | 40 | app.include_router(router, prefix="/api") 41 | 42 | if __name__ == "__main__": 43 | uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=False) 44 | -------------------------------------------------------------------------------- /src/api/endpoints/chat.py: -------------------------------------------------------------------------------- 1 | from fastapi import APIRouter, Body, Query, HTTPException 2 | from src.service import chat_completion, delete_conversation 3 | from src.model.response import CompletionResponse, DeleteResponse 4 | from src.model.request import CompletionRequest 5 | 6 | 7 | router = APIRouter() 8 | 9 | 10 | @router.post("/completions", response_model=CompletionResponse) 11 | async def api_completions(completion: CompletionRequest = Body()): 12 | """ 13 | 豆包聊天补全接口(目前仅支持文字消息e和图片消息) 14 | 1. 如果是新聊天 conversation_id, section_id**不填** 15 | 2. 如果沿用之前的聊天, 则沿用**第一次对话**返回的 conversation_id 和 section_id, 会话池会使用之前的参数 16 | 3. 目前如果使用未登录账号,那么不支持上下文 17 | """ 18 | try: 19 | text, imgs, conv_id, msg_id, sec_id = await chat_completion( 20 | prompt=completion.prompt, 21 | guest=completion.guest, 22 | conversation_id=completion.conversation_id, 23 | section_id=completion.section_id, 24 | attachments=completion.attachments, 25 | use_auto_cot=completion.use_auto_cot, 26 | use_deep_think=completion.use_deep_think 27 | ) 28 | return CompletionResponse( 29 | text=text, 30 | img_urls=imgs, 31 | conversation_id=conv_id, 32 | messageg_id=msg_id, 33 | section_id=sec_id 34 | ) 35 | except Exception as e: 36 | raise HTTPException(status_code=500, detail=str(e)) 37 | 38 | 39 | 40 | @router.post("/delete", response_model=DeleteResponse) 41 | async def api_delete(conversation_id: str = Query()): 42 | """ 43 | 删除聊天 44 | 1. conversation_id 不存在也会提示成功 45 | 2. 建议在聊天结束时都调用函数,避免创建过多对话 46 | """ 47 | try: 48 | ok, msg = await delete_conversation(conversation_id) 49 | return DeleteResponse( 50 | ok=ok, 51 | msg=msg 52 | ) 53 | except Exception as e: 54 | raise HTTPException(status_code=500, detail=str(e)) -------------------------------------------------------------------------------- /.history/session_20250615180751.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "cookie": "is_staff_user=false; store-region=cn-ah; store-region-src=uid; _ga=GA1.1.895357759.1742196011; s_v_web_id=verify_mbf4a7l3_1MHruucg_CkdA_4Cuj_8RbG_8nYLexTZUcJ0; passport_csrf_token=1eabf80454b58d818bbd5ebfe7389dc0; passport_csrf_token_default=1eabf80454b58d818bbd5ebfe7389dc0; passport_mfa_token=Cjjuuwap1TfSZ0WTSTsUQGFc1MHygzDpxCWVSC49B8xbNbsmfIQl1y7Cvk7WbavM5KkD6hfJGjFRgBpKCjwAAAAAAAAAAAAATxFIRXvKXzKiXRKEeaiM0kDzNkHHE%2FGOHyeOju5ikOgTvIa85nAh7S2dqRJq%2BgCXU2gQsITzDRj2sdFsIAIiAQNoDHJH; d_ticket=50db36b9c4704d170d98d22fc42d0962bc1f4; n_mh=4Yh99OVF3mj2MOpbnhh46c2zJ3k4mV7y6c5D5Pr85iE; _gcl_aw=GCL.1749008627.Cj0KCQjwuvrBBhDcARIsAKRrkjey6zRaDAFAoLejnMzYKhgMmcoFKHZ4jqwvewbEzgWs8sZT4l3JsDkaAn8LEALw_wcB; _gcl_gs=2.1.k1$i1749008624$u91292815; gd_random=eyJtYXRjaCI6ZmFsc2UsInBlcmNlbnQiOjAuMjA2MjExNDc4NjkzMzgzNzR9.SCksBUKlQYtVupbVMLbHkY8F4uAGdNROWA8KL8dFcT0=; ttcid=a0f76b09ec1c4c21ad23bd63ab62580f36; passport_auth_status=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; passport_auth_status_ss=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; uid_tt=0fc2d4822867dbfea63c93d7338deb83; uid_tt_ss=0fc2d4822867dbfea63c93d7338deb83; sid_tt=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid_ss=d2be5b7a33551f7cf5fee96c75f0ec67; i18next=zh; flow_ssr_sidebar_expand=1; sid_guard=d2be5b7a33551f7cf5fee96c75f0ec67%7C1749971799%7C5183999%7CThu%2C+14-Aug-2025+07%3A16%3A38+GMT; sid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; ssid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; tt_scid=Rm.-EpAIjajLEHgOVKHpN5Htt8qLlEgdhqer.nQW22fpOGqdH4EYN79cMBKVhU2ca296; ttwid=1%7CIPjQ87CLus7PgbcIJOdwauMrQqsEavFGm6QrH14LF8w%7C1749974414%7C08c5c0bb1f6b705e85c016d58541000af34d53bc1eb4bbae0781570345db7e0b; _ga_G8EP5CG8VZ=GS2.1.s1749974413$o33$g1$t1749974415$j58$l0$h0; passport_fe_beating_status=true", 4 | "device_id": "7516071569933567528", 5 | "tea_uuid": "7516071593681045002", 6 | "web_id": "7516071593681045002", 7 | "room_id": "9005407235430914", 8 | "x_flow_trace": "04-00159877ca32df15001cff3dd24dff79-001fe74e159a7db1-01" 9 | } 10 | ] -------------------------------------------------------------------------------- /.history/session_20250621131508.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "cookie": "is_staff_user=false; store-region=cn-ah; store-region-src=uid; _ga=GA1.1.895357759.1742196011; s_v_web_id=verify_mbf4a7l3_1MHruucg_CkdA_4Cuj_8RbG_8nYLexTZUcJ0; passport_csrf_token=1eabf80454b58d818bbd5ebfe7389dc0; passport_csrf_token_default=1eabf80454b58d818bbd5ebfe7389dc0; passport_mfa_token=Cjjuuwap1TfSZ0WTSTsUQGFc1MHygzDpxCWVSC49B8xbNbsmfIQl1y7Cvk7WbavM5KkD6hfJGjFRgBpKCjwAAAAAAAAAAAAATxFIRXvKXzKiXRKEeaiM0kDzNkHHE%2FGOHyeOju5ikOgTvIa85nAh7S2dqRJq%2BgCXU2gQsITzDRj2sdFsIAIiAQNoDHJH; d_ticket=50db36b9c4704d170d98d22fc42d0962bc1f4; n_mh=4Yh99OVF3mj2MOpbnhh46c2zJ3k4mV7y6c5D5Pr85iE; _gcl_aw=GCL.1749008627.Cj0KCQjwuvrBBhDcARIsAKRrkjey6zRaDAFAoLejnMzYKhgMmcoFKHZ4jqwvewbEzgWs8sZT4l3JsDkaAn8LEALw_wcB; _gcl_gs=2.1.k1$i1749008624$u91292815; ttcid=a0f76b09ec1c4c21ad23bd63ab62580f36; passport_auth_status=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; passport_auth_status_ss=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; uid_tt=0fc2d4822867dbfea63c93d7338deb83; uid_tt_ss=0fc2d4822867dbfea63c93d7338deb83; sid_tt=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid_ss=d2be5b7a33551f7cf5fee96c75f0ec67; sid_guard=d2be5b7a33551f7cf5fee96c75f0ec67%7C1749971799%7C5183999%7CThu%2C+14-Aug-2025+07%3A16%3A38+GMT; sid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; ssid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; gd_random=eyJtYXRjaCI6dHJ1ZSwicGVyY2VudCI6MC4yMDYyMTE0Nzg2OTMzODM3NH0=.sMDzJBBGUXMiY77gzcEPXXeCNNAht8I5FegJ9L6N1jg=; i18next=zh; ttwid=1%7CIPjQ87CLus7PgbcIJOdwauMrQqsEavFGm6QrH14LF8w%7C1750482832%7Cd2babf076500e721930841ca0ee2737a12509b9284221143c4a3f36e62d03511; flow_ssr_sidebar_expand=1; passport_fe_beating_status=true; msToken=0Heq33Mb_YHd_1Uj21WuGnMsZI2nOTVhPAy7zrkStLr3CR27FrgZ7V2vd9C1B1fD1ksfsgukr6RszpbjR08DrTqdJMXYWYoiWtYdV36pU80vvrEj5jFVkY4D_s9q1jPf8ww=; tt_scid=5tRqex40-nJvFH59GfANqBbrdZEHHVk5d1QPDqIV7dc4JFgIqtKI6wEfTRHf2IYhaa2c; _ga_G8EP5CG8VZ=GS2.1.s1750482834$o45$g1$t1750482842$j52$l0$h0", 4 | "device_id": "7516071569933567528", 5 | "tea_uuid": "7516071593681045002", 6 | "web_id": "7516071593681045002", 7 | "room_id": "9005407235430914", 8 | "x_flow_trace": "04-00159877ca32df15001cff3dd24dff79-001fe74e159a7db1-01" 9 | } 10 | ] -------------------------------------------------------------------------------- /.history/session_20250621131549.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "cookie": "is_staff_user=false; store-region=cn-ah; store-region-src=uid; _ga=GA1.1.895357759.1742196011; s_v_web_id=verify_mbf4a7l3_1MHruucg_CkdA_4Cuj_8RbG_8nYLexTZUcJ0; passport_csrf_token=1eabf80454b58d818bbd5ebfe7389dc0; passport_csrf_token_default=1eabf80454b58d818bbd5ebfe7389dc0; passport_mfa_token=Cjjuuwap1TfSZ0WTSTsUQGFc1MHygzDpxCWVSC49B8xbNbsmfIQl1y7Cvk7WbavM5KkD6hfJGjFRgBpKCjwAAAAAAAAAAAAATxFIRXvKXzKiXRKEeaiM0kDzNkHHE%2FGOHyeOju5ikOgTvIa85nAh7S2dqRJq%2BgCXU2gQsITzDRj2sdFsIAIiAQNoDHJH; d_ticket=50db36b9c4704d170d98d22fc42d0962bc1f4; n_mh=4Yh99OVF3mj2MOpbnhh46c2zJ3k4mV7y6c5D5Pr85iE; _gcl_aw=GCL.1749008627.Cj0KCQjwuvrBBhDcARIsAKRrkjey6zRaDAFAoLejnMzYKhgMmcoFKHZ4jqwvewbEzgWs8sZT4l3JsDkaAn8LEALw_wcB; _gcl_gs=2.1.k1$i1749008624$u91292815; ttcid=a0f76b09ec1c4c21ad23bd63ab62580f36; passport_auth_status=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; passport_auth_status_ss=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; uid_tt=0fc2d4822867dbfea63c93d7338deb83; uid_tt_ss=0fc2d4822867dbfea63c93d7338deb83; sid_tt=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid_ss=d2be5b7a33551f7cf5fee96c75f0ec67; sid_guard=d2be5b7a33551f7cf5fee96c75f0ec67%7C1749971799%7C5183999%7CThu%2C+14-Aug-2025+07%3A16%3A38+GMT; sid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; ssid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; gd_random=eyJtYXRjaCI6dHJ1ZSwicGVyY2VudCI6MC4yMDYyMTE0Nzg2OTMzODM3NH0=.sMDzJBBGUXMiY77gzcEPXXeCNNAht8I5FegJ9L6N1jg=; i18next=zh; ttwid=1%7CIPjQ87CLus7PgbcIJOdwauMrQqsEavFGm6QrH14LF8w%7C1750482832%7Cd2babf076500e721930841ca0ee2737a12509b9284221143c4a3f36e62d03511; flow_ssr_sidebar_expand=1; passport_fe_beating_status=true; msToken=0Heq33Mb_YHd_1Uj21WuGnMsZI2nOTVhPAy7zrkStLr3CR27FrgZ7V2vd9C1B1fD1ksfsgukr6RszpbjR08DrTqdJMXYWYoiWtYdV36pU80vvrEj5jFVkY4D_s9q1jPf8ww=; tt_scid=5tRqex40-nJvFH59GfANqBbrdZEHHVk5d1QPDqIV7dc4JFgIqtKI6wEfTRHf2IYhaa2c; _ga_G8EP5CG8VZ=GS2.1.s1750482834$o45$g1$t1750482842$j52$l0$h0", 4 | "device_id": "7516071569933567528", 5 | "tea_uuid": "7516071593681045002", 6 | "web_id": "7516071593681045002", 7 | "room_id": "9546235609443330", 8 | "x_flow_trace": "04-00159877ca32df15001cff3dd24dff79-001fe74e159a7db1-01" 9 | } 10 | ] -------------------------------------------------------------------------------- /.history/session_20250621131558.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "cookie": "is_staff_user=false; store-region=cn-ah; store-region-src=uid; _ga=GA1.1.895357759.1742196011; s_v_web_id=verify_mbf4a7l3_1MHruucg_CkdA_4Cuj_8RbG_8nYLexTZUcJ0; passport_csrf_token=1eabf80454b58d818bbd5ebfe7389dc0; passport_csrf_token_default=1eabf80454b58d818bbd5ebfe7389dc0; passport_mfa_token=Cjjuuwap1TfSZ0WTSTsUQGFc1MHygzDpxCWVSC49B8xbNbsmfIQl1y7Cvk7WbavM5KkD6hfJGjFRgBpKCjwAAAAAAAAAAAAATxFIRXvKXzKiXRKEeaiM0kDzNkHHE%2FGOHyeOju5ikOgTvIa85nAh7S2dqRJq%2BgCXU2gQsITzDRj2sdFsIAIiAQNoDHJH; d_ticket=50db36b9c4704d170d98d22fc42d0962bc1f4; n_mh=4Yh99OVF3mj2MOpbnhh46c2zJ3k4mV7y6c5D5Pr85iE; _gcl_aw=GCL.1749008627.Cj0KCQjwuvrBBhDcARIsAKRrkjey6zRaDAFAoLejnMzYKhgMmcoFKHZ4jqwvewbEzgWs8sZT4l3JsDkaAn8LEALw_wcB; _gcl_gs=2.1.k1$i1749008624$u91292815; ttcid=a0f76b09ec1c4c21ad23bd63ab62580f36; passport_auth_status=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; passport_auth_status_ss=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; uid_tt=0fc2d4822867dbfea63c93d7338deb83; uid_tt_ss=0fc2d4822867dbfea63c93d7338deb83; sid_tt=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid_ss=d2be5b7a33551f7cf5fee96c75f0ec67; sid_guard=d2be5b7a33551f7cf5fee96c75f0ec67%7C1749971799%7C5183999%7CThu%2C+14-Aug-2025+07%3A16%3A38+GMT; sid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; ssid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; gd_random=eyJtYXRjaCI6dHJ1ZSwicGVyY2VudCI6MC4yMDYyMTE0Nzg2OTMzODM3NH0=.sMDzJBBGUXMiY77gzcEPXXeCNNAht8I5FegJ9L6N1jg=; i18next=zh; ttwid=1%7CIPjQ87CLus7PgbcIJOdwauMrQqsEavFGm6QrH14LF8w%7C1750482832%7Cd2babf076500e721930841ca0ee2737a12509b9284221143c4a3f36e62d03511; flow_ssr_sidebar_expand=1; passport_fe_beating_status=true; msToken=0Heq33Mb_YHd_1Uj21WuGnMsZI2nOTVhPAy7zrkStLr3CR27FrgZ7V2vd9C1B1fD1ksfsgukr6RszpbjR08DrTqdJMXYWYoiWtYdV36pU80vvrEj5jFVkY4D_s9q1jPf8ww=; tt_scid=5tRqex40-nJvFH59GfANqBbrdZEHHVk5d1QPDqIV7dc4JFgIqtKI6wEfTRHf2IYhaa2c; _ga_G8EP5CG8VZ=GS2.1.s1750482834$o45$g1$t1750482842$j52$l0$h0", 4 | "device_id": "7516071569933567528", 5 | "tea_uuid": "7516071593681045002", 6 | "web_id": "7516071593681045002", 7 | "room_id": "9546235609443330", 8 | "x_flow_trace": "04-00184fbac0cd2363000a6611f087fc29-000a6a5c305423c5-01" 9 | } 10 | ] -------------------------------------------------------------------------------- /.history/session_20250621131505.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "cookie": " 4 | is_staff_user=false; store-region=cn-ah; store-region-src=uid; _ga=GA1.1.895357759.1742196011; s_v_web_id=verify_mbf4a7l3_1MHruucg_CkdA_4Cuj_8RbG_8nYLexTZUcJ0; passport_csrf_token=1eabf80454b58d818bbd5ebfe7389dc0; passport_csrf_token_default=1eabf80454b58d818bbd5ebfe7389dc0; passport_mfa_token=Cjjuuwap1TfSZ0WTSTsUQGFc1MHygzDpxCWVSC49B8xbNbsmfIQl1y7Cvk7WbavM5KkD6hfJGjFRgBpKCjwAAAAAAAAAAAAATxFIRXvKXzKiXRKEeaiM0kDzNkHHE%2FGOHyeOju5ikOgTvIa85nAh7S2dqRJq%2BgCXU2gQsITzDRj2sdFsIAIiAQNoDHJH; d_ticket=50db36b9c4704d170d98d22fc42d0962bc1f4; n_mh=4Yh99OVF3mj2MOpbnhh46c2zJ3k4mV7y6c5D5Pr85iE; _gcl_aw=GCL.1749008627.Cj0KCQjwuvrBBhDcARIsAKRrkjey6zRaDAFAoLejnMzYKhgMmcoFKHZ4jqwvewbEzgWs8sZT4l3JsDkaAn8LEALw_wcB; _gcl_gs=2.1.k1$i1749008624$u91292815; ttcid=a0f76b09ec1c4c21ad23bd63ab62580f36; passport_auth_status=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; passport_auth_status_ss=d1fd7df7b3abbdb44452de80b3818324%2Cd98deb9cead17a86e8620cd912c34341; uid_tt=0fc2d4822867dbfea63c93d7338deb83; uid_tt_ss=0fc2d4822867dbfea63c93d7338deb83; sid_tt=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid=d2be5b7a33551f7cf5fee96c75f0ec67; sessionid_ss=d2be5b7a33551f7cf5fee96c75f0ec67; sid_guard=d2be5b7a33551f7cf5fee96c75f0ec67%7C1749971799%7C5183999%7CThu%2C+14-Aug-2025+07%3A16%3A38+GMT; sid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; ssid_ucp_v1=1.0.0-KGZhOWJmODUyNjcyYTU5ZmY1M2RhOWE2ZmI2MzdkNzA0MGY0ZTAyM2EKGAjQ3LDDgc2BBxDX5rnCBhjCsR44AkDxBxoCbGYiIGQyYmU1YjdhMzM1NTFmN2NmNWZlZTk2Yzc1ZjBlYzY3; gd_random=eyJtYXRjaCI6dHJ1ZSwicGVyY2VudCI6MC4yMDYyMTE0Nzg2OTMzODM3NH0=.sMDzJBBGUXMiY77gzcEPXXeCNNAht8I5FegJ9L6N1jg=; i18next=zh; ttwid=1%7CIPjQ87CLus7PgbcIJOdwauMrQqsEavFGm6QrH14LF8w%7C1750482832%7Cd2babf076500e721930841ca0ee2737a12509b9284221143c4a3f36e62d03511; flow_ssr_sidebar_expand=1; passport_fe_beating_status=true; msToken=0Heq33Mb_YHd_1Uj21WuGnMsZI2nOTVhPAy7zrkStLr3CR27FrgZ7V2vd9C1B1fD1ksfsgukr6RszpbjR08DrTqdJMXYWYoiWtYdV36pU80vvrEj5jFVkY4D_s9q1jPf8ww=; tt_scid=5tRqex40-nJvFH59GfANqBbrdZEHHVk5d1QPDqIV7dc4JFgIqtKI6wEfTRHf2IYhaa2c; _ga_G8EP5CG8VZ=GS2.1.s1750482834$o45$g1$t1750482842$j52$l0$h0", 5 | "device_id": "7516071569933567528", 6 | "tea_uuid": "7516071593681045002", 7 | "web_id": "7516071593681045002", 8 | "room_id": "9005407235430914", 9 | "x_flow_trace": "04-00159877ca32df15001cff3dd24dff79-001fe74e159a7db1-01" 10 | } 11 | ] -------------------------------------------------------------------------------- /src/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 豆包API聊天界面 7 | 8 | 9 | 10 | 11 |
12 | 27 | 28 |
29 |
30 |

新会话

31 |
32 | 33 |
34 |
35 | 36 |
37 |
38 |

欢迎使用豆包API聊天界面

39 |

开始一个新的对话或从侧边栏选择已有会话

40 |
41 | 42 |
43 | 44 |
45 |
46 |
47 | 50 | 53 |
54 |
55 |
56 | 57 | 58 |
59 |
60 |
61 |
62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /.history/src/templates/index_20250621140711.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 豆包API聊天界面 7 | 8 | 9 | 10 | 11 |
12 | 27 | 28 |
29 |
30 |

新会话

31 |
32 | 33 |
34 |
35 | 36 |
37 |
38 |

欢迎使用豆包API聊天界面

39 |

开始一个新的对话或从侧边栏选择已有会话

40 |
41 | 42 |
43 | 44 |
45 |
46 |
47 | 50 | 53 |
54 |
55 |
56 | 57 | 58 |
59 |
60 |
61 |
62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /.history/src/templates/index_20250615145302.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 豆包API聊天界面 7 | 8 | 9 | 10 | 11 |
12 | 27 | 28 |
29 |
30 |

新会话

31 |
32 | 33 |
34 |
35 | 36 |
37 |
38 |

欢迎使用豆包API聊天界面

39 |

开始一个新的对话或从侧边栏选择已有会话

40 |
41 | 42 |
43 | 44 |
45 |
46 | 50 |
51 | 54 | 57 |
58 |
59 |
60 | 61 | 62 |
63 |
64 | 65 |
66 |
67 |
68 |
69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/pool/fetcher.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import urllib.parse 3 | from playwright.async_api import async_playwright 4 | 5 | 6 | class DoubaoAutomator: 7 | 8 | async def capture_request(self, request): 9 | """捕获请求信息""" 10 | # 只捕获API相关的请求 11 | if 'https://www.doubao.com/samantha/chat/completion' in request.url: 12 | # 解析URL参数 13 | url_parts = urllib.parse.urlparse(request.url) 14 | query_params = dict(urllib.parse.parse_qsl(url_parts.query)) 15 | 16 | # 提取所需参数 17 | headers = dict(request.headers) 18 | 19 | self.device_id = query_params.get('device_id') 20 | self.web_id = query_params.get('web_id') 21 | self.tea_uuid = self.web_id 22 | self.room_id = headers.get('referer', '').split("/", )[-1] 23 | self.x_flow_trace = headers.get('x-flow-trace', '') 24 | 25 | self.captured = True 26 | 27 | async def run_automation(self, message_text="你好,请介绍一下自己"): 28 | """运行自动化流程""" 29 | self.captured = False 30 | async with async_playwright() as p: 31 | # 启动浏览器 32 | browser = await p.chromium.launch( 33 | headless=False, # 设置为True可以无头模式运行 34 | args=['--disable-blink-features=AutomationControlled'] 35 | ) 36 | 37 | # 创建新页面 38 | page = await browser.new_page() 39 | 40 | # 设置用户代理 41 | await page.set_extra_http_headers({ 42 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' 43 | }) 44 | 45 | # 监听请求和响应 46 | page.on('request', self.capture_request) 47 | 48 | try: 49 | # 访问豆包网站 50 | print("正在访问 www.doubao.com...") 51 | await page.goto('https://www.doubao.com', wait_until='networkidle') 52 | 53 | # 等待页面加载完成 54 | print("等待页面加载...") 55 | await page.wait_for_load_state('networkidle') 56 | 57 | input_element = await page.wait_for_selector('textarea[data-testid="chat_input_input"]', timeout=5000) 58 | 59 | if input_element: 60 | # 输入文本 61 | await input_element.fill(message_text) 62 | 63 | # 尝试按回车键发送 64 | await input_element.press('Enter') 65 | print("已发送消息,等待响应...") 66 | 67 | # 等待请求被捕获或超时 68 | wait_time, max_wait_time = 0, 3 69 | while not self.captured and wait_time < max_wait_time: 70 | await asyncio.sleep(1) 71 | wait_time += 1 72 | print(f"等待请求捕获中... {wait_time}/{max_wait_time}秒") 73 | 74 | if self.captured: 75 | print("请求已成功捕获,等待响应完成...") 76 | cookies = await page.context.cookies() 77 | cookie_string = '; '.join([f"{c['name']}={c['value']}" for c in cookies]) 78 | self.cookie = cookie_string 79 | else: 80 | raise Exception(f"等待超时,未能捕获请求。请尝试增加等待时间或检查网络连接。") 81 | else: 82 | raise Exception("未找到输入框,尝试手动查看页面结构...") 83 | 84 | 85 | except Exception as e: 86 | raise Exception(f"自动化过程中出错: {e}") 87 | 88 | finally: 89 | await browser.close() 90 | 91 | return { 92 | "cookie": self.cookie, 93 | "device_id": self.device_id, 94 | "tea_uuid": self.tea_uuid, 95 | "web_id": self.web_id, 96 | "room_id": self.room_id, 97 | "x_flow_trace": self.x_flow_trace 98 | } 99 | -------------------------------------------------------------------------------- /src/pool/session_pool.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import random 4 | from pydantic import BaseModel 5 | from loguru import logger 6 | from .fetcher import DoubaoAutomator 7 | 8 | class DoubaoSession(BaseModel): 9 | """豆包API会话配置""" 10 | cookie: str 11 | device_id: str 12 | tea_uuid: str 13 | web_id: str 14 | room_id: str 15 | x_flow_trace: str 16 | 17 | def to_dict(self) -> dict[str, str]: 18 | """转换为字典""" 19 | return { 20 | "cookie": self.cookie, 21 | "device_id": self.device_id, 22 | "tea_uuid": self.tea_uuid, 23 | "web_id": self.web_id, 24 | "room_id": self.room_id, 25 | "x_flow_trace": self.x_flow_trace, 26 | } 27 | 28 | @classmethod 29 | def from_dict(cls, data: dict[str, str]) -> 'DoubaoSession': 30 | return cls(**data) 31 | 32 | 33 | class SessionPool: 34 | """豆包API会话池,管理多个账号配置""" 35 | def __init__(self, config_file: str = "session.json"): 36 | # conversation_id -> DoubaoSession 37 | self.session_map: dict[str, DoubaoSession] = {} 38 | self.auth_sessions: list[DoubaoSession] = [] 39 | self.guest_sessions: list[DoubaoSession] = [] 40 | self.config_file = config_file 41 | self.load_from_file() 42 | 43 | def create_session( 44 | self, 45 | guest: bool, 46 | cookie: str, 47 | device_id: str, 48 | tea_uuid: str, 49 | web_id: str, 50 | room_id: str, 51 | x_flow_trace: str 52 | ) -> DoubaoSession: 53 | """创建新会话配置""" 54 | session = DoubaoSession( 55 | cookie=cookie, 56 | device_id=device_id, 57 | tea_uuid=tea_uuid, 58 | web_id=web_id, 59 | room_id=room_id, 60 | x_flow_trace=x_flow_trace 61 | ) 62 | if guest: 63 | self.guest_sessions.append(session) 64 | else: 65 | self.auth_sessions.append(session) 66 | 67 | def get_session(self, conversation_id: str | None = None, guest: bool = False) -> DoubaoSession: 68 | """获取会话配置,如果不存在则随机""" 69 | if conversation_id is None: 70 | if guest: 71 | return random.choice(self.guest_sessions) if self.guest_sessions else None 72 | else: 73 | return random.choice(self.auth_sessions) if self.auth_sessions else None 74 | else: 75 | return self.session_map.get(conversation_id) 76 | 77 | def set_session(self, conversation_id: str, session: DoubaoSession): 78 | """将会话与conversation_id关联""" 79 | self.session_map[conversation_id] = session 80 | 81 | def del_session(self, session: DoubaoSession): 82 | """删除会话""" 83 | if session.is_logged: 84 | self.auth_sessions.remove(session) 85 | else: 86 | self.guest_sessions.remove(session) 87 | self.save_to_file() 88 | 89 | def save_to_file(self): 90 | """保存会话配置到文件""" 91 | try: 92 | data = [session.to_dict() for session in (self.auth_sessions + self.guest_sessions)] 93 | with open(self.config_file, 'w', encoding='utf-8') as f: 94 | json.dump(data, f, ensure_ascii=False, indent=4) 95 | logger.debug(f"会话配置已保存到文件: {self.config_file}") 96 | except Exception as e: 97 | logger.error(f"保存会话配置到文件失败: {str(e)}") 98 | 99 | def load_from_file(self): 100 | """从文件加载会话配置""" 101 | if not os.path.exists(self.config_file): 102 | return logger.warning(f"会话配置文件不存在: {self.config_file}") 103 | 104 | try: 105 | with open(self.config_file, 'r', encoding='utf-8') as f: 106 | data = json.load(f) 107 | 108 | for session_data in data: 109 | self.create_session(guest=False, **session_data) 110 | 111 | logger.info(f"已从文件加载会话配置") 112 | except Exception as e: 113 | logger.error(f"从文件加载会话配置失败: {str(e)}") 114 | 115 | async def fetch_guest_session(self, num: int): 116 | for _ in range(num): 117 | automator = DoubaoAutomator() 118 | self.create_session( 119 | guest=True, 120 | **(await automator.run_automation()) 121 | ) 122 | 123 | 124 | session_pool = SessionPool() 125 | 126 | __all__ = [ 127 | "DoubaoSession", 128 | "SessionPool", 129 | "session_pool" 130 | ] -------------------------------------------------------------------------------- /.history/README_20250615182852.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | - 打开浏览器(推荐Chrome或Edge) 51 | - 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | - 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | - 随意发送一条消息给豆包 54 | - 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141103.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | - 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | - 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | - 随意发送一条消息给豆包 54 | - 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141104.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | - 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | - 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | - 随意发送一条消息给豆包 54 | - 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141108.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | - 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | - 随意发送一条消息给豆包 54 | - 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141113.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141114.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141135.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141134.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. tea_uuid 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141137.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. tea_uuid 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141138.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. tea_uuid和 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141140.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`和 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141147.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`, 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141149.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`, 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141150.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`,device_id 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141152.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`,device_id, 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141157.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`,device_id,web_id 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141313.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包**Payload**中 54 | 5. `tea_uuid`,`device_id`,`web_id`位于请求的Params里, `cookie`和`x_flow_trace`位于请求的**Headers**中 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141316.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包**Payload**中 54 | 5. `tea_uuid`,`device_id`,`web_id`位于请求的Params里, `cookie`和`x_flow_trace`位于请求的**Headers**中, `` 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141158.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`,device_id,`web_id` 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141200.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`,`device_id`,`web_id` 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141202.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`,`device_id`,`web_id`位于 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141204.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`,`device_id`,`web_id`位于请求的 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141325.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包**Payload**中 54 | 5. `tea_uuid`,`device_id`,`web_id`位于请求的Params里, `cookie`和`x_flow_trace`位于请求的**Headers**中, `room_id` 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141327.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包**Payload**中 54 | 5. `tea_uuid`,`device_id`,`web_id`位于请求的Params里, `cookie`和`x_flow_trace`位于请求的**Headers**中, `room_id`位于 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141329.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包**Payload**中 54 | 5. `tea_uuid`,`device_id`,`web_id`位于请求的Params里, `cookie`和`x_flow_trace`位于请求的**Headers**中, `room_id`位于 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | -------------------------------------------------------------------------------- /.history/README_20250621141207.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包 54 | 5. 在网络请求中找到`completions`相关请求, 参数位于**请求头**、**Cookies**、**Payload**中 55 | 6. `tea_uuid`,`device_id`,`web_id`位于请求的Params 56 | 57 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 58 | 59 | ### 上手指南 60 | 61 | #### 开发前的配置要求 62 | 63 | 1. Python 3.8+ 64 | 2. pip 或 uv 包管理工具 65 | 3. 豆包平台账号(用于获取API访问凭证) 66 | 67 | #### 安装步骤 68 | 69 | 1. 克隆代码库 70 | ```sh 71 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 72 | cd DoubaoFreeApi 73 | ``` 74 | 75 | 2. 安装虚拟环境以及依赖 76 | ```sh 77 | uv init 78 | uv venv venv 79 | uv pip install -r requirements.txt 80 | ``` 81 | 82 | 3. 配置环境变量 83 | ```sh 84 | # 复制示例环境变量文件 85 | cp example.session.json session.json 86 | # 编辑 session.json 文件,填入豆包平台的相关凭证 87 | ``` 88 | 89 | 4. 启动服务 90 | ```sh 91 | uv run app.py 92 | ``` 93 | 94 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 95 | 96 | ### 项目结构 97 | 98 | ``` 99 | DoubaoFreeApi 100 | ├── README.md # 项目说明文档 101 | ├── requirements.txt # 项目依赖 102 | ├── example.session.json# 环境变量示例 103 | ├── app.py # 应用入口 104 | └── /src/ # 源代码目录 105 | ├── config.py # 配置管理 106 | ├── /api/ # API路由 107 | ├── /model/ # 数据模型 108 | └── /service/ # 业务逻辑服务 109 | └── /pool/ # Session 池 110 | ``` 111 | 112 | ### 前端界面 113 | 114 |

115 | API文档 116 |

117 | 118 | 119 | ### 开发文档 120 | 121 |

122 | API文档 123 |

124 | 125 | #### API 接口 126 | 127 | 本项目基于FastAPI框架开发,提供了以下API接口: 128 | 129 | 1. **聊天接口** 130 | 131 | - **POST** `/api/chat/completions` 132 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 133 | - **请求参数**: 134 | ```json 135 | { 136 | "prompt": "用户输入的消息", 137 | "guest": false, 138 | "attachments": [ 139 | { 140 | "key": "文件标识符", 141 | "name": "文件名称", 142 | "type": "文件类型", 143 | "file_review_state": 3, 144 | "file_parse_state": 3, 145 | "identifier": "唯一标识符" 146 | } 147 | ], 148 | "conversation_id": "0", // 新聊天使用"0" 149 | "section_id": null, // 新聊天为null 150 | "use_auto_cot": false, // 自动选择深度思考 151 | "use_deep_think": false // 深度思考 152 | } 153 | ``` 154 | - **响应**: 155 | ```json 156 | { 157 | "text": "AI回复内容", 158 | "img_urls": ["图片URL列表"], 159 | "conversation_id": "会话ID", 160 | "messageg_id": "消息ID", 161 | "section_id": "段落ID" 162 | } 163 | ``` 164 | - **说明**: 165 | - 如果是新聊天,conversation_id, section_id不填 166 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 167 | - 如果使用游客账号,那么不支持上下文 168 | 169 | - **POST** `/api/chat/delete` 170 | - **功能**:删除聊天会话 171 | - **请求参数**:`conversation_id` (Query参数) 172 | - **响应**: 173 | ```json 174 | { 175 | "ok": true, 176 | "msg": "成功信息" 177 | } 178 | ``` 179 | - **说明**: 180 | - conversation_id不存在也会提示成功 181 | - 建议在聊天结束时调用此接口,避免创建过多对话 182 | 183 | 2. **文件接口** 184 | 185 | - **POST** `/api/file/upload` 186 | - **功能**:上传图片或文件到豆包服务器 187 | - **请求参数**: 188 | - `file_type`: 文件类型 (Query参数) 189 | - `file_name`: 文件名称 (Query参数) 190 | - `file_bytes`: 文件二进制内容 (Body) 191 | - **响应**: 192 | ```json 193 | { 194 | "key": "文件标识符", 195 | "name": "文件名称", 196 | "type": "文件类型", 197 | "file_review_state": 3, 198 | "file_parse_state": 3, 199 | "identifier": "唯一标识符", 200 | "option": {}, 201 | "md5": "文件MD5值", 202 | "size": 文件大小 203 | } 204 | ``` 205 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 206 | 207 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 208 | 209 | #### 贡献指南 210 | 211 | 1. 代码风格遵循PEP 8规范 212 | 2. 提交PR前请确保代码通过测试 213 | 3. 新功能请先创建issue讨论 214 | 215 | 216 | ### 版权说明 217 | 218 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 219 | 220 | ### 鸣谢 221 | 222 | 223 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 224 | 225 | 226 | 227 | 228 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 229 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 230 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 231 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 232 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 233 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 234 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 235 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 236 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 237 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 238 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 239 | -------------------------------------------------------------------------------- /.history/README_20250621141331.md: -------------------------------------------------------------------------------- 1 | # Doubao Free API 2 | 3 | 一个轻量级豆包API代理服务 4 | 5 | 6 | 7 | [![Contributors][contributors-shield]][contributors-url] 8 | [![Forks][forks-shield]][forks-url] 9 | [![Stargazers][stars-shield]][stars-url] 10 | [![Issues][issues-shield]][issues-url] 11 | [![MIT License][license-shield]][license-url] 12 | 13 | 14 |
15 | 16 |

17 | 18 | Logo 19 | 20 | 21 |

Doubao Free API

22 |

23 | 一个轻量级豆包API代理服务 24 |
25 | 探索本项目的文档 » 26 |
27 |
28 | 查看Demo 29 | · 30 | 报告Bug 31 | · 32 | 提出新特性 33 |

34 | 35 |

36 | 37 | ## 近期更新 38 | 1. 适配新版本豆包,在`/api/chat/completions`接口中可以选择是否打开深度思考 39 | 2. 支持游客模式下对话,但是**没有上下文** 40 | 3. 实现简易 Session 池,可以在session.json中添加登录账户的 Session,在app.py中获取未登录 Session 41 | 4. 实现了简易的前端对话界面 42 | 43 | ### TODO 44 | 45 | - [ ] 实现未登录状态下携带上下文信息(目前,如果在未登录状态下写到conversation_id,返回500错误) 46 | 47 | ### 如何抓取豆包配置 48 | 49 | 要使用本项目,您需要抓取豆包网页版的相关配置信息。以下是抓取方法: 50 | 1. 打开浏览器(推荐Chrome或Edge) 51 | 2. 访问豆包网页版 [豆包](https://www.doubao.com) 并登录 52 | 3. 按F12打开开发者工具,切换到"网络"(Network)选项卡 53 | 4. 随意发送一条消息给豆包**Payload**中 54 | 5. `tea_uuid`,`device_id`,`web_id`位于请求的Params里, `cookie`和`x_flow_trace`位于请求的**Headers**中, `room_id`位于浏览器 55 | 56 | > **注意**: 这些配置信息有时效性,可能需要定期更新。请勿分享您的个人配置信息。 57 | 58 | ### 上手指南 59 | 60 | #### 开发前的配置要求 61 | 62 | 1. Python 3.8+ 63 | 2. pip 或 uv 包管理工具 64 | 3. 豆包平台账号(用于获取API访问凭证) 65 | 66 | #### 安装步骤 67 | 68 | 1. 克隆代码库 69 | ```sh 70 | git clone https://github.com/XilyFeAAAA/DoubaoFreeApi.git 71 | cd DoubaoFreeApi 72 | ``` 73 | 74 | 2. 安装虚拟环境以及依赖 75 | ```sh 76 | uv init 77 | uv venv venv 78 | uv pip install -r requirements.txt 79 | ``` 80 | 81 | 3. 配置环境变量 82 | ```sh 83 | # 复制示例环境变量文件 84 | cp example.session.json session.json 85 | # 编辑 session.json 文件,填入豆包平台的相关凭证 86 | ``` 87 | 88 | 4. 启动服务 89 | ```sh 90 | uv run app.py 91 | ``` 92 | 93 | 服务默认运行在 `http://localhost:8000`,API文档可访问 `http://localhost:8000/docs` 94 | 95 | ### 项目结构 96 | 97 | ``` 98 | DoubaoFreeApi 99 | ├── README.md # 项目说明文档 100 | ├── requirements.txt # 项目依赖 101 | ├── example.session.json# 环境变量示例 102 | ├── app.py # 应用入口 103 | └── /src/ # 源代码目录 104 | ├── config.py # 配置管理 105 | ├── /api/ # API路由 106 | ├── /model/ # 数据模型 107 | └── /service/ # 业务逻辑服务 108 | └── /pool/ # Session 池 109 | ``` 110 | 111 | ### 前端界面 112 | 113 |

114 | API文档 115 |

116 | 117 | 118 | ### 开发文档 119 | 120 |

121 | API文档 122 |

123 | 124 | #### API 接口 125 | 126 | 本项目基于FastAPI框架开发,提供了以下API接口: 127 | 128 | 1. **聊天接口** 129 | 130 | - **POST** `/api/chat/completions` 131 | - **功能**:豆包聊天补全接口(目前仅支持文字消息和图片消息) 132 | - **请求参数**: 133 | ```json 134 | { 135 | "prompt": "用户输入的消息", 136 | "guest": false, 137 | "attachments": [ 138 | { 139 | "key": "文件标识符", 140 | "name": "文件名称", 141 | "type": "文件类型", 142 | "file_review_state": 3, 143 | "file_parse_state": 3, 144 | "identifier": "唯一标识符" 145 | } 146 | ], 147 | "conversation_id": "0", // 新聊天使用"0" 148 | "section_id": null, // 新聊天为null 149 | "use_auto_cot": false, // 自动选择深度思考 150 | "use_deep_think": false // 深度思考 151 | } 152 | ``` 153 | - **响应**: 154 | ```json 155 | { 156 | "text": "AI回复内容", 157 | "img_urls": ["图片URL列表"], 158 | "conversation_id": "会话ID", 159 | "messageg_id": "消息ID", 160 | "section_id": "段落ID" 161 | } 162 | ``` 163 | - **说明**: 164 | - 如果是新聊天,conversation_id, section_id不填 165 | - 如果沿用之前的聊天,则使用第一次对话返回的conversation_id和section_id 166 | - 如果使用游客账号,那么不支持上下文 167 | 168 | - **POST** `/api/chat/delete` 169 | - **功能**:删除聊天会话 170 | - **请求参数**:`conversation_id` (Query参数) 171 | - **响应**: 172 | ```json 173 | { 174 | "ok": true, 175 | "msg": "成功信息" 176 | } 177 | ``` 178 | - **说明**: 179 | - conversation_id不存在也会提示成功 180 | - 建议在聊天结束时调用此接口,避免创建过多对话 181 | 182 | 2. **文件接口** 183 | 184 | - **POST** `/api/file/upload` 185 | - **功能**:上传图片或文件到豆包服务器 186 | - **请求参数**: 187 | - `file_type`: 文件类型 (Query参数) 188 | - `file_name`: 文件名称 (Query参数) 189 | - `file_bytes`: 文件二进制内容 (Body) 190 | - **响应**: 191 | ```json 192 | { 193 | "key": "文件标识符", 194 | "name": "文件名称", 195 | "type": "文件类型", 196 | "file_review_state": 3, 197 | "file_parse_state": 3, 198 | "identifier": "唯一标识符", 199 | "option": {}, 200 | "md5": "文件MD5值", 201 | "size": 文件大小 202 | } 203 | ``` 204 | - **说明**:上传成功后可将返回的信息添加到聊天接口的attachments参数中 205 | 206 | 详细API文档可在服务启动后访问 `http://localhost:8000/docs` 查看。 207 | 208 | #### 贡献指南 209 | 210 | 1. 代码风格遵循PEP 8规范 211 | 2. 提交PR前请确保代码通过测试 212 | 3. 新功能请先创建issue讨论 213 | 214 | 215 | ### 版权说明 216 | 217 | 该项目签署了MIT 授权许可,详情请参阅 [LICENSE](https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE) 218 | 219 | ### 鸣谢 220 | 221 | 222 | - [Doubao-Image-Proxy](https://github.com/giaoimgiao/Doubao-Image-Proxy) 223 | 224 | 225 | 226 | 227 | [your-project-path]:https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/main/LICENSE 228 | [contributors-shield]: https://img.shields.io/github/contributors/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 229 | [contributors-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/graphs/contributors 230 | [forks-shield]: https://img.shields.io/github/forks/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 231 | [forks-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/network/members 232 | [stars-shield]: https://img.shields.io/github/stars/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 233 | [stars-url]: https://github.com/shaojintian/Best_README_template/stargazers 234 | [issues-shield]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 235 | [issues-url]: https://img.shields.io/github/issues/XilyFeAAAA/DoubaoFreeApi.svg 236 | [license-shield]: https://img.shields.io/github/license/XilyFeAAAA/DoubaoFreeApi.svg?style=flat-square 237 | [license-url]: https://github.com/XilyFeAAAA/DoubaoFreeApi/blob/master/LICENSE 238 | --------------------------------------------------------------------------------