CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

feat: Support custom OpenAI-compatible providers (e.g. GLM/ZhiPu)

Open messiahyl opened this issue 6 months ago • 5 comments

Problem

DeepSeek TUI has a hardcoded provider whitelist (DeepSeek, NVIDIA NIM, OpenRouter, Novita, Fireworks, SGLang). The openai provider appears in deepseek model list but is rejected at runtime:

error: The interactive TUI supports DeepSeek, NVIDIA NIM, OpenRouter, Novita, Fireworks, and SGLang providers.

This makes it impossible to use popular OpenAI-compatible providers like GLM (智谱/ZhiPu), Moonshot, Qwen, etc.

Steps to reproduce

  1. Configure openai provider with GLM endpoint:
    provider = "openai"
    api_key = "glm-api-key"
    [providers.openai]
    base_url = "https://open.bigmodel.cn/api/coding/paas/v4"
    
  2. Run deepseek --provider openai --model glm-5 -p "hello"
  3. Error: provider not supported

Workaround attempt: sglang provider

Tried using sglang provider with custom base_url pointing to GLM's endpoint. The model validation passes, but the path is wrong — sglang hardcodes /v1/chat/completions while GLM uses /v4/chat/completions:

info API base URL: https://open.bigmodel.cn/api/coding/paas
Error: HTTP 404 Not Found: {"path":"/v1/chat/completions"}

What's needed

  1. Enable the openai provider in the TUI (it's already listed in model list but blocked at runtime)
  2. Or add a generic custom provider that:
    • Uses user-provided base_url as-is
    • Passes model ID through without normalization
    • Uses standard OpenAI-compatible /v1/chat/completions path (or allows custom path override)
  3. Path override option: Some providers (like GLM coding plan) use non-standard paths (/v4/ instead of /v1/). A config like api_path = "/v4/chat/completions" would solve this.

Use case

GLM (智谱) Coding Plan API:

  • Base URL: https://open.bigmodel.cn/api/coding/paas/v4
  • Endpoint: /chat/completions (not /v1/chat/completions)
  • Models: glm-4.7, glm-5, glm-5.1
  • Auth: Bearer token

This is a widely used LLM provider in China with millions of developers. Supporting custom providers would also unlock Moonshot, Qwen, Baichuan, and other OpenAI-compatible APIs.

Environment

  • deepseek-tui: 0.8.12
  • OS: macOS (aarch64)

messiahyl avatar May 05 '26 09:05 messiahyl

智普支持anthropic格式api,参考文档,只需要配置

ANTHROPIC_BASE_URL=https://open.bigmodel.cn/api/anthropic

lloydzhou avatar May 05 '26 11:05 lloydzhou

This is a common pain point with TUI-based LLM tools. The hardcoded provider whitelist blocks a large ecosystem of OpenAI-compatible endpoints.

For the path mismatch issue (GLM using /v4/chat/completions instead of /v1/chat/completions), a few approaches that work in practice:

  1. API path override in config (cleanest):

    [providers.custom]
    base_url = "https://open.bigmodel.cn/api/coding/paas"
    api_path = "/v4/chat/completions"  # override default /v1/
    
  2. Base URL trick: Some providers accept the version in the base URL itself. Setting base_url = "https://open.bigmodel.cn/api/coding/paas/v4" and having the client append /chat/completions (without /v1/) can work if the HTTP client supports it.

  3. Reverse proxy: Run a local proxy that rewrites /v1/chat/completions → /v4/chat/completions. Quick and dirty but works with any TUI.

The broader benefit of enabling custom providers: it unlocks the entire OpenAI-compatible ecosystem — GLM, Moonshot, Qwen, Mistral self-hosted, vLLM, SGLang, Ollama, and any gateway that speaks the OpenAI protocol. Most production LLM deployments now go through some form of OpenAI-compatible proxy.

XidaoApi avatar May 05 '26 14:05 XidaoApi

注意:项目本身使用 deepseek v4 pdf 做了很多 v4 相关的优化,其他的模型未必能达到应有的效果。 Note: The project itself uses Deepseek v4 PDF and has made many v4-related optimizations. Other models may not be able to achieve the desired results.

douglarek avatar May 05 '26 14:05 douglarek

yes, I am trying to figure out the best way forward with this - I appreciate your suggestion. I am also a huge fan of the GLM models and have considered adding them since they also do not have a dedicated coding terminal (that i'm aware of), but I am weighing the risks against the benfeits

Hmbown avatar May 05 '26 18:05 Hmbown

glm5.1 基于deepseek-v3.2训练的,api兼容claude; 直接按官方的文档配置了在claude code/opencode等工具使用就可以了

https://docs.bigmodel.cn/cn/coding-plan/tool/others

lloydzhou avatar May 07 '26 12:05 lloydzhou