# fly143/deepseek-free-api architecture

> Architecture diagram of the GitHub repository fly143/deepseek-free-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fly143/deepseek-free-api
- Repository: https://github.com/fly143/deepseek-free-api

## Overview

DeepSeek Free API Proxy turns DeepSeek’s web chat service into OpenAI- and Anthropic-compatible APIs. The main workflow accepts a client request, normalizes it, prepares the account/session and upstream request, then relays a response; supporting branches cover model discovery, file and image handling, tool calls, and Responses API lifecycle operations. The README documents these capabilities, while source excerpts and the SOURCE INDEX establish several internal dependencies. Some implementation details are unsampled, so uncertain links are omitted.

Main entry points: [`proxy.py`](https://github.com/fly143/deepseek-free-api/blob/main/proxy.py) (Chat handling), [`app/anthropic_routes.py`](https://github.com/fly143/deepseek-free-api/blob/main/app/anthropic_routes.py) (Messages routes), [`app/registrar.py`](https://github.com/fly143/deepseek-free-api/blob/main/app/registrar.py) (Account registration), [`tool_call.py`](https://github.com/fly143/deepseek-free-api/blob/main/tool_call.py) (Tool prompt building)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API surface"]
  node_proxy["API gateway<br/>[proxy.py]"]
  node_anthropic_routes["Messages routes"]
  node_anthropic_convert["Messages conversion<br/>[anthropic.py]"]
  node_batch["Batch API<br/>[batch.py]"]
  node_responses["Responses API<br/>[proxy.py]"]
  node_admin["Admin panel<br/>[proxy.py]"]
end

subgraph group_conversation["Conversation pipeline"]
  node_chat["Chat handling<br/>[proxy.py]"]
  node_models["Model discovery<br/>[proxy.py]"]
  node_files["File and image handling<br/>[proxy.py]"]
  node_context["Context trimming<br/>[context_manager.py]"]
  node_compression["Context compression"]
  node_tool_prompt["Tool prompt building<br/>[tool_call.py]"]
  node_tool_parser["DSML parsing<br/>[tool_dsml.py]"]
  node_tool_filter["Tool output filtering<br/>[tool_sieve.py]"]
end

subgraph group_account["Accounts and upstream"]
  node_accounts[("Account configuration<br/>[config.py]")]
  node_registration["Account registration<br/>[registrar.py]"]
  node_device_ids["Device ID pool<br/>[device_ids.py]"]
  node_pow["PoW solver<br/>[pow_native.py]"]
  node_upstream["DeepSeek API"]
end

subgraph group_state["State and context"]
  node_response_store[("Response storage<br/>[response_store.py]")]
  node_session_store[("Session tracking<br/>[session_store.py]")]
  node_usage_store[("Usage tracking<br/>[usage_store.py]")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_proxy
node_client -->|"sends messages"| node_anthropic_routes
node_proxy -->|"dispatches chat"| node_chat
node_proxy -->|"dispatches responses"| node_responses
node_proxy -->|"serves panel"| node_admin
node_anthropic_routes -->|"converts messages"| node_anthropic_convert
node_anthropic_routes -->|"calls chat"| node_chat
node_anthropic_routes -->|"uses batch"| node_batch
node_chat -->|"resolves model"| node_models
node_chat -->|"trims context"| node_context
node_chat -->|"compresses context"| node_compression
node_chat -->|"builds tool prompt"| node_tool_prompt
node_tool_prompt -->|"parses DSML"| node_tool_parser
node_chat -->|"filters stream"| node_tool_filter
node_chat -->|"uploads files"| node_files
node_chat -->|"loads account"| node_accounts
node_chat -->|"forwards HTTPS"| node_upstream
node_models -->|"probes models"| node_upstream
node_files -->|"uploads files"| node_upstream
node_accounts -.->|"configures accounts"| node_registration
node_registration -->|"selects device"| node_device_ids
node_registration -->|"solves challenge"| node_pow
node_registration -->|"registers account"| node_upstream
node_proxy -->|"solves challenges"| node_pow
node_proxy -->|"stores responses"| node_response_store
node_proxy -->|"tracks sessions"| node_session_store
node_proxy -->|"tracks usage"| node_usage_store

click node_proxy "https://github.com/fly143/deepseek-free-api/blob/main/proxy.py"
click node_anthropic_routes "https://github.com/fly143/deepseek-free-api/blob/main/app/anthropic_routes.py"
click node_anthropic_convert "https://github.com/fly143/deepseek-free-api/blob/main/app/anthropic.py"
click node_batch "https://github.com/fly143/deepseek-free-api/blob/main/app/batch.py"
click node_responses "https://github.com/fly143/deepseek-free-api/blob/main/proxy.py"
click node_admin "https://github.com/fly143/deepseek-free-api/blob/main/proxy.py"
click node_chat "https://github.com/fly143/deepseek-free-api/blob/main/proxy.py"
click node_models "https://github.com/fly143/deepseek-free-api/blob/main/proxy.py"
click node_files "https://github.com/fly143/deepseek-free-api/blob/main/proxy.py"
click node_context "https://github.com/fly143/deepseek-free-api/blob/main/context_manager.py"
click node_compression "https://github.com/fly143/deepseek-free-api/blob/main/context_compressor.py"
click node_tool_prompt "https://github.com/fly143/deepseek-free-api/blob/main/tool_call.py"
click node_tool_parser "https://github.com/fly143/deepseek-free-api/blob/main/tool_dsml.py"
click node_tool_filter "https://github.com/fly143/deepseek-free-api/blob/main/tool_sieve.py"
click node_accounts "https://github.com/fly143/deepseek-free-api/blob/main/app/config.py"
click node_registration "https://github.com/fly143/deepseek-free-api/blob/main/app/registrar.py"
click node_device_ids "https://github.com/fly143/deepseek-free-api/blob/main/app/device_ids.py"
click node_pow "https://github.com/fly143/deepseek-free-api/blob/main/pow_native.py"
click node_response_store "https://github.com/fly143/deepseek-free-api/blob/main/response_store.py"
click node_session_store "https://github.com/fly143/deepseek-free-api/blob/main/session_store.py"
click node_usage_store "https://github.com/fly143/deepseek-free-api/blob/main/usage_store.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_proxy,node_anthropic_routes,node_anthropic_convert,node_batch,node_responses,node_admin,node_client toneBlue
class node_chat,node_models,node_files,node_context,node_compression,node_tool_prompt,node_tool_parser,node_tool_filter toneAmber
class node_accounts,node_registration,node_device_ids,node_pow,node_upstream toneMint
class node_response_store,node_session_store,node_usage_store toneRose
```

## Components

### API surface

- [API gateway](https://github.com/fly143/deepseek-free-api/blob/main/proxy.py): `proxy.py`
- [Messages routes](https://github.com/fly143/deepseek-free-api/blob/main/app/anthropic_routes.py): `app/anthropic_routes.py`
- [Messages conversion](https://github.com/fly143/deepseek-free-api/blob/main/app/anthropic.py): `app/anthropic.py`
- [Batch API](https://github.com/fly143/deepseek-free-api/blob/main/app/batch.py): `app/batch.py`
- [Responses API](https://github.com/fly143/deepseek-free-api/blob/main/proxy.py): `proxy.py`
- [Admin panel](https://github.com/fly143/deepseek-free-api/blob/main/proxy.py): `proxy.py`

### Conversation pipeline

- [Chat handling](https://github.com/fly143/deepseek-free-api/blob/main/proxy.py): `proxy.py`
- [Model discovery](https://github.com/fly143/deepseek-free-api/blob/main/proxy.py): `proxy.py`
- [File and image handling](https://github.com/fly143/deepseek-free-api/blob/main/proxy.py): `proxy.py`
- [Context trimming](https://github.com/fly143/deepseek-free-api/blob/main/context_manager.py): `context_manager.py`
- [Context compression](https://github.com/fly143/deepseek-free-api/blob/main/context_compressor.py): `context_compressor.py`
- [Tool prompt building](https://github.com/fly143/deepseek-free-api/blob/main/tool_call.py): `tool_call.py`
- [DSML parsing](https://github.com/fly143/deepseek-free-api/blob/main/tool_dsml.py): `tool_dsml.py`
- [Tool output filtering](https://github.com/fly143/deepseek-free-api/blob/main/tool_sieve.py): `tool_sieve.py`

### Accounts and upstream

- [Account configuration](https://github.com/fly143/deepseek-free-api/blob/main/app/config.py): `app/config.py`
- [Account registration](https://github.com/fly143/deepseek-free-api/blob/main/app/registrar.py): `app/registrar.py`
- [Device ID pool](https://github.com/fly143/deepseek-free-api/blob/main/app/device_ids.py): `app/device_ids.py`
- [PoW solver](https://github.com/fly143/deepseek-free-api/blob/main/pow_native.py): `pow_native.py`
- **DeepSeek API**

### State and context

- [Response storage](https://github.com/fly143/deepseek-free-api/blob/main/response_store.py): `response_store.py`
- [Session tracking](https://github.com/fly143/deepseek-free-api/blob/main/session_store.py): `session_store.py`
- [Usage tracking](https://github.com/fly143/deepseek-free-api/blob/main/usage_store.py): `usage_store.py`

### Other components

- **API client**

## Connections

- API client → API gateway: sends requests (evidence: `README.md`)
- API client → Messages routes: sends messages (evidence: `README.md`)
- API gateway → Chat handling: dispatches chat (evidence: `proxy.py`)
- API gateway → Responses API: dispatches responses (evidence: `README.md`)
- API gateway → Admin panel: serves panel (evidence: `proxy.py`)
- Messages routes → Messages conversion: converts messages (evidence: `app/anthropic_routes.py`)
- Messages routes → Chat handling: calls chat (evidence: `app/anthropic_routes.py`)
- Messages routes → Batch API: uses batch (evidence: `app/anthropic_routes.py`)
- Chat handling → Model discovery: resolves model (evidence: `README.md`)
- Chat handling → Context trimming: trims context (evidence: `proxy.py`)
- Chat handling → Context compression: compresses context (evidence: `proxy.py`)
- Chat handling → Tool prompt building: builds tool prompt (evidence: `README.md`)
- Tool prompt building → DSML parsing: parses DSML (evidence: `tool_call.py`)
- Chat handling → Tool output filtering: filters stream (evidence: `README.md`)
- Chat handling → File and image handling: uploads files (evidence: `README.md`)
- Chat handling → Account configuration: loads account (evidence: `proxy.py`)
- Chat handling → DeepSeek API: forwards HTTPS (evidence: `README.md`)
- Model discovery → DeepSeek API: probes models (evidence: `README.md`)
- File and image handling → DeepSeek API: uploads files (evidence: `README.md`)
- Account configuration → Account registration: configures accounts (evidence: `app/registrar.py`)
- Account registration → Device ID pool: selects device (evidence: `app/registrar.py`)
- Account registration → PoW solver: solves challenge (evidence: `app/registrar.py`)
- Account registration → DeepSeek API: registers account (evidence: `app/registrar.py`)
- API gateway → PoW solver: solves challenges (evidence: `README.md`)
- API gateway → Response storage: stores responses (evidence: `proxy.py`)
- API gateway → Session tracking: tracks sessions (evidence: `proxy.py`)
- API gateway → Usage tracking: tracks usage (evidence: `proxy.py`)
