Repository navigation
feat(gemini,antigravity): add Gemini 4 Hydrogen/Carbon support and dynamic effort variant routing - #8778
Closed
universonic wants to merge 7 commits into
Closed
feat(gemini,antigravity): add Gemini 4 Hydrogen/Carbon support and dynamic effort variant routing#8778universonic wants to merge 7 commits into
universonic wants to merge 7 commits into
Conversation
Contributor
|
All contributors have signed the CLA. ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
doublepi123
added a commit
to doublepi123/sub2api
that referenced
this pull request
Nov 14, 2026
Port upstream Wei-Shaw#8778 (which also carries the Wei-Shaw#8746 Hydrogen billing) on top of the fork's Carbon adaptation. Hydrogen: - Antigravity lists Hydrogen only as gemini-4-hydrogen-low/-medium/-high/ -xhigh (production account 8). Default mapping adds the four suffixes and a bare self-mapped alias that resolves to a real tier; static catalog, Gemini API / CLI catalogs, frontend whitelist and presets follow. - xhigh/max select -xhigh where the account has it and fall back to -high for families without it; native thinkingBudget is normalized to thinkingLevel for Hydrogen as for Carbon. - Pricing: $1.50 / $7.50 / $0.075 per MTok, priority 1.8x. Claude 5.5 on Antigravity: - claude-opus-5-5 / claude-sonnet-5-5 default mappings become dynamic self-maps routed by effort (default stays -high); explicit fixed admin mappings still win; native Anthropic accounts are untouched. - Scheduling admits bare names on tier-only accounts; model cooldowns and billing tiers follow the variant actually forwarded. Fork semantics kept over the PR: - Carbon keeps the bare self-map plus measured -low/-medium/-high suffixes and defaults to medium when the client pins no level. - Variant selection keeps the fork's body-based parser where an explicit thinking budget beats effort; PR tests were adapted to that contract.
Author
更新说明:同步
|
Author
|
@Wei-Shaw 这些改动对提升 Gemini 用户使用体验有关键帮助,请求合并,谢谢。 |
doublepi123
added a commit
to doublepi123/sub2api
that referenced
this pull request
Nov 17, 2026
Sync 185 upstream commits (106 non-merge), including the Gemini 4 Hydrogen billing PR Wei-Shaw#8746, Vertex multi-region endpoints, OpenAI Ultra Fast group gating, scheduler bucket-merged snapshot loading and the Gemini native content session hash. Conflict resolutions that keep fork behavior: - VERSION and the fork's single-job release workflow are kept. - Hydrogen billing keeps the fork's tier-alias match; Wei-Shaw#8746's card and snapshot entry were already present from the Wei-Shaw#8778 port, so nothing is duplicated. - Antigravity compat variant selection keeps the fork's body-based level (explicit thinking budget beats effort); upstream's now-unused geminiThinkingLevelFromClaudeBody helper is dropped. includeThoughts follows upstream (enabled on streams) together with its new tests. - Chat Completions / Responses to Anthropic keep the fork's Kiro branch and gain upstream's one-shot retry after a concurrent token rotation. - Scheduler credential projection keeps the Kiro catalog and Gemini explicit-cache keys and adds openai_capabilities. - Gemini native sticky sessions take upstream's content hash, which keeps the fork's API-key isolation and stable first-turn anchor. Fork follow-ups in this merge: - 252_fork_group_usage_rollup_published_timezone.sql restores the published-timezone invalidation from fork migration 228, which upstream 251 replaced with the session timezone; verified on Postgres 18 with a UTC session against Asia/Shanghai buckets. - The Kiro snapshot test stub implements ListModelAvailabilityCandidates, now used by the database fallback loader.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景说明
本 PR 基于 #8661(
feat(gemini): add Gemini 4 Carbon support,保留原提交记录)构建(计费部分与 #8746 存在交集),在此基础上新增了对gemini-4-hydrogen的完整支持,并统一优化了 Antigravity 渠道下的effort动态变体路由、混合分组冷却对齐与计费档位归因。改了什么 & 为什么要这样改
1. 新增
gemini-4-hydrogen全链路支持(含xhigh档位)gemini/geminicli默认目录与前端gemini白名单中新增gemini-4-hydrogen;在 Antigravity 目录、默认映射与前端预设中新增gemini-4-hydrogen-{low,medium,high,xhigh}及动态自映射gemini-4-hydrogen -> gemini-4-hydrogen。request_transformer.go、gemini_compat_thinking.go、antigravity_gemini_thinking_variant.go与gemini_reasoning_effort.go中为gemini-4-hydrogen支持low/medium/high/xhigh四个thinkingLevel(max映射为xhigh;其余不支持xhigh的模型自动钳制/降级为high),禁用thinkingBudget。BillingService兜底计费及PricingService档位别名归一中新增gemini-4-hydrogen定价(标准$1.50 / $7.50 / $0.075每百万 token,Priority 1.8x,1M 输入上下文 / 64K 同步输出,仅隐式缓存无存储费)。gemini-4-hydrogen与 Carbon 同样只接受thinkingLevel(传thinkingBudget或minimal会触发上游 HTTP 400),但额外开放了xhigh深度思考档位,且在 Antigravity 上游目录中拆分为四个带档位后缀的模型 ID;若沿用旧预算路径或缺少-xhigh变体映射会导致请求 400、xhigh档位丢失或上游 404。2. 修复并统一 Antigravity 前置变体选择与兼容层的
effort解析ResolveClaudeThinkingLevel(优先级:thinking.type == "disabled">output_config.effort>thinking.budget_tokens),接入AntigravityGatewayService.Forward与prepareAntigravityCompatCall。buildAntigravityCompatGeminiBody中补齐applyGeminiCompatThinkingConfig,并统一/v1/chat/completions对嵌套reasoning.effort与平铺reasoning_effort的解析与请求转换。ClaudeRequest引入了OutputConfig,但网关前置的变体挑选函数此前仅读取thinking.budget_tokens(未传thinking时恒回退high),而下游转换器见到已带档位后缀的模型又会跳过effort写入;同时 Antigravity 的 OpenAI 兼容层对裸模型(如gemini-4-carbon)遗漏了thinkingConfig注入,会导致客户端传入的output_config.effort/reasoning_effort被静默忽略或覆盖为high。3. 支持 Antigravity 下 Claude 5.5(
claude-opus-5-5/claude-sonnet-5-5)随effort动态映射变体DefaultAntigravityModelMapping中的claude-opus-5-5与claude-sonnet-5-5由固定-high调整为动态自映射,纳入isAntigravityThinkingVariantFamily按请求effort自动路由至-low/-medium/-high(缺省仍落到-high;若管理员显式配置base -> *-high则仍优先尊重固定映射;单独添加base -> base预设时自动回退默认分档目录避免发裸名 404)。useModelWhitelist.ts同步补齐Opus 5.5/Sonnet 5.5动态预设与-low预设;后端configuredUpstreamModelsForCapabilitySync与GetUpstreamModelMetadata支持动态分档裸键的能力同步与多档位元数据聚合。-low/-medium/-high三个独立模型,此前默认写死-high会使 Claude Code / OpenCode 等客户端调节effort时无法切到对应档位。该分档逻辑严格限制在PlatformAntigravity内,原生PlatformAnthropic(OAuth / SetupToken / APIKey / Bedrock)保持裸模型 ID 与既有行为完全不变。4. 调度准入、模型级冷却归属与实际生效计费档位对齐
gateway_scheduling.go、gemini_messages_compat_service.go)支持仅同步了后缀变体(含单-xhigh目录)的 Antigravity 账号接纳裸模型请求。WithAntigravityThinkingLevelFromClaudeBody(读取分组策略改写后的最终请求体)、WithAntigravityThinkingLevelFromGeminiBody,配合resolveFinalAntigravityModelKey与antigravityRateLimitModelKey(含TestConnection)使调度预检与转发限流统一按实际目标变体读写冷却状态。effectiveAntigravityGeminiReasoningEffort,区分入站请求的RequestedReasoningEffort与上游实际生效的ReasoningEffort(覆盖档位钳制、账号缺档降级、签名/预算整流重试及web_search降级至gemini-2.5-flash等场景)。-low限流误冷却默认-high或在混合分组(Antigravity + Anthropic 订阅)中因调度与转发档位不一致白白消耗故障切换次数”、以及“上游实际档位发生钳制/降级时仍按未生效高档倍率计费”等边界问题。本地验证
go test -tags=unit ./internal/domain ./internal/pkg/antigravity/... ./internal/pkg/gemini/... ./internal/pkg/geminicli/... ./internal/service ./internal/handler/...go vet -tags=unit ./internal/domain ./internal/pkg/antigravity/... ./internal/pkg/gemini/... ./internal/pkg/geminicli/... ./internal/service ./internal/handler/...golangci-lint run ./internal/domain ./internal/pkg/antigravity ./internal/pkg/gemini ./internal/pkg/geminicli ./internal/service ./internal/handlervitest run src/composables/__tests__/useModelWhitelist.spec.tsvue-tsc --noEmit&eslint src/composables/useModelWhitelist.ts src/composables/__tests__/useModelWhitelist.spec.ts