Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名) - 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块) - docreader proto 描述符采用等长替换,保持序列化字节布局有效 - Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像 - 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
113 lines
4.7 KiB
Go
113 lines
4.7 KiB
Go
// Package providers registers the OpenRouter gateway.
|
|
//
|
|
// Facts (https://openrouter.ai/docs/guides/best-practices/reasoning-tokens —
|
|
// the old /docs/use-cases/ path now redirects there):
|
|
// - `max_tokens` is documented as deprecated ("Maximum tokens
|
|
// (deprecated, use max_completion_tokens)") and some upstreams enforce a
|
|
// minimum of 16 on it, so this vendor keeps the protocol default
|
|
// `max_completion_tokens`;
|
|
// - thinking is expressed with the unified `reasoning` object
|
|
// ({"effort": ...} or {"enabled": bool}) which OpenRouter translates for
|
|
// every upstream. The effort enum is
|
|
// max | xhigh | high | medium | low | minimal | none, which is why xhigh
|
|
// and max are enabled vendor-wide; per-model support is gated by
|
|
// `supported_efforts` in /api/v1/models, and models flagged mandatory
|
|
// (today gemini-3.8-flash, gemini-3.1-pro-preview, glm-5.3, grok-4.6)
|
|
// reject an off switch entirely. Claude upstreams reject "none" and send
|
|
// minimal as low, so the anthropic/* family is "off": null with minimal
|
|
// folded onto low;
|
|
// - Anthropic-routed models honour `cache_control` breakpoints, ephemeral
|
|
// with a 5m or 1h ttl and at most four explicit breakpoints (the
|
|
// anthropic/* family sets cache_control_format "anthropic");
|
|
// - `prompt_cache_key` is accepted as the sticky routing key (OpenRouter's
|
|
// own preferred field is `session_id`) and usage reports
|
|
// prompt_tokens_details.cached_tokens;
|
|
// - embeddings are routed through the same /api/v1 base
|
|
// (https://openrouter.ai/docs/api_reference/embeddings).
|
|
//
|
|
// Unverified: GET /api/v1/models lists chat models only — embedding models
|
|
// live behind /api/v1/embeddings/models — so any future auto-sync of this
|
|
// catalog has to read both listings or it will silently lose embeddings.
|
|
package providers
|
|
|
|
import (
|
|
_ "embed"
|
|
|
|
"academy/internal/models/api"
|
|
"academy/internal/types"
|
|
)
|
|
|
|
//go:embed assets/openrouter.svg
|
|
var openrouterIcon []byte
|
|
|
|
// OpenrouterID is the provider identifier stored on model rows.
|
|
const OpenrouterID = "openrouter"
|
|
|
|
// OpenrouterBaseURL is the OpenAI-compatible gateway endpoint.
|
|
const OpenrouterBaseURL = "https://openrouter.ai/api/v1"
|
|
|
|
func newOpenrouterProvider() *Definition {
|
|
return &Definition{
|
|
ID: OpenrouterID,
|
|
Name: "OpenRouter",
|
|
Names: map[string]string{"zh-CN": "OpenRouter"},
|
|
Description: "openai/gpt-5.5, anthropic/claude-opus-5, google/gemini-3.8-flash, " +
|
|
"deepseek/deepseek-v4-pro, etc.",
|
|
Website: "https://openrouter.ai",
|
|
Icon: openrouterIcon,
|
|
API: api.APIOpenAICompletions,
|
|
Order: 40,
|
|
RequiresAuth: true,
|
|
Auth: AuthBearer,
|
|
URLPatterns: []string{"openrouter.ai"},
|
|
DefaultBaseURLs: map[types.ModelType]string{
|
|
types.ModelTypeKnowledgeQA: OpenrouterBaseURL,
|
|
types.ModelTypeEmbedding: OpenrouterBaseURL,
|
|
types.ModelTypeRerank: OpenrouterBaseURL,
|
|
types.ModelTypeVLLM: OpenrouterBaseURL,
|
|
},
|
|
ModelTypes: []types.ModelType{
|
|
types.ModelTypeKnowledgeQA,
|
|
types.ModelTypeEmbedding,
|
|
types.ModelTypeRerank,
|
|
types.ModelTypeVLLM,
|
|
types.ModelTypeASR,
|
|
},
|
|
Compat: VendorCompat{
|
|
Transcriptions: api.TranscriptionsCompat{
|
|
// https://openrouter.ai/docs/api/api-reference/stt/create-transcription:
|
|
// OpenAI-style multipart file + model, json by default. "Max 25
|
|
// MB; send larger files as base64 JSON via input_audio."
|
|
MaxFileBytes: api.Ptr(25 << 20),
|
|
// language is an ISO-639-1 form field. The format "is derived
|
|
// from the filename extension", with no closed list.
|
|
LanguageParam: api.Ptr(api.LanguageForm),
|
|
},
|
|
Embeddings: api.EmbeddingsCompat{
|
|
// https://openrouter.ai/docs/api/api-reference/embeddings/create-embeddings:
|
|
// model, input, dimensions, encoding_format, input_type, provider,
|
|
// user. input_type is a free-form string handed to whichever
|
|
// upstream serves the model ("e.g. search_query,
|
|
// search_document"), so its vocabulary is the upstream's, and on
|
|
// an asymmetric model it changes the document vectors. Not
|
|
// declared, for the reason Jina's task is not
|
|
// (Tencent/WeKnora#1401).
|
|
SendEncodingFormat: api.Ptr(true),
|
|
DimensionsField: api.Ptr("dimensions"),
|
|
},
|
|
OpenAICompletions: api.OpenAICompletionsCompat{
|
|
ThinkingFormat: api.Ptr(api.ThinkingFormatOpenRouter),
|
|
SupportsReasoningEffort: api.Ptr(true),
|
|
PromptCacheKey: api.Ptr(true),
|
|
PromptCacheAccounting: api.Ptr(true),
|
|
},
|
|
},
|
|
// The reasoning.effort enum covers the whole ladder; per-model
|
|
// support is gated upstream, not here.
|
|
ThinkingLevels: api.ThinkingLevelMap{
|
|
api.ReasoningXHigh: api.StringPtr("xhigh"),
|
|
api.ReasoningMax: api.StringPtr("max"),
|
|
},
|
|
}
|
|
}
|