开源项目 GoModel 基于 Go 语言构建,提供 AI 网关功能,代码已发布至 GitHub。该项目于 4 月 21 日在 Hacker News 的 Show HN 板块亮相,获得 102 个赞。GoModel 旨在利用 Go 语言的高并发特性,为 AI 应用提供统一的模型接入和管理层,简化多模型服务的集成与调用流程。
原文 · 未翻译
GoModel - AI Gateway in Go
A fast and lightweight AI gateway written in Go, providing a unified OpenAI-compatible API for OpenAI, Anthropic, Gemini, DeepSeek, xAI, Groq, OpenRouter, Z.ai, Azure OpenAI, Oracle, Ollama, and more.
⚠️ Avoid passing secrets via -e on the command line - they can leak via shell history and process lists. For production, use docker run --env-file .env to load API keys from a file instead.
That's it! GoModel automatically detects which providers are available based on the credentials you supply.
Supported LLM Providers
Example model identifiers are illustrative and subject to change; consult provider catalogs for current models. Feature columns reflect gateway API support, not every individual model capability exposed by an upstream provider.
开源项目 GoModel 基于 Go 语言构建,提供 AI 网关功能,代码已发布至 GitHub。该项目于 4 月 21 日在 Hacker News 的 Show HN 板块亮相,获得 102 个赞。GoModel 旨在利用 Go 语言的高并发特性,为 AI 应用提供统一的模型接入和管理层,简化多模型服务的集成与调用流程。
原文 · 保持原样,未翻译
GoModel - AI Gateway in Go
A fast and lightweight AI gateway written in Go, providing a unified OpenAI-compatible API for OpenAI, Anthropic, Gemini, DeepSeek, xAI, Groq, OpenRouter, Z.ai, Azure OpenAI, Oracle, Ollama, and more.
For Z.ai's GLM Coding Plan, set ZAI_BASE_URL=https://api.z.ai/api/coding/paas/v4. Xiaomi MiMo TTS (mimo-v2.5-tts*) and ASR (mimo-v2.5-asr) are served through /v1/audio/speech and /v1/audio/transcriptions (translated to MiMo's chat-completions audio dialect) as well as directly via chat completions; for 1M context append [1m] to the model ID and list it in XIAOMI_MODELS. Configured model lists are available for every provider with _MODELS, for example OPENROUTER_MODELS=openai/gpt-oss-120b,anthropic/claude-sonnet-4 or ORACLE_MODELS=openai.gpt-oss-120b,xai.grok-3. DeepSeek defaults to https://api.deepseek.com; set DEEPSEEK_BASE_URL only when using a compatible proxy or alternate DeepSeek endpoint. By default, CONFIGURED_PROVIDER_MODELS_MODE=fallback uses those lists only when upstream /models is unavailable or empty. Set CONFIGURED_PROVIDER_MODELS_MODE=allowlist to expose only configured models for providers that define a list, skipping their upstream /models calls. For vLLM, set VLLM_API_KEY only if the upstream server was started with --api-key. To register multiple instances of the same provider type without config.yaml, use suffixed env vars such as OPENAI_EAST_API_KEY and OPENAI_EAST_BASE_URL; add OPENAI_EAST_MODELS to configure that instance's model list. This registers provider openai-east with type openai. Vertex AI follows the same suffix pattern — VERTEX_US_PROJECT registers provider vertex-us. Vertex project and location env vars must match the instance prefix: for a suffixed instance such as VERTEX_US_PROJECT, also set VERTEX_US_LOCATION and any other suffixed settings for that instance, rather than the generic VERTEX_PROJECT / VERTEX_LOCATION. VERTEX_AUTH_TYPE defaults to Application Default Credentials (gcp_adc).
Endpoint Method Description /v1/chat/completions POST Chat completions (streaming supported) /v1/responses POST OpenAI Responses API /v1/conversations POST Create a conversation (gateway-managed) /v1/conversations/{id} GET Retrieve a conversation /v1/conversations/{id} POST Replace conversation metadata in full /v1/conversations/{id} DELETE Delete a conversation /v1/embeddings POST Text embeddings /v1/models GET List available models /v1/files POST Upload a file (OpenAI-compatible multipart) /v1/files GET List files /v1/files/{id} GET Retrieve file metadata /v1/files/{id} DELETE Delete a file /v1/files/{id}/content GET Retrieve raw file content /v1/batches POST Create a native provider batch (OpenAI-compatible schema; inline requests supported where provider-native) /v1/batches GET List stored batches /v1/batches/{id} GET Retrieve one stored batch /v1/batches/{id}/cancel POST Cancel a pending batch /v1/batches/{id}/results GET Retrieve native batch results when available
/v1/chat/completions
/v1/responses
/v1/conversations
/v1/conversations/{id}
/v1/conversations/{id}
/v1/conversations/{id}
/v1/embeddings
/v1/models
/v1/files
/v1/files
/v1/files/{id}
/v1/files/{id}
/v1/files/{id}/content
/v1/batches
requests
/v1/batches
/v1/batches/{id}
/v1/batches/{id}/cancel
/v1/batches/{id}/results
Anthropic-Compatible API
Endpoint Method Description /v1/messages POST Anthropic Messages API through translated model routing (streaming supported) /v1/messages/count_tokens POST Heuristic Anthropic Messages input token estimate
/v1/messages
/v1/messages/count_tokens
Provider Passthrough
Endpoint Method Description /p/{provider}/... GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS Provider-native passthrough with opaque upstream responses
/p/{provider}/...
Admin Endpoints
Endpoint Method Description /admin/dashboard GET Admin dashboard UI /admin/runtime/config GET Admin runtime configuration /admin/cache/overview GET Cache statistics overview /admin/usage/summary GET Aggregate token usage statistics /admin/usage/daily GET Per-period token usage breakdown /admin/usage/models GET Usage breakdown by model /admin/usage/user-paths GET Usage breakdown by user path /admin/usage/log GET Paginated usage log entries /admin/audit/detail GET Detailed audit entry information /admin/audit/log GET Paginated audit log entries /admin/audit/conversation GET Conversation thread around one audit entry /admin/providers/status GET Provider availability status /admin/runtime/refresh POST Refresh runtime configuration /admin/models GET List models with provider type /admin/models/categories GET List model categories /admin/model-overrides GET List model overrides /admin/model-overrides PUT Create/update model override /admin/model-overrides DELETE Remove model override /admin/auth-keys GET List authentication keys
/admin/dashboard
/admin/runtime/config
/admin/cache/overview
/admin/usage/summary
/admin/usage/daily
/admin/usage/models
/admin/usage/user-paths
/admin/usage/log
/admin/audit/detail
/admin/audit/log
/admin/audit/conversation
/admin/providers/status
/admin/runtime/refresh
/admin/models
/admin/models/categories
/admin/model-overrides
/admin/model-overrides
/admin/model-overrides
/admin/auth-keys
Legacy alias: Until 2026-08-09, all admin endpoints are also reachable under /admin/api/v1/*. Legacy responses include Deprecation: true and Sunset: Sun, 09 Aug 2026 00:00:00 GMT headers. The endpoint formerly at /admin/api/v1/dashboard/config moved to /admin/runtime/config on the new prefix.
Legacy alias: Until 2026-08-09, all admin endpoints are also reachable under /admin/api/v1/*. Legacy responses include Deprecation: true and Sunset: Sun, 09 Aug 2026 00:00:00 GMT headers. The endpoint formerly at /admin/api/v1/dashboard/config moved to /admin/runtime/config on the new prefix.
/admin/api/v1/*
Deprecation: true
Sunset: Sun, 09 Aug 2026 00:00:00 GMT
/admin/api/v1/dashboard/config
/admin/runtime/config
Operations Endpoints
Endpoint Method Description /health GET Health check /metrics GET Prometheus metrics (experimental, when enabled) /swagger/index.html GET Swagger UI (when enabled)
/health
/metrics
/swagger/index.html
Gateway Configuration
GoModel is configured through environment variables and an optional config.yaml. Environment variables override YAML values. See .env.template and config/config.example.yaml for the available options.
config.yaml
.env.template
config/config.example.yaml
Key settings:
Variable Default Description PORT 8080 Server port BASE_PATH / Mount the gateway under a path prefix such as /g GOMODEL_MASTER_KEY (none) API key for authentication USER_PATH_HEADER X-GoModel-User-Path Header used to read/write request user_path values ENABLE_PASSTHROUGH_ROUTES true Enable provider-native passthrough routes under /p/{provider}/... ALLOW_PASSTHROUGH_V1_ALIAS true Allow /p/{provider}/v1/... aliases while keeping /p/{provider}/... canonical ENABLED_PASSTHROUGH_PROVIDERS openai,anthropic,openrouter,zai,vllm,deepseek Comma-separated list of enabled passthrough providers GEMINI_API_MODE native Gemini AI Studio upstream mode: native or openai_compatible VERTEX_API_MODE native Vertex AI Gemini upstream mode: native or openai_compatible USE_GOOGLE_GEMINI_NATIVE_API true Legacy global Gemini mode toggle used when per-provider *_API_MODE is unset STORAGE_TYPE sqlite Storage backend (sqlite, postgresql, mongodb) METRICS_ENABLED false Enable Prometheus metrics (experimental) LOGGING_ENABLED false Enable audit logging DASHBOARD_LIVE_LOGS_ENABLED true Stream realtime dashboard log previews with bounded replay DASHBOARD_LIVE_LOGS_BUFFER_SIZE 10000 Max in-memory live events retained; increase above ~1000 msgs/sec or bursty traffic DASHBOARD_LIVE_LOGS_REPLAY_LIMIT 1000 Max events replayed after reconnect; increase for longer reconnect windows DASHBOARD_LIVE_LOGS_HEARTBEAT_SECONDS 15 SSE heartbeat interval; lower when proxies need faster liveness checks GUARDRAILS_ENABLED false Enable the configured guardrails pipeline
PORT
8080
BASE_PATH
/
/g
GOMODEL_MASTER_KEY
USER_PATH_HEADER
X-GoModel-User-Path
user_path
ENABLE_PASSTHROUGH_ROUTES
true
/p/{provider}/...
⚠️ Avoid passing secrets via -e on the command line - they can leak via shell history and process lists. For production, use docker run --env-file .env to load API keys from a file instead.
That's it! GoModel automatically detects which providers are available based on the credentials you supply.
Supported LLM Providers
Example model identifiers are illustrative and subject to change; consult provider catalogs for current models. Feature columns reflect gateway API support, not every individual model capability exposed by an upstream provider.
For Z.ai's GLM Coding Plan, set ZAI_BASE_URL=https://api.z.ai/api/coding/paas/v4. Xiaomi MiMo TTS (mimo-v2.5-tts*) and ASR (mimo-v2.5-asr) are served through /v1/audio/speech and /v1/audio/transcriptions (translated to MiMo's chat-completions audio dialect) as well as directly via chat completions; for 1M context append [1m] to the model ID and list it in XIAOMI_MODELS. Configured model lists are available for every provider with _MODELS, for example OPENROUTER_MODELS=openai/gpt-oss-120b,anthropic/claude-sonnet-4 or ORACLE_MODELS=openai.gpt-oss-120b,xai.grok-3. DeepSeek defaults to https://api.deepseek.com; set DEEPSEEK_BASE_URL only when using a compatible proxy or alternate DeepSeek endpoint. By default, CONFIGURED_PROVIDER_MODELS_MODE=fallback uses those lists only when upstream /models is unavailable or empty. Set CONFIGURED_PROVIDER_MODELS_MODE=allowlist to expose only configured models for providers that define a list, skipping their upstream /models calls. For vLLM, set VLLM_API_KEY only if the upstream server was started with --api-key. To register multiple instances of the same provider type without config.yaml, use suffixed env vars such as OPENAI_EAST_API_KEY and OPENAI_EAST_BASE_URL; add OPENAI_EAST_MODELS to configure that instance's model list. This registers provider openai-east with type openai. Vertex AI follows the same suffix pattern — VERTEX_US_PROJECT registers provider vertex-us. Vertex project and location env vars must match the instance prefix: for a suffixed instance such as VERTEX_US_PROJECT, also set VERTEX_US_LOCATION and any other suffixed settings for that instance, rather than the generic VERTEX_PROJECT / VERTEX_LOCATION. VERTEX_AUTH_TYPE defaults to Application Default Credentials (gcp_adc).
Endpoint Method Description /v1/chat/completions POST Chat completions (streaming supported) /v1/responses POST OpenAI Responses API /v1/conversations POST Create a conversation (gateway-managed) /v1/conversations/{id} GET Retrieve a conversation /v1/conversations/{id} POST Replace conversation metadata in full /v1/conversations/{id} DELETE Delete a conversation /v1/embeddings POST Text embeddings /v1/models GET List available models /v1/files POST Upload a file (OpenAI-compatible multipart) /v1/files GET List files /v1/files/{id} GET Retrieve file metadata /v1/files/{id} DELETE Delete a file /v1/files/{id}/content GET Retrieve raw file content /v1/batches POST Create a native provider batch (OpenAI-compatible schema; inline requests supported where provider-native) /v1/batches GET List stored batches /v1/batches/{id} GET Retrieve one stored batch /v1/batches/{id}/cancel POST Cancel a pending batch /v1/batches/{id}/results GET Retrieve native batch results when available
/v1/chat/completions
/v1/responses
/v1/conversations
/v1/conversations/{id}
/v1/conversations/{id}
/v1/conversations/{id}
/v1/embeddings
/v1/models
/v1/files
/v1/files
/v1/files/{id}
/v1/files/{id}
/v1/files/{id}/content
/v1/batches
requests
/v1/batches
/v1/batches/{id}
/v1/batches/{id}/cancel
/v1/batches/{id}/results
Anthropic-Compatible API
Endpoint Method Description /v1/messages POST Anthropic Messages API through translated model routing (streaming supported) /v1/messages/count_tokens POST Heuristic Anthropic Messages input token estimate
/v1/messages
/v1/messages/count_tokens
Provider Passthrough
Endpoint Method Description /p/{provider}/... GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS Provider-native passthrough with opaque upstream responses
/p/{provider}/...
Admin Endpoints
Endpoint Method Description /admin/dashboard GET Admin dashboard UI /admin/runtime/config GET Admin runtime configuration /admin/cache/overview GET Cache statistics overview /admin/usage/summary GET Aggregate token usage statistics /admin/usage/daily GET Per-period token usage breakdown /admin/usage/models GET Usage breakdown by model /admin/usage/user-paths GET Usage breakdown by user path /admin/usage/log GET Paginated usage log entries /admin/audit/detail GET Detailed audit entry information /admin/audit/log GET Paginated audit log entries /admin/audit/conversation GET Conversation thread around one audit entry /admin/providers/status GET Provider availability status /admin/runtime/refresh POST Refresh runtime configuration /admin/models GET List models with provider type /admin/models/categories GET List model categories /admin/model-overrides GET List model overrides /admin/model-overrides PUT Create/update model override /admin/model-overrides DELETE Remove model override /admin/auth-keys GET List authentication keys
/admin/dashboard
/admin/runtime/config
/admin/cache/overview
/admin/usage/summary
/admin/usage/daily
/admin/usage/models
/admin/usage/user-paths
/admin/usage/log
/admin/audit/detail
/admin/audit/log
/admin/audit/conversation
/admin/providers/status
/admin/runtime/refresh
/admin/models
/admin/models/categories
/admin/model-overrides
/admin/model-overrides
/admin/model-overrides
/admin/auth-keys
Legacy alias: Until 2026-08-09, all admin endpoints are also reachable under /admin/api/v1/*. Legacy responses include Deprecation: true and Sunset: Sun, 09 Aug 2026 00:00:00 GMT headers. The endpoint formerly at /admin/api/v1/dashboard/config moved to /admin/runtime/config on the new prefix.
Legacy alias: Until 2026-08-09, all admin endpoints are also reachable under /admin/api/v1/*. Legacy responses include Deprecation: true and Sunset: Sun, 09 Aug 2026 00:00:00 GMT headers. The endpoint formerly at /admin/api/v1/dashboard/config moved to /admin/runtime/config on the new prefix.
/admin/api/v1/*
Deprecation: true
Sunset: Sun, 09 Aug 2026 00:00:00 GMT
/admin/api/v1/dashboard/config
/admin/runtime/config
Operations Endpoints
Endpoint Method Description /health GET Health check /metrics GET Prometheus metrics (experimental, when enabled) /swagger/index.html GET Swagger UI (when enabled)
/health
/metrics
/swagger/index.html
Gateway Configuration
GoModel is configured through environment variables and an optional config.yaml. Environment variables override YAML values. See .env.template and config/config.example.yaml for the available options.
config.yaml
.env.template
config/config.example.yaml
Key settings:
Variable Default Description PORT 8080 Server port BASE_PATH / Mount the gateway under a path prefix such as /g GOMODEL_MASTER_KEY (none) API key for authentication USER_PATH_HEADER X-GoModel-User-Path Header used to read/write request user_path values ENABLE_PASSTHROUGH_ROUTES true Enable provider-native passthrough routes under /p/{provider}/... ALLOW_PASSTHROUGH_V1_ALIAS true Allow /p/{provider}/v1/... aliases while keeping /p/{provider}/... canonical ENABLED_PASSTHROUGH_PROVIDERS openai,anthropic,openrouter,zai,vllm,deepseek Comma-separated list of enabled passthrough providers GEMINI_API_MODE native Gemini AI Studio upstream mode: native or openai_compatible VERTEX_API_MODE native Vertex AI Gemini upstream mode: native or openai_compatible USE_GOOGLE_GEMINI_NATIVE_API true Legacy global Gemini mode toggle used when per-provider *_API_MODE is unset STORAGE_TYPE sqlite Storage backend (sqlite, postgresql, mongodb) METRICS_ENABLED false Enable Prometheus metrics (experimental) LOGGING_ENABLED false Enable audit logging DASHBOARD_LIVE_LOGS_ENABLED true Stream realtime dashboard log previews with bounded replay DASHBOARD_LIVE_LOGS_BUFFER_SIZE 10000 Max in-memory live events retained; increase above ~1000 msgs/sec or bursty traffic DASHBOARD_LIVE_LOGS_REPLAY_LIMIT 1000 Max events replayed after reconnect; increase for longer reconnect windows DASHBOARD_LIVE_LOGS_HEARTBEAT_SECONDS 15 SSE heartbeat interval; lower when proxies need faster liveness checks GUARDRAILS_ENABLED false Enable the configured guardrails pipeline