Skip to content

Charge Grok Imagine images by official per-image tiers - #1089

Open
think-back wants to merge 1 commit into
mainfrom
feat/grok-image-per-image-billing
Open

think-back wants to merge 1 commit into
mainfrom
feat/grok-image-per-image-billing

Conversation

@think-back

Copy link
Copy Markdown
Collaborator

Summary

  • switch Grok Imagine image models to the official per-image pricing contract
  • apply request-level resolution/quality multipliers for Imagine 2.0 and Imagine Pro/Quality
  • keep unknown or auto options on the lowest official tier as a safe fallback

Official tiers

  • grok-imagine-image: $0.02/image for 1K and 2K
  • grok-imagine-image-2.0: $0.04 (1K low), $0.06 (2K low / 1K medium), $0.08 (2K medium)
  • grok-imagine-image-pro / grok-imagine-image-quality: $0.05 (1K), $0.07 (2K)

Verification

  • go test ./dto -count=1
  • go test ./pkg/billingexpr -count=1
  • go test ./relay/helper -count=1 (one existing timing-sensitive stream scanner test was flaky in this run; no code path from this change is involved)

Align Grok Imagine billing with xAI per-image pricing and keep higher resolution and quality tiers request-aware.\n\nConstraint: xAI bills generated images per image, with resolution and quality tiers for Imagine 2.0 and Pro.\nRejected: Token multipliers for Grok image generation | They do not match the upstream billing contract.\nConfidence: high\nScope-risk: narrow\nDirective: Keep model_price at each model's lowest official tier; derive only documented request tiers.\nTested: go test ./dto ./relay/helper ./pkg/billingexpr -count=1\nNot-tested: Live Flatkey settings update pending authenticated admin session.
@KingCesc

KingCesc commented Sep 3, 2026

Copy link
Copy Markdown

🤖 OpenCodeReview · 评审 commit ffbed2cb · 共 1 条

dto/openai_image.go

  • L216-223: [阻塞] grok-imagine-image-2.0 只配置了 low/medium 两档,但这里在 quality 为空或 auto 时会先回退到 modelPrices["default"]。由于该模型并没有 default 档位,qualityPrices 会是 nil,随后取价失败直接返回 1,而上游又会把图片质量设为 auto,这会导致 2.0 请求按错误倍率计费,产生明显的账单偏差。建议为该模型显式提供默认档位(按最低官方 tier)或在缺省质量时特殊映射到 low
if quality == "" || quality == "auto" {
		if model == "grok-imagine-image-2.0" {
			quality = "low"
		} else {
			quality = "default"
		}
	}
	qualityPrices, ok := modelPrices[quality]
	if !ok {
		qualityPrices = modelPrices["default"]
	}
	if qualityPrices == nil {
		return 1
	}
	price, ok := qualityPrices[size]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants