2026-06-09-openai-reasoning-proxy-spec.md 1.4 KB

OpenAI Reasoning Proxy Spec

Goal

Provide a single-file FastAPI proxy that exposes an OpenAI-compatible POST /v1/chat/completions endpoint while translating reasoning controls to LM Studio native POST /api/v1/chat.

Scope

  • Implemented as one Python file.
  • Supports:
    • GET /healthz
    • GET /v1/models
    • POST /v1/chat/completions
  • Accepts OpenAI-style reasoning and enable_thinking.
  • Translates them to LM Studio native reasoning: "on" | "off".
  • Converts native LM Studio output back into OpenAI-style choices[0].message.

Behavior

  • reasoning: "off" wins over enable_thinking.
  • If enable_thinking is provided:
    • false => native reasoning: "off"
    • true => native reasoning: "on"
  • If neither is provided, default to native reasoning: "on".
  • stream=true is rejected for now.

Message Mapping

  • OpenAI system messages are merged into native system_prompt.
  • Other messages are flattened into a plain-text transcript:
    • User: ...
    • Assistant: ...
  • This preserves basic chat context without depending on undocumented native message schemas.

Verification

  • Unit tests cover payload mapping and native-to-OpenAI response translation.
  • Real integration test confirmed:
    • baseline => reasoning on
    • enable_thinking: false => reasoning off
    • reasoning: "off" => reasoning off
    • reasoning: "on" => reasoning on