{"modulePath":"github.com/xhd2015/llm-proxy","version":"v0.0.43","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package commandcode\n\nPackage commandcode serves an Anthropic Messages proxy backed by a Command Code subscription, so clients such as Grok CLI can use Command Code models without the \\`cmd\\` binary.\n\n## Constants\n\n```go\nconst DefaultBaseURL = \"https://api.commandcode.ai\"\n```\nDefaultBaseURL is the production Command Code API endpoint.\n\n```go\nconst DefaultPort = 8892\n```\nDefaultPort is the loopback port for the proxy (Codex uses 8891).\n\n```go\nconst DefaultVersion = \"1.53.0\"\n```\nDefaultVersion is the X-Command-Code-Version sent upstream. The backend rejects requests below a minimum version, so it is overridable by flag.\n\n## Variables\n\n```go\nvar Catalog = []Model{\n\t{\n\t\tID:            \"deepseek/deepseek-v4-pro\",\n\t\tName:          \"DeepSeek V4 Pro (latest)\",\n\t\tDescription:   \"hybrid-attention long-context reasoning\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"deepseek/deepseek-v4-flash\",\n\t\tName:          \"DeepSeek V4 Flash (latest)\",\n\t\tDescription:   \"fast hybrid-attention reasoning (default)\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"deepseek/deepseek-v4-flash-vision-exp\",\n\t\tName:          \"DeepSeek V4 Flash Vision (exp)\",\n\t\tDescription:   \"fast hybrid-attention reasoning with vision\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"deepseek/deepseek-v4-flash-fast\",\n\t\tName:          \"DeepSeek V4 Flash Fast\",\n\t\tDescription:   \"low-latency V4 Flash deployment\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"deepseek/deepseek-v4.1-flash\",\n\t\tName:          \"DeepSeek V4.1 Flash\",\n\t\tDescription:   \"V4.1 hybrid-attention reasoning with vision\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"moonshotai/kimi-k3\",\n\t\tName:          \"Kimi K3\",\n\t\tDescription:   \"long-horizon coding \u0026 knowledge work with 1M context\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"moonshotai/kimi-k2.7-code\",\n\t\tName:          \"Kimi K2.7 Code\",\n\t\tDescription:   \"improved long-horizon coding with vision\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 256000,\n\t},\n\t{\n\t\tID:            \"moonshotai/kimi-k2.7-code-highspeed\",\n\t\tName:          \"Kimi K2.7 Code HighSpeed\",\n\t\tDescription:   \"high-speed long-horizon coding with vision\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 262000,\n\t},\n\t{\n\t\tID:            \"moonshotai/kimi-k2.6\",\n\t\tName:          \"Kimi K2.6\",\n\t\tDescription:   \"long-horizon coding with vision\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 256000,\n\t},\n\t{\n\t\tID:            \"moonshotai/kimi-k2.5\",\n\t\tName:          \"Kimi K2.5\",\n\t\tDescription:   \"multimodal frontend coding\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 256000,\n\t},\n\t{\n\t\tID:            \"z-ai/glm-5.3-flash\",\n\t\tName:          \"GLM-5.3 Flash\",\n\t\tDescription:   \"fast, affordable GLM coding with 1M context\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1048576,\n\t},\n\t{\n\t\tID:            \"zai-org/glm-5.3\",\n\t\tName:          \"GLM-5.3\",\n\t\tDescription:   \"frontier coding with emergent cyber capabilities\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"zai-org/glm-5.2\",\n\t\tName:          \"GLM-5.2\",\n\t\tDescription:   \"powerful coding with 1M context and long-horizon tasks\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"zai-org/glm-5.2-fast\",\n\t\tName:          \"GLM-5.2 Fast\",\n\t\tDescription:   \"high-throughput GLM-5.2 with 1M context\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"zai-org/glm-5.1\",\n\t\tName:          \"GLM-5.1\",\n\t\tDescription:   \"long-horizon autonomous coding agent\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"zai-org/glm-5\",\n\t\tName:          \"GLM-5\",\n\t\tDescription:   \"multi-mode thinking \u0026 long-range planning\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 200000,\n\t},\n\t{\n\t\tID:            \"minimaxai/minimax-m3\",\n\t\tName:          \"MiniMax M3\",\n\t\tDescription:   \"frontier coding, agents \u0026 native multimodality\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"minimaxai/minimax-m2.7\",\n\t\tName:          \"MiniMax M2.7\",\n\t\tDescription:   \"end-to-end software engineering agent\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"minimaxai/minimax-m2.5\",\n\t\tName:          \"MiniMax M2.5\",\n\t\tDescription:   \"cross-platform full-stack agentic dev\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 200000,\n\t},\n\t{\n\t\tID:            \"xiaomi/mimo-v2.5-pro\",\n\t\tName:          \"MiMo V2.5 Pro\",\n\t\tDescription:   \"high-capability long-context agentic coding\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"xiaomi/mimo-v2.5\",\n\t\tName:          \"MiMo V2.5\",\n\t\tDescription:   \"efficient long-context agentic coding\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.8-max-0902\",\n\t\tName:          \"Qwen 3.8 Max 0902\",\n\t\tDescription:   \"upgraded Qwen 3.8 Max: stronger coding \u0026 agentic tool use\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.8-max\",\n\t\tName:          \"Qwen 3.8 Max\",\n\t\tDescription:   \"autonomous long-horizon coding \u0026 professional work\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.8-27b\",\n\t\tName:          \"Qwen 3.8 27B\",\n\t\tDescription:   \"compact vision-language coding \u0026 agentic work\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 262144,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.8-flash\",\n\t\tName:          \"Qwen 3.8 Flash\",\n\t\tDescription:   \"fast low-cost agentic coding \u0026 reasoning\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.7-max\",\n\t\tName:          \"Qwen 3.7 Max\",\n\t\tDescription:   \"frontier coding \u0026 long-horizon agent execution\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.7-plus\",\n\t\tName:          \"Qwen 3.7 Plus\",\n\t\tDescription:   \"agentic coding \u0026 reasoning at lower cost\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.7-flash\",\n\t\tName:          \"Qwen 3.7 Flash\",\n\t\tDescription:   \"fast low-cost agentic coding \u0026 reasoning\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.6-max-preview\",\n\t\tName:          \"Qwen 3.6 Max Preview\",\n\t\tDescription:   \"vibe coding \u0026 efficient agent execution\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"qwen/qwen3.6-plus\",\n\t\tName:          \"Qwen 3.6 Plus\",\n\t\tDescription:   \"agentic coding \u0026 reasoning\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"meituan/longcat-2.0:free\",\n\t\tName:          \"LongCat 2.0\",\n\t\tDescription:   \"FREE trillion-parameter agentic coding with 1M context\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"stepfun/step-3.7-flash\",\n\t\tName:          \"Step 3.7 Flash\",\n\t\tDescription:   \"multimodal sparse-MoE reasoning\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 256000,\n\t},\n\t{\n\t\tID:            \"stepfun/step-3.5-flash\",\n\t\tName:          \"Step 3.5 Flash\",\n\t\tDescription:   \"fast sparse-MoE agentic reasoning\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"tencent/hy3-paid\",\n\t\tName:          \"Tencent Hy3\",\n\t\tDescription:   \"sparse-MoE reasoning \u0026 agentic tool use\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 262144,\n\t},\n\t{\n\t\tID:            \"tencent/hy4-preview\",\n\t\tName:          \"Tencent Hy4 Preview\",\n\t\tDescription:   \"agentic coding \u0026 sustained multi-step tool use\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1048576,\n\t},\n\t{\n\t\tID:            \"nvidia/nemotron-3-ultra-550b-a55b\",\n\t\tName:          \"Nemotron 3 Ultra\",\n\t\tDescription:   \"open reasoning model for long-horizon autonomous agents\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"thinkingmachines/inkling\",\n\t\tName:          \"Inkling\",\n\t\tDescription:   \"multimodal MoE reasoning\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 256000,\n\t},\n\t{\n\t\tID:            \"thinkingmachines/inkling-small\",\n\t\tName:          \"Inkling Small\",\n\t\tDescription:   \"lightweight MoE reasoning at lower cost and latency\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"poolside/laguna-s-2.1-free\",\n\t\tName:          \"Laguna S 2.1\",\n\t\tDescription:   \"FREE open-weight agentic coding and long-horizon work\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"inclusionai/ling-3.0-flash-sante:free\",\n\t\tName:          \"Ling 3.0 Flash Sante\",\n\t\tDescription:   \"FREE health \u0026 medicine tuned lightweight-MoE, still strong on code\",\n\t\tGroup:         \"Open Source\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"claude-sonnet-5\",\n\t\tName:          \"Claude Sonnet 5\",\n\t\tDescription:   \"best combo of speed \u0026 intelligence (recommended)\",\n\t\tGroup:         \"Anthropic\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"claude-sonnet-4-6\",\n\t\tName:          \"Claude Sonnet 4.6\",\n\t\tDescription:   \"prev Sonnet, still fast \u0026 capable\",\n\t\tGroup:         \"Anthropic\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"claude-fable-5-1\",\n\t\tName:          \"Claude Fable 5.1\",\n\t\tDescription:   \"most capable for demanding reasoning \u0026 long-horizon agents\",\n\t\tGroup:         \"Anthropic\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"claude-fable-5\",\n\t\tName:          \"Claude Fable 5\",\n\t\tDescription:   \"prev Fable, still strong for deep reasoning \u0026 agents\",\n\t\tGroup:         \"Anthropic\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"claude-opus-5\",\n\t\tName:          \"Claude Opus 5\",\n\t\tDescription:   \"most intelligent Opus for agents and coding\",\n\t\tGroup:         \"Anthropic\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"claude-opus-4-8\",\n\t\tName:          \"Claude Opus 4.8\",\n\t\tDescription:   \"prev flagship, still strong for agents and coding\",\n\t\tGroup:         \"Anthropic\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"claude-opus-4-7\",\n\t\tName:          \"Claude Opus 4.7\",\n\t\tDescription:   \"older Opus, still strong for agents and coding\",\n\t\tGroup:         \"Anthropic\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"claude-haiku-4-5\",\n\t\tName:          \"claude-haiku-4-5\",\n\t\tDescription:   \"fastest \u0026 most compact, great for quick tasks\",\n\t\tGroup:         \"Anthropic\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"gpt-6-astra\",\n\t\tName:          \"GPT-6 Astra\",\n\t\tDescription:   \"most capable OpenAI model for demanding reasoning \u0026 agents\",\n\t\tGroup:         \"OpenAI\",\n\t\tContextWindow: 1050000,\n\t},\n\t{\n\t\tID:            \"gpt-5.6-sol\",\n\t\tName:          \"GPT-5.6 Sol\",\n\t\tDescription:   \"frontier model for complex professional work\",\n\t\tGroup:         \"OpenAI\",\n\t\tContextWindow: 1050000,\n\t},\n\t{\n\t\tID:            \"gpt-5.6-terra\",\n\t\tName:          \"GPT-5.6 Terra\",\n\t\tDescription:   \"balances intelligence and cost\",\n\t\tGroup:         \"OpenAI\",\n\t\tContextWindow: 1050000,\n\t},\n\t{\n\t\tID:            \"gpt-5.6-luna\",\n\t\tName:          \"GPT-5.6 Luna\",\n\t\tDescription:   \"optimized for cost-sensitive workloads\",\n\t\tGroup:         \"OpenAI\",\n\t\tContextWindow: 1050000,\n\t},\n\t{\n\t\tID:            \"gpt-5.5\",\n\t\tName:          \"GPT-5.5\",\n\t\tDescription:   \"latest frontier model for general complex work\",\n\t\tGroup:         \"OpenAI\",\n\t\tContextWindow: 400000,\n\t},\n\t{\n\t\tID:            \"gpt-5.4\",\n\t\tName:          \"GPT-5.4\",\n\t\tDescription:   \"frontier model for general complex work\",\n\t\tGroup:         \"OpenAI\",\n\t\tContextWindow: 400000,\n\t},\n\t{\n\t\tID:            \"gpt-5.3-codex\",\n\t\tName:          \"GPT-5.3 Codex\",\n\t\tDescription:   \"frontier coding model\",\n\t\tGroup:         \"OpenAI\",\n\t\tContextWindow: 400000,\n\t},\n\t{\n\t\tID:            \"gpt-5.4-mini\",\n\t\tName:          \"GPT-5.4 Mini\",\n\t\tDescription:   \"fast, cost-effective model for everyday tasks\",\n\t\tGroup:         \"OpenAI\",\n\t\tContextWindow: 400000,\n\t},\n\t{\n\t\tID:            \"google/gemini-3.8-flash\",\n\t\tName:          \"Gemini 3.8 Flash\",\n\t\tDescription:   \"newest Gemini Flash, improved core reasoning\",\n\t\tGroup:         \"Google\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"google/gemini-3.7-flash\",\n\t\tName:          \"Gemini 3.7 Flash\",\n\t\tDescription:   \"higher-quality coding \u0026 agentic workflows, fewer tokens\",\n\t\tGroup:         \"Google\",\n\t\tContextWindow: 1048576,\n\t},\n\t{\n\t\tID:            \"google/gemini-3.6-flash\",\n\t\tName:          \"Gemini 3.6 Flash\",\n\t\tDescription:   \"previous Gemini Flash, still fast \u0026 capable\",\n\t\tGroup:         \"Google\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"google/gemini-3.5-flash\",\n\t\tName:          \"Gemini 3.5 Flash\",\n\t\tDescription:   \"Pro-level coding proficiency, parallel agentic execution\",\n\t\tGroup:         \"Google\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"google/gemini-3.5-flash-lite\",\n\t\tName:          \"Gemini 3.5 Flash Lite\",\n\t\tDescription:   \"upgraded agentic capabilities, ideal for subagents\",\n\t\tGroup:         \"Google\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"google/gemini-3.1-flash-lite\",\n\t\tName:          \"Gemini 3.1 Flash Lite\",\n\t\tDescription:   \"high-volume workhorse model with implicit caching\",\n\t\tGroup:         \"Google\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"sakana/fugu-ultra\",\n\t\tName:          \"Fugu Ultra\",\n\t\tDescription:   \"multi-agent orchestration across frontier models\",\n\t\tGroup:         \"Sakana\",\n\t\tContextWindow: 1000000,\n\t},\n\t{\n\t\tID:            \"meta/muse-spark-1.1\",\n\t\tName:          \"Muse Spark 1.1\",\n\t\tDescription:   \"agentic performance, tool use, and computer use\",\n\t\tGroup:         \"Meta\",\n\t\tContextWindow: 1048576,\n\t},\n\t{\n\t\tID:            \"meta/muse-spark-1.2\",\n\t\tName:          \"Muse Spark 1.2\",\n\t\tDescription:   \"coding-optimized for agentic workflows and large codebases\",\n\t\tGroup:         \"Meta\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"meta/muse-spark-1.2-contributor\",\n\t\tName:          \"Muse Spark 1.2 Contributor\",\n\t\tDescription:   \"Muse Spark 1.2 at ~95% off\",\n\t\tGroup:         \"Meta\",\n\t\tContextWindow: 0,\n\t},\n\t{\n\t\tID:            \"meta/muse-spark-1.3\",\n\t\tName:          \"Muse Spark 1.3\",\n\t\tDescription:   \"multimodal reasoning for long-horizon agentic and coding workflows\",\n\t\tGroup:         \"Meta\",\n\t\tContextWindow: 1048576,\n\t},\n\t{\n\t\tID:            \"meta/muse-spark-1.3-contributor\",\n\t\tName:          \"Muse Spark 1.3 Contributor\",\n\t\tDescription:   \"Muse Spark 1.3 at up to 95% off\",\n\t\tGroup:         \"Meta\",\n\t\tContextWindow: 1048576,\n\t},\n\t{\n\t\tID:            \"xai/grok-4.5\",\n\t\tName:          \"Grok 4.5\",\n\t\tDescription:   \"smartest model for coding, agentic tasks, knowledge work\",\n\t\tGroup:         \"xAI\",\n\t\tContextWindow: 500000,\n\t},\n\t{\n\t\tID:            \"xai/grok-4.6\",\n\t\tName:          \"Grok 4.6\",\n\t\tDescription:   \"frontier performance on coding, knowledge work, and STEM\",\n\t\tGroup:         \"xAI\",\n\t\tContextWindow: 500000,\n\t},\n}\n```\nCatalog lists the models Command Code advertises for a subscription. Plan gating still applies server-side, so a listed model may be rejected.\n\n## Functions\n\n```go\nfunc AuthPath(home string) (string, error)\n```\nAuthPath resolves the auth.json path inside home.\n\n```go\nfunc ConfigBlocks(endpoint string) string\n```\nConfigBlocks renders ready-to-paste \\[model.\\*] blocks for ~/.grok/config.toml, mirroring \\`llm-proxy codex-models\\`.\n\n```go\nfunc DefaultHome() string\n```\nDefaultHome is the Command Code config directory used when --commandcode-home is not given.\n\n```go\nfunc ModelsV2(endpoint string) modelsV2Response\n```\nModelsV2 builds the Grok CLI catalog. Grok requests this on resume from idle to refresh context-window metadata.\n\n```go\nfunc NewHandler(opts Options) (http.Handler, error)\n```\nNewHandler validates credentials and returns the Command Code HTTP handler.\n\n```go\nfunc SectionName(id string) string\n```\nSectionName is the \\[model.\"\\\u003csection\u003e\"] key for a Command Code model id.\n\n```go\nfunc ServeAccounts(w http.ResponseWriter, r *http.Request, pools []*AccountPool, liveFor time.Duration)\n```\nServeAccounts writes per-credential quota, in-flight requests, and live sessions. eluc's AI usage page reads it, and so can any local operator. It is the multi-pool entry the config-mode proxy mounts at /v1/accounts, where one provider may own several pools.\n\n```go\nfunc Start(opts Options) error\n```\nStart validates credentials and serves the proxy until the process stops.\n\n## Types\n\n```go\ntype AccountConfig struct {\n\tName string\n\tHome string\n\t// Disabled parks the account without removing it. Zero means enabled, so a\n\t// caller that does not care about parking keeps the account routable.\n\tDisabled bool\n\t// MaxInFlight caps concurrent requests; 0 means unlimited.\n\tMaxInFlight int\n\t// Selected marks the credential the config's own \"selected\" flag names.\n\t// It is the only account used when load balancing is off.\n\tSelected bool\n}\n```\nAccountConfig is one credential the pool may route to.\n\n```go\ntype AccountPool struct {\n\t// contains filtered or unexported fields\n}\n```\nAccountPool owns the credentials, their quotas, and their in-flight counts.\n\n```go\nfunc NewAccountPool(configs []AccountConfig, opts PoolOptions) (*AccountPool, error)\n```\nNewAccountPool builds the pool and, unless disabled, starts the refresher.\n\n```go\nfunc (p *AccountPool) Acquire(name string) bool\n```\nAcquire reserves one in-flight slot on the named account, refusing when its concurrency cap is already reached.\n\n```go\nfunc (p *AccountPool) AcquireSlot(ctx context.Context, preferred string, exclude map[string]bool) *account\n```\nAcquireSlot picks an account and reserves a slot on it, waiting up to the pool's WaitForSlot for a busy pool to drain. A nil account means nothing can serve the request right now (quota, capacity, or every candidate excluded).\n\n```go\nfunc (p *AccountPool) Close()\n```\nClose stops the refresher.\n\n```go\nfunc (p *AccountPool) Configure(accounts []AccountConfig, settings PoolSettings)\n```\nConfigure reconciles the pool with the provider's current config. Accounts are matched by name: survivors keep their quota and in-flight counts, new ones start fresh, removed ones stop being routable. The session registry is untouched, so conversations keep their ids across a reload.\n\n```go\nfunc (p *AccountPool) Cooldown(name, reason string, d time.Duration)\n```\nCooldown takes an account out of rotation for a while, used after a 429 or a model-permission refusal.\n\n```go\nfunc (p *AccountPool) HasCandidate(preferred string, exclude map[string]bool) bool\n```\nHasCandidate reports whether any account could take a request right now.\n\n```go\nfunc (p *AccountPool) Len() int\n```\nLen reports the number of accounts.\n\n```go\nfunc (p *AccountPool) LoadBalance() bool\n```\nLoadBalance reports whether the pool routes across accounts.\n\n```go\nfunc (p *AccountPool) Names() []string\n```\nNames lists the configured accounts in order.\n\n```go\nfunc (p *AccountPool) Refresh(ctx context.Context)\n```\nRefresh polls every account once. A failure keeps the previous availability (a network blip must not take the pool down) but an auth failure disables the account until it is fixed.\n\n```go\nfunc (p *AccountPool) Registry() *Registry\n```\nRegistry returns the session registry shared by every route that uses this pool, so one conversation keeps one id across models and the stats view sees every live session.\n\n```go\nfunc (p *AccountPool) Release(name string)\n```\nRelease returns an in-flight slot.\n\n```go\nfunc (p *AccountPool) RouteName(preferred string, exclude map[string]bool) (string, bool)\n```\nRouteName reports which account would serve a request, for diagnostics and tests; the account type itself stays private.\n\n```go\nfunc (p *AccountPool) Select(preferred string, exclude map[string]bool) *account\n```\nSelect returns the account to serve one request: the preferred one when it is still usable, else the least busy usable account, ties broken by remaining weekly quota.\n\n```go\nfunc (p *AccountPool) Snapshot() []AccountStat\n```\nSnapshot copies the current state for the stats endpoint.\n\n```go\ntype AccountStat struct {\n\tName        string      `json:\"name\"`\n\tHome        string      `json:\"home,omitempty\"`\n\tAvailable   bool        `json:\"available\"`\n\tReason      string      `json:\"reason,omitempty\"`\n\tInFlight    int         `json:\"inFlight\"`\n\tEnabled     bool        `json:\"enabled\"`\n\tMaxInFlight int         `json:\"maxInFlight\"`\n\tSelected    bool        `json:\"selected\"`\n\tSessions    int         `json:\"sessions\"`\n\tFiveHour    WindowUsage `json:\"fiveHour\"`\n\tWeekly      WindowUsage `json:\"weekly\"`\n\tRefreshedAt time.Time   `json:\"refreshedAt,omitempty\"`\n\tLastError   string      `json:\"lastError,omitempty\"`\n}\n```\nAccountStat is one row of the pool's public view.\n\n```go\ntype Auth struct {\n\tAPIKey   string\n\tUserID   string\n\tUserName string\n}\n```\nAuth holds the credentials read from a Command Code home directory.\n\n```go\nfunc ReadAuth(home string) (*Auth, error)\n```\nReadAuth reads auth.json from home. It is called per request so a rotated apiKey is picked up without restarting the proxy.\n\n```go\ntype Client struct {\n\tBaseURL string\n\t// Home is the Command Code config directory holding auth.json.\n\tHome string\n\t// Version is sent as X-Command-Code-Version; the backend enforces a minimum.\n\tVersion string\n\tHTTP    *http.Client\n}\n```\nClient calls the Command Code /alpha/generate endpoint.\n\n```go\nfunc (c *Client) Generate(ctx context.Context, body *alphaRequest) (*http.Response, error)\n```\nGenerate posts the translated request to /alpha/generate. Credentials are read per call so a rotated apiKey is picked up without a restart.\n\n```go\ntype ContentBlock struct {\n\tType string `json:\"type\"`\n\n\t// type=text\n\tText string `json:\"text\"`\n\n\t// type=tool_use\n\tID    string          `json:\"id\"`\n\tName  string          `json:\"name\"`\n\tInput json.RawMessage `json:\"input\"`\n\n\t// type=tool_result\n\tToolUseID string          `json:\"tool_use_id\"`\n\tContent   json.RawMessage `json:\"content\"`\n\n\t// type=thinking\n\tThinking string `json:\"thinking\"`\n\n\t// type=image (Anthropic nests these under \"source\").\n\tSource *ImageSource `json:\"source,omitempty\"`\n\n\t// Prompt caching marker, forwarded verbatim on system text blocks.\n\tCacheControl json.RawMessage `json:\"cache_control,omitempty\"`\n}\n```\nContentBlock is the flat union of the Anthropic content block fields the proxy translates. Absent fields stay zero and are omitted when encoding.\n\n```go\ntype CreditSnapshot struct {\n\tFiveHour WindowUsage\n\tWeekly   WindowUsage\n\tExceeded bool\n\tReason   string\n}\n```\nCreditSnapshot is what one quota refresh learned about an account.\n\n```go\ntype Digest [32]byte\n```\nDigest is one link of a conversation's fingerprint chain.\n\n```go\nfunc ChainDigests(model string, system any, messages []alphaMessage) []Digest\n```\nChainDigests derives the conversation's fingerprint chain: one digest per user turn, each folded over the previous one, so an appended turn extends the chain instead of replacing it.\n\n\tsha0  = H(model ‖ system ‖ body0 ‖ user0)\n\tsha_i = H(sha_{i-1} ‖ body_i ‖ user_i)\n\nA request with no user text at all falls back to a digest of everything, so two different histories can never collapse onto one key.\n\n```go\nfunc (d Digest) Short() string\n```\nString renders a digest for logs.\n\n```go\nfunc (d Digest) String() string\n```\n\n```go\ntype ImageSource struct {\n\tType      string `json:\"type\"`\n\tMediaType string `json:\"media_type\"`\n\tData      string `json:\"data\"`\n}\n```\nImageSource is the Anthropic base64 image payload.\n\n```go\ntype MatchInfo struct {\n\t// Created is true when a new session id was allocated.\n\tCreated bool\n\t// Forked is true when the chain shared a prefix with an existing session\n\t// but diverged, so it is a branch rather than a continuation.\n\tForked bool\n\t// Parent is the longest-prefix session when Forked.\n\tParent *Session\n\t// Matched is how many retained digests lined up.\n\tMatched int\n}\n```\nMatchInfo describes how a chain resolved to a session.\n\n```go\ntype Message struct {\n\tRole    string          `json:\"role\"`\n\tContent json.RawMessage `json:\"content\"`\n}\n```\nMessage is one Anthropic message; Content is a plain string or an array of content blocks.\n\n```go\ntype MessagesRequest struct {\n\tModel     string          `json:\"model\"`\n\tMaxTokens int             `json:\"max_tokens\"`\n\tSystem    json.RawMessage `json:\"system\"`\n\tMessages  []Message       `json:\"messages\"`\n\tTools     []Tool          `json:\"tools\"`\n\tStream    bool            `json:\"stream\"`\n\t// Thinking is Grok/Anthropic thinking config. Command Code always reasons\n\t// for models that support it; the proxy only reads display=summarized so it\n\t// can coalesce token-level reasoning and text deltas.\n\tThinking json.RawMessage `json:\"thinking\"`\n\t// OutputConfig carries Grok/Anthropic effort. When --model-capability\n\t// effort-mapping is set for the request model, Effort is mapped onto\n\t// params.reasoning_effort.\n\tOutputConfig outputConfig `json:\"output_config\"`\n}\n```\nMessagesRequest is the subset of the Anthropic Messages request the proxy consumes.\n\n```go\ntype Model struct {\n\t// ID is the id sent as params.model (e.g. \"deepseek/deepseek-v4-flash\").\n\tID string\n\t// Name is a human-readable display name.\n\tName string\n\t// Description is the one-line description shown by `cmd --list-models`.\n\tDescription string\n\t// Group is the catalog section (e.g. \"Open Source\", \"Anthropic\").\n\tGroup string\n\t// ContextWindow is 0 when the catalog does not advertise one.\n\tContextWindow uint64\n}\n```\nModel describes one Command Code subscription model.\n\n```go\ntype Options struct {\n\t// Home is the Command Code config dir holding auth.json.\n\tHome string\n\t// Version is sent as X-Command-Code-Version.\n\tVersion string\n\t// BaseURL overrides the Command Code API base (default DefaultBaseURL).\n\tBaseURL string\n\t// Port is the loopback listen port (default DefaultPort).\n\tPort int\n\t// Endpoint is the public catalog base URL. It defaults from Port when empty.\n\tEndpoint string\n\t// Verbose logs every proxied request.\n\tVerbose bool\n\t// HTTP is the client used for upstream calls.\n\tHTTP *http.Client\n\t// Logger receives full request logs when set.\n\tLogger *logutil.Logger\n\t// NoCoalesceThinking flushes every Command Code reasoning-delta and\n\t// text-delta, even when the client sent thinking.display=summarized.\n\tNoCoalesceThinking bool\n\t// EffortByModel maps client model id -\u003e (client effort -\u003e Command Code\n\t// reasoning_effort). Values of \"drop\" omit the upstream field. A missing\n\t// model or missing client effort leaves today's behavior (no field).\n\tEffortByModel map[string]map[string]string\n\t// AdjustUsageForDSH, keyed by client model id, rewrites Anthropic\n\t// input_tokens to the uncached miss so DSH cache-hit % is disjoint.\n\tAdjustUsageForDSH map[string]bool\n\t// Accounts is the credential pool. When empty, Home becomes a single\n\t// account so the legacy single-credential flags keep working.\n\tAccounts []AccountConfig\n\t// Pool injects an already-built pool, so every model route of one provider\n\t// shares quotas, in-flight counts, and sessions.\n\tPool *AccountPool\n\t// SessionWindow is how many recent turn digests a session remembers.\n\tSessionWindow int\n\t// SessionTTL drops conversations idle longer than this.\n\tSessionTTL time.Duration\n\t// LiveSessionFor bounds the sessions the stats endpoint reports.\n\tLiveSessionFor time.Duration\n\t// RefreshEvery is the quota refresh interval.\n\tRefreshEvery time.Duration\n}\n```\nOptions configures the Command Code proxy.\n\n```go\ntype PoolOptions struct {\n\tBaseURL      string\n\tVersion      string\n\tHTTP         *http.Client\n\tRefreshEvery time.Duration\n\tNow          func() time.Time\n\tFetch        UsageFetcher\n\t// DisableRefresh keeps the pool static; tests use it with an explicit Fetch.\n\tDisableRefresh bool\n\t// SessionWindow and SessionTTL configure the shared session registry.\n\tSessionWindow int\n\tSessionTTL    time.Duration\n\t// Settings are the provider-level knobs (load balance, refresh interval).\n\tSettings PoolSettings\n\t// WaitForSlot bounds how long a request waits for a free concurrency slot.\n\tWaitForSlot time.Duration\n\t// LiveSessionFor bounds the sessions reported as live.\n\tLiveSessionFor time.Duration\n}\n```\nPoolOptions configures an AccountPool.\n\n```go\ntype PoolSettings struct {\n\t// LoadBalance routes across accounts and allows failover. When false only\n\t// the selected account serves requests.\n\tLoadBalance bool\n\t// Selected names the account used when LoadBalance is off.\n\tSelected string\n\t// RefreshEvery overrides the quota poll interval.\n\tRefreshEvery time.Duration\n}\n```\nPoolSettings are the provider-level knobs the config file controls.\n\n```go\ntype Registry struct {\n\t// contains filtered or unexported fields\n}\n```\nRegistry maps fingerprint chains to sessions. It is the only mutable routing state: one lock covers match, append, and account binding, so two concurrent first requests of the same conversation cannot create two sessions.\n\n```go\nfunc NewRegistry(options RegistryOptions) *Registry\n```\nNewRegistry builds an empty registry.\n\n```go\nfunc (r *Registry) AccountOf(sessionID string) string\n```\nAccountOf reports the credential currently bound to a session.\n\n```go\nfunc (r *Registry) Acquire(sessionID string)\n```\nAcquire marks one in-flight request on the session.\n\n```go\nfunc (r *Registry) Len() int\n```\nLen reports the number of tracked sessions.\n\n```go\nfunc (r *Registry) MatchOrCreate(chain []Digest) (*Session, MatchInfo)\n```\nMatchOrCreate resolves a chain to a session. The chain is computed outside the lock; everything that mutates state happens inside it.\n\n```go\nfunc (r *Registry) Release(sessionID string)\n```\nRelease clears one in-flight request.\n\n```go\nfunc (r *Registry) SetAccount(sessionID, account string)\n```\nSetAccount binds a session to the credential that serves it.\n\n```go\nfunc (r *Registry) Snapshot(liveFor time.Duration) []SessionStat\n```\nSnapshot lists sessions seen within liveFor.\n\n```go\ntype RegistryOptions struct {\n\t// Window is how many recent digests each session remembers (default 10).\n\tWindow int\n\t// Max caps the number of sessions (default 2000).\n\tMax int\n\t// TTL drops sessions idle longer than this (default 60m).\n\tTTL time.Duration\n\tNow func() time.Time\n\t// NewID allocates a session id; it defaults to a random UUID.\n\tNewID func() (string, error)\n}\n```\nRegistryOptions configures a Registry.\n\n```go\ntype Session struct {\n\t// ID is the threadId sent upstream. It is allocated, not content-derived.\n\tID string\n\t// Account is the credential currently serving the conversation.\n\tAccount string\n\t// contains filtered or unexported fields\n}\n```\nSession is one conversation the proxy has routed.\n\n```go\nfunc (s *Session) InFlight() int\n```\nInFlight reports the requests currently streaming for this session.\n\n```go\nfunc (s *Session) LastSeen() time.Time\n```\nLastSeen reports when the session last carried a request.\n\n```go\ntype SessionStat struct {\n\tID       string\n\tAccount  string\n\tInFlight int\n\tLastSeen time.Time\n}\n```\nSessionStat is one row of the live session view.\n\n```go\ntype Tool struct {\n\tName        string          `json:\"name\"`\n\tDescription string          `json:\"description\"`\n\tInputSchema json.RawMessage `json:\"input_schema\"`\n}\n```\nTool is an Anthropic tool definition. Command Code accepts the same shape, so input\\_schema is forwarded verbatim.\n\n```go\ntype Turn struct {\n\t// contains filtered or unexported fields\n}\n```\nTurn is one user turn: the messages that led up to it plus its user text. The chain hashes the previous digest, this body, then the user text.\n\n```go\nfunc SplitTurns(messages []alphaMessage) []Turn\n```\nSplitTurns groups messages into user turns. A turn starts at a user message that carries at least one text block; its body is everything between the previous user text and this one, so tool calls and tool results stay inside the turn they belong to. Messages after the last user text are not part of any turn: they grow while an agent works through tool calls and must not move the fingerprint.\n\n```go\ntype UsageFetcher func(ctx context.Context, home string) (*CreditSnapshot, error)\n```\nUsageFetcher reads an account's quota. Tests replace it.\n\n```go\nfunc FetchCredits(baseURL string) UsageFetcher\n```\nFetchCredits is the production fetcher. It reuses agent-pro's Command Code client, so the proxy and eluc read quota through exactly the same code.\n\n```go\ntype WindowUsage struct {\n\tUsed     float64\n\tCap      float64\n\tResetAt  time.Time\n\tExceeded bool\n}\n```\nWindowUsage is one rate-limit window as the usage endpoint reports it.\n\n```go\nfunc (w WindowUsage) Remaining() float64\n```\nRemaining is the unused fraction of the window, used to break ties between equally busy accounts.\n\n","path":"github.com/xhd2015/llm-proxy/commandcode","name":"commandcode","synopsis":"Package commandcode serves an Anthropic Messages proxy backed by a Command Code subscription, so clients such as Grok CLI can use Command Code models without the `cmd` binary.","isRedistributable":true}
