                                                                              
    ████████╗██╗  ██╗███████╗ ██████╗ ██╗     ██████╗ ██╗     ██╗     ███╗   ███╗
    ╚══██╔══╝██║  ██║██╔════╝██╔═══██╗██║     ██╔══██╗██║     ██║     ████╗ ████║
       ██║   ███████║█████╗  ██║   ██║██║     ██║  ██║██║     ██║     ██╔████╔██║
       ██║   ██╔══██║██╔══╝  ██║   ██║██║     ██║  ██║██║     ██║     ██║╚██╔╝██║
       ██║   ██║  ██║███████╗╚██████╔╝███████╗██████╔╝███████╗███████╗██║ ╚═╝ ██║
       ╚═╝   ╚═╝  ╚═╝╚══════╝ ╚═════╝ ╚══════╝╚═════╝ ╚══════╝╚══════╝╚═╝     ╚═╝
                                                                              
                      ██████╗ ██████╗  ██████╗ ██╗  ██╗██╗   ██╗
                      ██╔══██╗██╔══██╗██╔═══██╗╚██╗██╔╝╚██╗ ██╔╝
                      ██████╔╝██████╔╝██║   ██║ ╚███╔╝  ╚████╔╝ 
                      ██╔═══╝ ██╔══██╗██║   ██║ ██╔██╗   ╚██╔╝  
                      ██║     ██║  ██║╚██████╔╝██╔╝ ██╗   ██║   
                      ╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═╝   ╚═╝   
                                                                              
    ┌────────────────────────────────────────────────────────────────────────────────┐
    │                         » OpenAI-Compatible API Proxy «                        │
    │                                » Version 4.1.0 «                               │
    └────────────────────────────────────────────────────────────────────────────────┘


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                              » DESCRIPTION «                                   ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         This proxy server provides a high-performance, unified API interface for
         theoldllm.vercel.app. It streamlines access to all model families
         (GPT, Claude, Gemini, DeepSeek, GLM, Grok, etc.) via a single, optimized
         endpoint structure.

         ✨ VERSION 4.2.1 FEATURES:
         - Unified Architecture: All models route through P9/P8 providers.
         - Zero Configuration: No auth tokens, no browser scripts required.
         - High Performance: Fully optimized streaming for all models.
         - Thinking Model Support: Proper handling of reasoning/thinking models.
         - Multiple Output Modes: 10 different formatting options for thinking.
         - Extensive Library: Access to a huge variety of models.


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                              » REQUIREMENTS «                                  ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         ┌─────────────────────────────────────────────────────────────────┐
         │  ■ Python 3.10 or higher                                        │
         │  ■ Internet connection                                          │
         │  ■ pip install fastapi uvicorn httpx                            │
         └─────────────────────────────────────────────────────────────────┘


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                              » INSTALLATION «                                  ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         1. Install Python dependencies:

            pip install -r requirements.txt

         2. Run the server:

            python python_server.py

         3. Use the API at:

            http://localhost:8001/v1


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                         » ENVIRONMENT VARIABLES «                              ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         ┌─────────────────────────────────────────────────────────────────┐
         │  THINKING OUTPUT MODE                                           │
         └─────────────────────────────────────────────────────────────────┘

              THINKING_OUTPUT_MODE=tagged     # Default - <think></think> tags
              THINKING_OUTPUT_MODE=merged     # No separation
              THINKING_OUTPUT_MODE=hidden     # Hide thinking completely
              THINKING_OUTPUT_MODE=xml        # <reasoning></reasoning> tags
              THINKING_OUTPUT_MODE=markdown   # Blockquote format
              THINKING_OUTPUT_MODE=separated  # Horizontal rule separator
              THINKING_OUTPUT_MODE=labeled    # Emoji labels (💭/💬)
              THINKING_OUTPUT_MODE=details    # Collapsible HTML details
              THINKING_OUTPUT_MODE=brackets   # 【brackets】
              THINKING_OUTPUT_MODE=italics    # *italicized*

         ┌─────────────────────────────────────────────────────────────────┐
         │  OTHER SETTINGS                                                 │
         └─────────────────────────────────────────────────────────────────┘

              PORT=8001                        # Server port
              DEBUG_MODE=false                 # Enable debug logging
              REQUEST_TIMEOUT=300              # Request timeout in seconds
              THINKING_SEPARATOR="\n\n---\n\n" # Custom separator (separated mode)


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                         » SILLYTAVERN SETUP «                                  ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         ┌─────────────────────────────────────────────────────────────────┐
         │  IMPORTANT: ENABLE AUTO-PARSE FOR THINKING TAGS                 │
         └─────────────────────────────────────────────────────────────────┘

              For the <think></think> tags to display correctly in SillyTavern,
              you MUST enable the "Auto-Parse" option:

              1. Open SillyTavern
              2. Go to the Advanced Formatting panel (A icon)
              3. Find the "Auto-Parse" option
              4. Enable Auto-Parse in Reasoning
              5. Enjoy!

              Without this setting, thinking tags will appear as raw text
              instead of being properly formatted/collapsed.

         ┌─────────────────────────────────────────────────────────────────┐
         │  CONNECTION SETTINGS                                            │
         └─────────────────────────────────────────────────────────────────┘

              API Type: Chat Completion (OpenAI)
              Base URL: http://localhost:8001/v1
              API Key:  any-string (not validated)


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                           » AVAILABLE MODELS «                                 ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         ┌─────────────────────────────────────────────────────────────────┐
         │  GPT-5 SERIES                                                   │
         └─────────────────────────────────────────────────────────────────┘
              gpt-5.2 .................... GPT-5.2
              gpt-5.2-chat-latest ........ GPT-5.2 Chat Latest
              gpt-5.1 .................... GPT-5.1
              gpt-5.1-chat-latest ........ GPT-5.1 Chat Latest
              gpt-5 ...................... GPT-5
              gpt-5-mini ................. GPT-5 Mini
              gpt-5-nano ................. GPT-5 Nano
              gpt-5-chat ................. GPT-5 Chat
              gpt-5-chat-latest .......... GPT-5 Chat Latest

         ┌─────────────────────────────────────────────────────────────────┐
         │  OPENAI O-SERIES                                                │
         └─────────────────────────────────────────────────────────────────┘
              o4-mini .................... O4 Mini
              o3 ......................... O3
              o3-mini .................... O3 Mini
              o1 ......................... O1

         ┌─────────────────────────────────────────────────────────────────┐
         │  GPT-4 SERIES                                                   │
         └─────────────────────────────────────────────────────────────────┘
              gpt-4.1 .................... GPT-4.1
              gpt-4.1-mini ............... GPT-4.1 Mini
              gpt-4.1-nano ............... GPT-4.1 Nano
              gpt-4o ..................... GPT-4o
              gpt-4o-mini ................ GPT-4o Mini
              gpt-4o-search-preview ...... GPT-4o Search Preview
              gpt-4o-search-mini-preview . GPT-4o Search Mini
              gpt-4-turbo ................ GPT-4 Turbo
              gpt-4-turbo-preview ........ GPT-4 Turbo Preview
              gpt-4 ...................... GPT-4
              chatgpt-4o-latest .......... ChatGPT 4o Latest

         ┌─────────────────────────────────────────────────────────────────┐
         │  GPT-3.5 & OSS                                                  │
         └─────────────────────────────────────────────────────────────────┘
              gpt-3.5-turbo .............. GPT-3.5 Turbo
              gpt-oss-120b ............... GPT OSS 120B
              gpt-oss-20b ................ GPT OSS 20B

         ┌─────────────────────────────────────────────────────────────────┐
         │  CLAUDE OPUS                                                    │
         └─────────────────────────────────────────────────────────────────┘
              claude-opus-4.5 ............ Claude Opus 4.5
              claude-opus-4.1 ............ Claude Opus 4.1
              claude-opus-4 .............. Claude Opus 4

         ┌─────────────────────────────────────────────────────────────────┐
         │  CLAUDE SONNET                                                  │
         └─────────────────────────────────────────────────────────────────┘
              claude-sonnet-4.5 .......... Claude Sonnet 4.5
              claude-sonnet-4 ............ Claude Sonnet 4
              claude-3.7-sonnet .......... Claude 3.7 Sonnet
              claude-3.5-sonnet .......... Claude 3.5 Sonnet

         ┌─────────────────────────────────────────────────────────────────┐
         │  CLAUDE HAIKU & CLAUDE 3                                        │
         └─────────────────────────────────────────────────────────────────┘
              claude-haiku-4.5 ........... Claude Haiku 4.5
              claude-3.5-haiku ........... Claude 3.5 Haiku
              claude-3-opus .............. Claude 3 Opus
              claude-3-haiku ............. Claude 3 Haiku

         ┌─────────────────────────────────────────────────────────────────┐
         │  GOOGLE GEMINI                                                  │
         └─────────────────────────────────────────────────────────────────┘
              gemini-3-pro-preview ....... Gemini 3 Pro
              gemini-3-flash-preview ..... Gemini 3 Flash
              gemini-2.5-pro ............. Gemini 2.5 Pro          💭 (sometimes)
              gemini-2.5-flash ........... Gemini 2.5 Flash        💭 (sometimes)
              gemini-2.5-flash-lite ...... Gemini 2.5 Flash Lite
              gemini-2.0-flash ........... Gemini 2.0 Flash
              gemini-2.0-flash-001 ....... Gemini 2.0 Flash 001
              gemini-2.0-flash-lite ...... Gemini 2.0 Flash Lite
              gemini-2.0-flash-lite-001 .. Gemini 2.0 Flash Lite 001

         ┌─────────────────────────────────────────────────────────────────┐
         │  DEEPSEEK                                                       │
         └─────────────────────────────────────────────────────────────────┘
              deepseek-v3.1-terminus ..... DeepSeek V3.1 Terminus
              deepseek-v3.2 .............. DeepSeek V3.2
              deepseek-v3.1 .............. DeepSeek V3.1
              deepseek-r1 ................ DeepSeek R1             💭
              deepseek-r1-0528 ........... DeepSeek R1 (0528)      💭
              deepseek-prover-v2 ......... DeepSeek Prover V2      
              deepseek-r1t2-chimera:free . DeepSeek R1T2 Chimera   💭

         ┌─────────────────────────────────────────────────────────────────┐
         │  GLM (ZHIPU)                                                    │
         └─────────────────────────────────────────────────────────────────┘
              glm-4.7 .................... GLM-4.7                 💭
              glm-4.6 .................... GLM-4.6                 💭
              glm-4.5 .................... GLM-4.5                 💭
              glm-4.5-air ................ GLM-4.5 Air             💭
              glm-4.5-air:free ........... GLM-4.5 Air Free        💭

         ┌─────────────────────────────────────────────────────────────────┐
         │  GROK (xAI)                                                     │
         └─────────────────────────────────────────────────────────────────┘
              grok-4.1-fast .............. Grok 4.1 Fast
              grok-4 ..................... Grok 4
              grok-3 ..................... Grok 3                  
              grok-code-fast-1 ........... Grok Code Fast 1

         ┌─────────────────────────────────────────────────────────────────┐
         │  KIMI                                                           │
         └─────────────────────────────────────────────────────────────────┘
              kimi-k2-thinking ........... Kimi K2 Thinking        💭
              kimi-k2-instruct ........... Kimi K2 Instruct
              kimi-k2 .................... Kimi K2
              kimi-k2-0905 ............... Kimi K2 (0905)

         ┌─────────────────────────────────────────────────────────────────┐
         │  MISTRAL                                                        │
         └─────────────────────────────────────────────────────────────────┘
              mistral-nemotron ........... Mistral Nemotron
              mistral-nemo ............... Mistral Nemo
              devstral-2512:free ......... Devstral 2512

         ┌─────────────────────────────────────────────────────────────────┐
         │  QWEN                                                           │
         └─────────────────────────────────────────────────────────────────┘
              qwen3-235b-a22b-07-25 ...... Qwen 3 235B             
              qwen3-32b .................. Qwen 3 32B              💭
              qwen3-next-80b-thinking .... Qwen 3 80B Thinking     💭
              qwen3-next-80b-a3b-instruct  Qwen 3 80B Instruct

         ┌─────────────────────────────────────────────────────────────────┐
         │  MINIMAX / LLAMA                                                │
         └─────────────────────────────────────────────────────────────────┘
              minimax-m2 ................. MiniMax M2              💭
              llama-3.3-70b-instruct ..... Llama 3.3 70B

         ┌─────────────────────────────────────────────────────────────────┐
         │  💭 = THINKING MODEL (supports reasoning/chain-of-thought)      │
         └─────────────────────────────────────────────────────────────────┘


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                          » THINKING MODELS «                                   ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         Thinking models output their reasoning process before the final answer.
         This proxy automatically detects and formats this output based on your
         chosen THINKING_OUTPUT_MODE.

         ┌─────────────────────────────────────────────────────────────────┐
         │  SUPPORTED THINKING MODELS                                      │
         └─────────────────────────────────────────────────────────────────┘

              ■ Gemini 2.5 Pro / Flash
              ■ DeepSeek R1 / R1-0528 / R1T2 Chimera
              ■ GLM series
              ■ MiniMax M2
              ■ Kimi K2 Thinking
              ■ Qwen 3 (32B, 80B Thinking)

         ┌─────────────────────────────────────────────────────────────────┐
         │  OUTPUT EXAMPLES                                                │
         └─────────────────────────────────────────────────────────────────┘

              TAGGED (default):
              ┌──────────────────────────────────────────────────────────┐
              │ <think>                                                  │
              │ Let me analyze this step by step...                      │
              │ First, I need to consider...                             │
              │ </think>                                                 │
              │                                                          │
              │ Here is my answer based on my analysis.                  │
              └──────────────────────────────────────────────────────────┘

              LABELED:
              ┌──────────────────────────────────────────────────────────┐
              │ 💭 **Thinking:**                                         │
              │ Let me analyze this step by step...                      │
              │                                                          │
              │ 💬 **Answer:**                                           │
              │ Here is my answer based on my analysis.                  │
              └──────────────────────────────────────────────────────────┘

              SEPARATED:
              ┌──────────────────────────────────────────────────────────┐
              │ Let me analyze this step by step...                      │
              │                                                          │
              │ ---                                                      │
              │                                                          │
              │ Here is my answer based on my analysis.                  │
              └──────────────────────────────────────────────────────────┘


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                               » EXAMPLES «                                     ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         ┌─────────────────────────────────────────────────────────────────┐
         │  CURL - Streaming                                               │
         └─────────────────────────────────────────────────────────────────┘

              curl http://localhost:8001/v1/chat/completions \
                -H "Content-Type: application/json" \
                -d '{
                  "model": "gpt-4o",
                  "messages": [{"role": "user", "content": "Hello!"}],
                  "stream": true
                }'

         ┌─────────────────────────────────────────────────────────────────┐
         │  CURL - With Thinking Model                                     │
         └─────────────────────────────────────────────────────────────────┘

              curl http://localhost:8001/v1/chat/completions \
                -H "Content-Type: application/json" \
                -d '{
                  "model": "glm-4.7",
                  "messages": [{"role": "user", "content": "Solve: 2+2*2"}],
                  "stream": true
                }'

         ┌─────────────────────────────────────────────────────────────────┐
         │  CURL - Override Thinking Mode Per-Request                      │
         └─────────────────────────────────────────────────────────────────┘

              curl http://localhost:8001/v1/chat/completions \
                -H "Content-Type: application/json" \
                -d '{
                  "model": "deepseek-r1",
                  "messages": [{"role": "user", "content": "Explain gravity"}],
                  "stream": true,
                  "thinking_mode": "labeled"
                }'

         ┌─────────────────────────────────────────────────────────────────┐
         │  PYTHON - OpenAI SDK                                            │
         └─────────────────────────────────────────────────────────────────┘

              from openai import OpenAI

              client = OpenAI(
                  base_url="http://localhost:8001/v1",
                  api_key="any-string"
              )

              stream = client.chat.completions.create(
                  model="claude-3.5-sonnet",
                  messages=[{"role": "user", "content": "Write a haiku"}],
                  stream=True
              )
              for chunk in stream:
                  if chunk.choices[0].delta.content:
                      print(chunk.choices[0].delta.content, end="", flush=True)

         ┌─────────────────────────────────────────────────────────────────┐
         │  PYTHON - Thinking Model                                        │
         └─────────────────────────────────────────────────────────────────┘

              from openai import OpenAI

              client = OpenAI(
                  base_url="http://localhost:8001/v1",
                  api_key="any-string"
              )

              # Thinking will be formatted according to THINKING_OUTPUT_MODE
              response = client.chat.completions.create(
                  model="qwen3-32b",
                  messages=[{"role": "user", "content": "What is 15% of 80?"}],
                  stream=True
              )
              for chunk in response:
                  if chunk.choices[0].delta.content:
                      print(chunk.choices[0].delta.content, end="", flush=True)


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                            » API ENDPOINTS «                                   ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         ┌─────────────────────────────────────────────────────────────────┐
         │  STANDARD OPENAI-COMPATIBLE                                     │
         └─────────────────────────────────────────────────────────────────┘

              GET  /v1/models ............. List available models
              POST /v1/chat/completions ... Chat completion (stream/non-stream)

         ┌─────────────────────────────────────────────────────────────────┐
         │  ADDITIONAL ENDPOINTS                                           │
         └─────────────────────────────────────────────────────────────────┘

              GET  / ...................... Dashboard (web UI)
              GET  /health ................ Health check
              GET  /v1/thinking-modes ..... List thinking output modes


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                              » CHANGELOG «                                     ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         ┌─────────────────────────────────────────────────────────────────┐
         │  v4.1.0                                                         │
         └─────────────────────────────────────────────────────────────────┘
              ■ Set default thinking mode to "tagged" (<think></think>)
              ■ Added qwen3-32b as thinking model
              ■ Added ThinkingFormatter class with 10 output modes
              ■ Added per-request thinking_mode override
              ■ Added /v1/thinking-modes endpoint
              ■ Enhanced dashboard with mode examples
              ■ Improved streaming transition between thinking and answer
              ■ Fixed thinking model output for SillyTavern compatibility
              ■ Added THINKING_OUTPUT_MODE environment variable
              ■ Fixed GLM-4.7 "reasoning" field extraction
              ■ Added multiple reasoning field format support
              ■ Added thinking model support (GLM, DeepSeek R1, Gemini, etc.)
              ■ Fixed version consistency issues
              ■ Replaced deprecated FastAPI startup event with lifespan
              ■ Added shared HTTP client for better performance
              ■ Added environment variable configuration
              ■ Added message validation
              ■ Added health check endpoint

         ┌─────────────────────────────────────────────────────────────────┐
         │  v4.0.1                                                         │
         └─────────────────────────────────────────────────────────────────┘
              ■ Fully removed all token management code
              ■ Removed all dependencies on browser scripts
              ■ Removed internal fallback token
              ■ Readded P8 logging
              ■ Streamlined proxy logic for P8/P9 routing
              ■ Massive model library update

         ┌─────────────────────────────────────────────────────────────────┐
         │  v4.0.0 [BETA]                                                  │
         └─────────────────────────────────────────────────────────────────┘
              ■ Major architecture rewrite
              ■ Unified all providers to direct Proxy API (P9)
              ■ Removed legacy Persona/Session logic


    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                            » TROUBLESHOOTING «                                 ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

         ┌─────────────────────────────────────────────────────────────────┐
         │  THINKING TAGS SHOWING AS RAW TEXT                              │
         └─────────────────────────────────────────────────────────────────┘

              Problem: <think></think> tags appear as plain text
              Solution: Enable "Auto-Parse" in SillyTavern's Advanced Formatting

         ┌─────────────────────────────────────────────────────────────────┐
         │  BLANK OUTPUT FROM THINKING MODELS                              │
         └─────────────────────────────────────────────────────────────────┘

              Problem: GLM-4.7, DeepSeek R1, etc. return empty responses
              Solution: Update to v4.1.0 - this fixes reasoning field extraction

         ┌─────────────────────────────────────────────────────────────────┐
         │  403 FORBIDDEN ERRORS                                           │
         └─────────────────────────────────────────────────────────────────┘

              Problem: Requests fail with 403 error
              Solution: The upstream service may be rate limiting. Wait and retry.

         ┌─────────────────────────────────────────────────────────────────┐
         │  TIMEOUT ERRORS                                                 │
         └─────────────────────────────────────────────────────────────────┘

              Problem: Requests timeout before completing
              Solution: Increase timeout with REQUEST_TIMEOUT=600


    ┌────────────────────────────────────────────────────────────────────────────────┐
    │                                                                                │
    │                            ★ END OF README ★                                   │
    │                                                                                │
    │                    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░                       │
    │                    ░  TheOldLLM Proxy v4.1.0           ░                       │
    │                    ░  http://localhost:8001            ░                       │
    │                    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░                       │
    │                                                                                │
    └────────────────────────────────────────────────────────────────────────────────┘