llmhub

module
v0.0.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: MIT

README

LLMHub

A proxy server that provides OpenAI/Gemini/Claude/Codex/Grok compatible API interfaces for CLI.

It now also supports OpenAI Codex (GPT models) and Claude Code via OAuth.

So you can use local or multi-account CLI access with OpenAI(include Responses)/Gemini/Claude-compatible clients and SDKs.

Overview

  • OpenAI/Gemini/Claude/Grok compatible API endpoints for CLI models
  • OpenAI Codex support (GPT models) via OAuth login
  • Claude Code support via OAuth login
  • Grok Build support via OAuth login
  • Amp CLI and IDE extensions support with provider routing
  • Streaming, non-streaming, and WebSocket responses where supported
  • Function calling/tools support
  • Multimodal input support (text and images)
  • Multiple accounts with round-robin load balancing (Gemini, OpenAI, Claude, Grok)
  • Simple CLI authentication flows (Gemini, OpenAI, Claude, Grok)
  • Generative Language API Key support
  • AI Studio Build multi-account load balancing
  • Gemini CLI multi-account load balancing
  • Claude Code multi-account load balancing
  • OpenAI Codex multi-account load balancing
  • Grok Build multi-account load balancing
  • OpenAI-compatible upstream providers via config (e.g., OpenRouter)
  • Reusable Go SDK for embedding the proxy

Installation

For production, install the latest GitHub Release binary and set up a systemd service on a Linux VPS with one command:

curl -fsSL https://raw.githubusercontent.com/therealtinhtute/llmhub/master/scripts/install.sh | sudo sh

This downloads the binary, creates the llmhub system user, prompts for Postgres plus initial config env, seeds the remote database once, and starts the service.

Point your AI coding tool at http://SERVER_IP:8317/v1. The management panel is at http://SERVER_IP:8317/management.html (configure remote-management.secret-key and remote-management.allow-remote before exposing beyond localhost).

Local binary VPS install

When you already have a Linux llmhub binary, copy it beside the local installer and run it from that directory:

sudo ./install-local.sh

The local installer defaults to port 9090. It prompts for an optional domain name for Caddy HTTPS; leave the prompt blank to keep the direct IP/port setup. Override the port or preseed domain mode when needed:

sudo DEFAULT_PORT=8080 ./install-local.sh
sudo CADDY_DOMAIN=llm.example.com ./install-local.sh
sudo ./install-local.sh /path/to/llmhub-linux-amd64

The generated systemd unit is VPS-oriented by default: it uses Restart=always, waits 3s between restart attempts, and disables the default start-rate lockout with StartLimitIntervalSec=0 so llmhub keeps coming back after repeated crashes until you fix the underlying issue. Override these at install time with SERVICE_RESTART=..., SERVICE_RESTART_SEC=..., or SERVICE_START_LIMIT_INTERVAL=... if you want a different policy.

If you provide a domain, the installer configures Caddy as a reverse proxy to the local llmhub port and prints HTTPS endpoints. Point the domain's DNS A record at the VPS first or immediately after install; TLS becomes live once DNS propagates.

For Postgres-backed runtime storage, the installer can prompt for PGSTORE_DSN, PGSTORE_SCHEMA, and PGSTORE_USAGE_RETENTION_SECONDS during the run, or you can put them in the same .env file ahead of time. The installer keeps runtime metadata under /var/lib/llmhub/pgstore by setting WRITABLE_PATH=/var/lib/llmhub. LLMHUB_INIT_CONFIG_B64 or LLMHUB_INIT_CONFIG_YAML is needed only for the first seed of an empty Postgres runtime; rerunning the installer against an already-seeded VPS can skip the YAML paste step.

Example .env:

PGSTORE_DSN='postgres://postgres.xxx:password@aws-0-region.pooler.supabase.com:6543/postgres?sslmode=require'
PGSTORE_SCHEMA='llmhub'
PGSTORE_USAGE_RETENTION_SECONDS='60'

Recommended same-directory layout:

llmhub-install/
  install-local.sh
  llmhub
  .env
Manual binary install

If you prefer manual installation:

ARCH="$(uname -m)"
case "$ARCH" in
  x86_64) ARCH="amd64" ;;
  aarch64|arm64) ARCH="arm64" ;;
  *) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;;
esac

TAG="$(curl -fsSLI -o /dev/null -w '%{url_effective}' https://github.com/therealtinhtute/llmhub/releases/latest)"
TAG="${TAG##*/}"

curl -fL \
  "https://github.com/therealtinhtute/llmhub/releases/download/${TAG}/llmhub-linux-${ARCH}" \
  -o llmhub

chmod +x llmhub
sudo install -m 0755 llmhub /usr/local/bin/llmhub
llmhub -h

You can also use:

make install-latest

Use sudo make install-latest when your user cannot write to /usr/local/bin.

Manual service setup

The one-line installer does this automatically. If installing manually, create the system user and directories:

sudo useradd --system --home /var/lib/llmhub --shell /usr/sbin/nologin llmhub
sudo mkdir -p /etc/llmhub /var/lib/llmhub /var/log/llmhub
sudo chown -R llmhub:llmhub /var/lib/llmhub /var/log/llmhub
sudo chmod 750 /var/lib/llmhub

Create the bootstrap env file:

sudo tee /etc/llmhub/llmhub.env >/dev/null <<'EOF'
LLMHUB_HOST=0.0.0.0
LLMHUB_PORT=8317
PGSTORE_DSN='postgres://postgres.xxx:password@aws-0-region.pooler.supabase.com:6543/postgres?sslmode=require'
PGSTORE_SCHEMA='llmhub'
PGSTORE_USAGE_RETENTION_SECONDS='60'
LLMHUB_INIT_CONFIG_B64='<base64 of initial YAML config>'
EOF

Seed the database once:

sudo -u llmhub env $(grep -v '^#' /etc/llmhub/llmhub.env | xargs) \
  /usr/local/bin/llmhub init-db-from-env -env-file /etc/llmhub/llmhub.env

Install the systemd unit:

sudo tee /etc/systemd/system/llmhub.service >/dev/null <<'EOF'
[Unit]
Description=LLMHub proxy server
After=network-online.target
Wants=network-online.target
StartLimitIntervalSec=0

[Service]
Type=simple
User=llmhub
Group=llmhub
WorkingDirectory=/var/lib/llmhub
Environment=HOME=/var/lib/llmhub
EnvironmentFile=-/etc/llmhub/llmhub.env
ExecStartPre=/usr/local/bin/llmhub init-db-from-env -env-file /etc/llmhub/llmhub.env
ExecStart=/usr/local/bin/llmhub
Restart=always
RestartSec=3s

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now llmhub
sudo systemctl status llmhub

Logs: journalctl -u llmhub -f

Build from source

For local development, build from source with Go 1.21+ and Bun:

make build
./llmhub init-db-from-env -env-file .env
./llmhub

Use make dev-pg when you want the dev server to load .env, seed Postgres, and run against the DB-backed runtime.

The initial runtime config is supplied through LLMHUB_INIT_CONFIG_YAML or LLMHUB_INIT_CONFIG_B64, then stored in Postgres. Runtime reads and writes config only from the database after that.

Postgres Durable Runtime

LLMHub runtime is now Postgres-only. Provide PGSTORE_DSN plus one of LLMHUB_INIT_CONFIG_YAML or LLMHUB_INIT_CONFIG_B64 for the initial seed, and Postgres becomes the source of truth for cliproxy config, OAuth/auth records, and the recent management usage queue.

Example Supabase-style configuration:

export PGSTORE_DSN='postgres://postgres.xxx:password@aws-0-region.pooler.supabase.com:6543/postgres?sslmode=require'
export PGSTORE_SCHEMA='llmhub'
export PGSTORE_USAGE_RETENTION_SECONDS='60'
export LLMHUB_INIT_CONFIG_B64="$(printf '%s\n' 'host: 0.0.0.0' 'port: 8317' | base64 | tr -d '\n')"
llmhub init-db-from-env
llmhub

Boot behavior:

  • Startup requires a working Postgres connection and does not fall back to any local durable runtime store.
  • init-db-from-env creates schema/tables if needed and seeds config only when the config row is still empty.
  • Runtime fails fast when the DB has no config yet; run llmhub init-db-from-env or llmhub migrate-local-to-db first.
  • Management edits and OAuth/auth writes persist directly to Postgres.
  • Runtime does not keep durable local auth files, config files, or request archive files. Operational logs stay on stdout/stderr.

Operational notes:

  • Protect PGSTORE_DSN as a secret.
  • Use SSL for remote Postgres, for example sslmode=require.
  • Use a Supabase transaction/session pooler URL suitable for a long-running app.
  • Keep the usage retention short; it is a recent management queue, not a long-term analytics store.
  • If you previously relied on logging-to-file, request log files, or forced error request archives, those local files are intentionally disabled when PGSTORE_DSN is active.

Management Panel

The management panel is served at http://localhost:PORT/management.html once the service is running. It provides visual config editing, OAuth flows, auth file management, quota tracking, and log tailing.

Amp CLI Support

LLMHub includes integrated support for Amp CLI and Amp IDE extensions, enabling you to use your Google/ChatGPT/Claude OAuth subscriptions with Amp's coding tools:

  • Provider route aliases for Amp's API patterns (/api/provider/{provider}/v1...)
  • Management proxy for OAuth authentication and account features
  • Smart model fallback with automatic routing
  • Model mapping to route unavailable models to alternatives (e.g., claude-opus-4.5 → claude-sonnet-4)
  • Security-first design with localhost-only management endpoints

When you need the request/response shape of a specific backend family, use the provider-specific paths instead of the merged /v1/... endpoints:

  • Use /api/provider/{provider}/v1/messages for messages-style backends.
  • Use /api/provider/{provider}/v1beta/models/... for model-scoped generate endpoints.
  • Use /api/provider/{provider}/v1/chat/completions for chat-completions backends.

These routes help you select the protocol surface, but they do not by themselves guarantee a unique inference executor when the same client-visible model name is reused across multiple backends. Inference routing is still resolved from the request model/alias. For strict backend pinning, use unique aliases, prefixes, or otherwise avoid overlapping client-visible model names.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Directories

Path Synopsis
cmd
fetch_antigravity_models command
Command fetch_antigravity_models connects to the Antigravity API using the stored auth credentials and saves the dynamically fetched model list to a JSON file for inspection or offline use.
Command fetch_antigravity_models connects to the Antigravity API using the stored auth credentials and saves the dynamically fetched model list to a JSON file for inspection or offline use.
fetch_codex_models command
Command fetch_codex_models connects to the Codex API using stored auth credentials and saves the dynamically fetched Codex client model catalog to a JSON file for inspection or offline use.
Command fetch_codex_models connects to the Codex API using stored auth credentials and saves the dynamically fetched Codex client model catalog to a JSON file for inspection or offline use.
server command
Package main provides the entry point for the CLI Proxy API server.
Package main provides the entry point for the CLI Proxy API server.
examples
custom-provider command
Package main demonstrates how to create a custom AI provider executor and integrate it with the CLI Proxy API server.
Package main demonstrates how to create a custom AI provider executor and integrate it with the CLI Proxy API server.
http-request command
Package main demonstrates how to use coreauth.Manager.HttpRequest/NewHttpRequest to execute arbitrary HTTP requests with provider credentials injected.
Package main demonstrates how to use coreauth.Manager.HttpRequest/NewHttpRequest to execute arbitrary HTTP requests with provider credentials injected.
translator command
internal
api
Package api provides the HTTP API server implementation for the CLI Proxy API.
Package api provides the HTTP API server implementation for the CLI Proxy API.
api/handlers/management
Package management provides the management API handlers and middleware for configuring the server and managing auth files.
Package management provides the management API handlers and middleware for configuring the server and managing auth files.
api/middleware
Package middleware provides HTTP middleware components for the CLI Proxy API server.
Package middleware provides HTTP middleware components for the CLI Proxy API server.
api/modules
Package modules provides a pluggable routing module system for extending the API server with optional features without modifying core routing logic.
Package modules provides a pluggable routing module system for extending the API server with optional features without modifying core routing logic.
api/modules/amp
Package amp implements the Amp CLI routing module, providing OAuth-based integration with Amp CLI for ChatGPT and Anthropic subscriptions.
Package amp implements the Amp CLI routing module, providing OAuth-based integration with Amp CLI for ChatGPT and Anthropic subscriptions.
auth
Package auth provides authentication functionality for various AI service providers.
Package auth provides authentication functionality for various AI service providers.
auth/antigravity
Package antigravity provides OAuth2 authentication functionality for the Antigravity provider.
Package antigravity provides OAuth2 authentication functionality for the Antigravity provider.
auth/claude
Package claude provides OAuth2 authentication functionality for Anthropic's Claude API.
Package claude provides OAuth2 authentication functionality for Anthropic's Claude API.
auth/codex
Package codex provides authentication and token management for OpenAI's Codex API.
Package codex provides authentication and token management for OpenAI's Codex API.
auth/empty
Package empty provides a no-operation token storage implementation.
Package empty provides a no-operation token storage implementation.
auth/gemini
Package gemini provides authentication and token management functionality for Google's Gemini AI services.
Package gemini provides authentication and token management functionality for Google's Gemini AI services.
auth/kimi
Package kimi provides authentication and token management for Kimi (Moonshot AI) API.
Package kimi provides authentication and token management for Kimi (Moonshot AI) API.
auth/vertex
Package vertex provides token storage for Google Vertex AI Gemini via service account credentials.
Package vertex provides token storage for Google Vertex AI Gemini via service account credentials.
auth/xai
Package xai provides OAuth2 authentication helpers for xAI Grok.
Package xai provides OAuth2 authentication helpers for xAI Grok.
browser
Package browser provides cross-platform functionality for opening URLs in the default web browser.
Package browser provides cross-platform functionality for opening URLs in the default web browser.
buildinfo
Package buildinfo exposes compile-time metadata shared across the server.
Package buildinfo exposes compile-time metadata shared across the server.
cmd
Package cmd provides command-line interface functionality for the CLI Proxy API server.
Package cmd provides command-line interface functionality for the CLI Proxy API server.
config
Package config provides configuration management for the CLI Proxy API server.
Package config provides configuration management for the CLI Proxy API server.
constant
Package constant defines provider name constants used throughout the CLI Proxy API.
Package constant defines provider name constants used throughout the CLI Proxy API.
interfaces
Package interfaces defines the core interfaces and shared structures for the CLI Proxy API server.
Package interfaces defines the core interfaces and shared structures for the CLI Proxy API server.
logging
Package logging provides Gin middleware for HTTP request logging and panic recovery.
Package logging provides Gin middleware for HTTP request logging and panic recovery.
misc
Package misc provides miscellaneous utility functions for the CLI Proxy API server.
Package misc provides miscellaneous utility functions for the CLI Proxy API server.
registry
Package registry provides model definitions and lookup helpers for various AI providers.
Package registry provides model definitions and lookup helpers for various AI providers.
runtime/executor
Package executor provides runtime execution capabilities for various AI service providers.
Package executor provides runtime execution capabilities for various AI service providers.
thinking
Package thinking provides unified thinking configuration processing.
Package thinking provides unified thinking configuration processing.
thinking/provider/antigravity
Package antigravity implements thinking configuration for Antigravity API format.
Package antigravity implements thinking configuration for Antigravity API format.
thinking/provider/claude
Package claude implements thinking configuration scaffolding for Claude models.
Package claude implements thinking configuration scaffolding for Claude models.
thinking/provider/codex
Package codex implements thinking configuration for Codex (OpenAI Responses API) models.
Package codex implements thinking configuration for Codex (OpenAI Responses API) models.
thinking/provider/gemini
Package gemini implements thinking configuration for Gemini models.
Package gemini implements thinking configuration for Gemini models.
thinking/provider/geminicli
Package geminicli implements thinking configuration for Gemini CLI API format.
Package geminicli implements thinking configuration for Gemini CLI API format.
thinking/provider/kimi
Package kimi implements thinking configuration for Kimi (Moonshot AI) models.
Package kimi implements thinking configuration for Kimi (Moonshot AI) models.
thinking/provider/openai
Package openai implements thinking configuration for OpenAI/Codex models.
Package openai implements thinking configuration for OpenAI/Codex models.
thinking/provider/xai
Package xai implements thinking configuration for xAI Grok Responses API models.
Package xai implements thinking configuration for xAI Grok Responses API models.
translator/antigravity/claude
Package claude provides request translation functionality for Claude Code API compatibility.
Package claude provides request translation functionality for Claude Code API compatibility.
translator/antigravity/gemini
Package gemini provides request translation functionality for Gemini CLI to Gemini API compatibility.
Package gemini provides request translation functionality for Gemini CLI to Gemini API compatibility.
translator/antigravity/openai/chat-completions
Package openai provides request translation functionality for OpenAI to Gemini CLI API compatibility.
Package openai provides request translation functionality for OpenAI to Gemini CLI API compatibility.
translator/claude/gemini
Package gemini provides request translation functionality for Gemini to Claude Code API compatibility.
Package gemini provides request translation functionality for Gemini to Claude Code API compatibility.
translator/claude/gemini-cli
Package geminiCLI provides request translation functionality for Gemini CLI to Claude Code API compatibility.
Package geminiCLI provides request translation functionality for Gemini CLI to Claude Code API compatibility.
translator/claude/openai/chat-completions
Package openai provides request translation functionality for OpenAI to Claude Code API compatibility.
Package openai provides request translation functionality for OpenAI to Claude Code API compatibility.
translator/codex/claude
Package claude provides request translation functionality for Claude Code API compatibility.
Package claude provides request translation functionality for Claude Code API compatibility.
translator/codex/gemini
Package gemini provides request translation functionality for Codex to Gemini API compatibility.
Package gemini provides request translation functionality for Codex to Gemini API compatibility.
translator/codex/gemini-cli
Package geminiCLI provides request translation functionality for Gemini CLI to Codex API compatibility.
Package geminiCLI provides request translation functionality for Gemini CLI to Codex API compatibility.
translator/codex/openai/chat-completions
Package openai provides utilities to translate OpenAI Chat Completions request JSON into OpenAI Responses API request JSON using gjson/sjson.
Package openai provides utilities to translate OpenAI Chat Completions request JSON into OpenAI Responses API request JSON using gjson/sjson.
translator/gemini-cli/claude
Package claude provides request translation functionality for Claude Code API compatibility.
Package claude provides request translation functionality for Claude Code API compatibility.
translator/gemini-cli/gemini
Package gemini provides request translation functionality for Gemini CLI to Gemini API compatibility.
Package gemini provides request translation functionality for Gemini CLI to Gemini API compatibility.
translator/gemini-cli/openai/chat-completions
Package openai provides request translation functionality for OpenAI to Gemini CLI API compatibility.
Package openai provides request translation functionality for OpenAI to Gemini CLI API compatibility.
translator/gemini/claude
Package claude provides request translation functionality for Claude API.
Package claude provides request translation functionality for Claude API.
translator/gemini/gemini
Package gemini provides in-provider request normalization for Gemini API.
Package gemini provides in-provider request normalization for Gemini API.
translator/gemini/gemini-cli
Package gemini provides request translation functionality for Claude API.
Package gemini provides request translation functionality for Claude API.
translator/gemini/openai/chat-completions
Package openai provides request translation functionality for OpenAI to Gemini API compatibility.
Package openai provides request translation functionality for OpenAI to Gemini API compatibility.
translator/openai/claude
Package claude provides request translation functionality for Anthropic to OpenAI API.
Package claude provides request translation functionality for Anthropic to OpenAI API.
translator/openai/gemini
Package gemini provides request translation functionality for Gemini to OpenAI API.
Package gemini provides request translation functionality for Gemini to OpenAI API.
translator/openai/gemini-cli
Package geminiCLI provides request translation functionality for Gemini to OpenAI API.
Package geminiCLI provides request translation functionality for Gemini to OpenAI API.
translator/openai/openai/chat-completions
Package openai provides request translation functionality for OpenAI to Gemini CLI API compatibility.
Package openai provides request translation functionality for OpenAI to Gemini CLI API compatibility.
translator/translator
Package translator provides request and response translation functionality between different AI API formats.
Package translator provides request and response translation functionality between different AI API formats.
tui
Package tui provides a terminal-based management interface for LLMHub.
Package tui provides a terminal-based management interface for LLMHub.
util
Package util provides utility functions for the CLI Proxy API server.
Package util provides utility functions for the CLI Proxy API server.
watcher
clients.go implements watcher client lifecycle logic and persistence helpers.
clients.go implements watcher client lifecycle logic and persistence helpers.
watcher/diff
auth_diff.go computes human-readable diffs for auth file field changes.
auth_diff.go computes human-readable diffs for auth file field changes.
watcher/synthesizer
Package synthesizer provides auth synthesis strategies for the watcher package.
Package synthesizer provides auth synthesis strategies for the watcher package.
sdk
api
Package api exposes helpers for embedding LLMHub.
Package api exposes helpers for embedding LLMHub.
api/handlers
Package handlers provides core API handler functionality for the CLI Proxy API server.
Package handlers provides core API handler functionality for the CLI Proxy API server.
api/handlers/claude
Package claude provides HTTP handlers for Claude API code-related functionality.
Package claude provides HTTP handlers for Claude API code-related functionality.
api/handlers/gemini
Package gemini provides HTTP handlers for Gemini CLI API functionality.
Package gemini provides HTTP handlers for Gemini CLI API functionality.
api/handlers/openai
Package openai provides HTTP handlers for OpenAI API endpoints.
Package openai provides HTTP handlers for OpenAI API endpoints.
cliproxy
Package cliproxy provides the core service implementation for the CLI Proxy API.
Package cliproxy provides the core service implementation for the CLI Proxy API.
config
Package config provides the public SDK configuration API.
Package config provides the public SDK configuration API.
logging
Package logging re-exports request logging primitives for SDK consumers.
Package logging re-exports request logging primitives for SDK consumers.
translator
Package translator provides types and functions for converting chat requests and responses between different schemas.
Package translator provides types and functions for converting chat requests and responses between different schemas.
translator/builtin
Package builtin exposes the built-in translator registrations for SDK users.
Package builtin exposes the built-in translator registrations for SDK users.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL