feat(relay): add OpenAI gpt-4.1 o3 o4 gpt-image-1 models - #1597
Conversation
WalkthroughUpdates add new OpenAI model identifiers to the exported model list and extend default per-model ratios for pricing/routing, including the gpt-4.1, o1, o3, and o4-mini families with dated variants. No function signatures or control flow changed; modifications are data-only. Changes
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
relay/channel/openai/constant.go (1)
42-42: gpt-image-1 introduced — add a defaultModelPrice entry for parity with dall-e-3You added "gpt-image-1" to the OpenAI model list (Line 42), and model_ratio.go includes both defaultModelRatio and defaultImageRatio entries for it. However, defaultModelPrice currently includes dall-e-3 but not gpt-image-1. If any path calls GetModelPrice("gpt-image-1", ...), it will return (-1, false).
Recommend adding a defaultModelPrice for "gpt-image-1" (matching dall-e-3’s presence), or confirm that your pricing logic never queries ModelPrice for image models and relies solely on ImageRatio.
I can add the price entry for you. Do you want me to open a follow-up PR for that?
setting/ratio_setting/model_ratio.go (2)
78-87: o3 and o4-mini families — add completion ratio hint for o4 to avoid defaulting to 1GetHardcodedCompletionModelRatio currently assigns a completion ratio for o1 and o3 (Line 492–Line 494) but not for o4. That means o4-mini (and its deep-research variant) will fall back to 1, which is probably not what you intend given other comparable models.
Suggestion: extend the hardcoded check to include o4 so completion tokens are scaled consistently.
Here’s a minimal change to consider (outside the changed range):
// getHardcodedCompletionModelRatio: extend o-family completion ratios if strings.HasPrefix(name, "o1") || strings.HasPrefix(name, "o3") || strings.HasPrefix(name, "o4") { return 4, true }If you want different ratios for o4-mini vs o4 (future non-mini), we can refine this with more granular checks.
255-279: Add price entry for gpt-image-1 to match dall-e-3 (if ModelPrice is used for images)defaultModelPrice declares "dall-e-3" but not "gpt-image-1". If any code path uses price-based billing for gpt-image-1, this will be missing. If price is not used for images (and only ImageRatio applies), this is optional.
Proposed addition (outside changed range; adjust value per your pricing policy):
// In defaultModelPrice: "gpt-image-1": 0.04, // keep parity with dall-e-3 unless you have a distinct priceWould you like me to submit this tweak?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
relay/channel/openai/constant.go(2 hunks)setting/ratio_setting/model_ratio.go(2 hunks)
🔇 Additional comments (7)
relay/channel/openai/constant.go (4)
15-17: gpt-4.1 family added — alignment with ratios looks goodThe new identifiers for gpt-4.1/gpt-4.1-mini/gpt-4.1-nano (Line 15–Line 17) are consistent with entries added in setting/ratio_setting/model_ratio.go (Line 55–Line 61). No functional risks seen here.
18-18: o1 moved earlier + dated variant — OKAdding "o1" and "o1-2024-12-17" here resolves the prior duplication mentioned in the PR summary. No runtime impact; just data reordering.
21-21: o1-pro entries added — confirm downstream support in routing"o1-pro" and "o1-pro-2025-03-19" are now listed. Ensure the downstream OpenAI relay path recognizes and correctly routes these model IDs (some o1/o3/o4 families use Responses API semantics and/or special tool capability gates).
Would you like a quick repo scan to list all places that gate or special-case "o1-pro" models?
26-30: o3/o3-pro/o3-deep-research and o4-mini variants added — model catalog is completeThe additions for "o3", "o3-pro", "o3-deep-research" with their dated variants and "o4-mini"/"o4-mini-deep-research" align with the new ratios in model_ratio.go (Line 78–Line 87). Good coverage and naming consistency.
setting/ratio_setting/model_ratio.go (3)
55-61: gpt-4.1 family ratios — verify pricing assumptionsRatios for gpt-4.1/mini/nano map to comments implying $2/$0.4/$0.1 per 1M tokens. That’s a large shift from historical 4.x pricing. If this is intentional (and based on updated OpenAI pricing), great. If not, this could meaningfully undercharge.
Would you like me to run a quick web check for the latest OpenAI published prices and confirm these multipliers?
61-61: gpt-image-1 ratio present — ensure consistent billing pathdefaultModelRatio has "gpt-image-1": 2.5 and defaultImageRatio also has "gpt-image-1": 2. Confirm which path is used at runtime for image requests to avoid inconsistent or double application (ModelRatio vs ImageRatio).
If the image pipeline occasionally flows through token-based billing, consider documenting precedence between ModelRatio and ImageRatio for image endpoints.
62-69: o1 family ratios extended — o1-pro looks intentionally premiumThe entries for o1/o1-mini/o1-preview and the new o1-pro variants look internally consistent with comments. Nothing blocking here.
| "gpt-4.1": 1.0, // $2 / 1M tokens | ||
| "gpt-4.1-2025-04-14": 1.0, // $2 / 1M tokens | ||
| "gpt-4.1-mini": 0.2, // $0.4 / 1M tokens | ||
| "gpt-4.1-mini-2025-04-14": 0.2, // $0.4 / 1M tokens | ||
| "gpt-4.1-nano": 0.05, // $0.1 / 1M tokens | ||
| "gpt-4.1-nano-2025-04-14": 0.05, // $0.1 / 1M tokens | ||
| "gpt-image-1": 2.5, // $5 / 1M tokens |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Sanity check: ensure every new OpenAI model has a default ratio and reasonable completion ratio
All new models have defaultModelRatio entries, but completion ratio coverage for o4 is likely missing as noted. To be safe, run this repo-local check to confirm coverage and catch any misses between ModelList and defaultModelRatio.
Also applies to: 62-69, 78-87
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Pull all OpenAI models from the list
const_file="relay/channel/openai/constant.go"
ratio_file="setting/ratio_setting/model_ratio.go"
# Extract all model names from ModelList
models=$(sed -n '/var ModelList = \[]string{/,/}/p' "$const_file" | \
rg -o '"[^"]+"' | tr -d '"')
# Filter to newly introduced families for this PR
new_patterns='^(gpt-4\.1|o3|o4-mini|gpt-image-1|o1-pro)'
new_models=$(printf "%s\n" "$models" | rg -nP "$new_patterns" | cut -d: -f2-)
# Extract keys from defaultModelRatio map
ratio_keys=$(sed -n '/var defaultModelRatio = map\[string\]float64{/,/}/p' "$ratio_file" | \
rg -o '"[^"]+"' | tr -d '"')
echo "Checking new models have defaultModelRatio entries..."
missing=""
while IFS= read -r m; do
if ! printf "%s\n" "$ratio_keys" | rg -qx "$m" >/dev/null; then
missing+="$m"$'\n'
fi
done <<< "$new_models"
if [ -n "$missing" ]; then
echo "Missing ratios for:"
printf "%s" "$missing"
exit 1
else
echo "OK: All new models found in defaultModelRatio."
fi
echo
echo "Checking defaultModelPrice has gpt-image-1 (optional, only if price used for images)..."
price_keys=$(sed -n '/var defaultModelPrice = map\[string\]float64{/,/}/p' "$ratio_file" | \
rg -o '"[^"]+"' | tr -d '"')
if printf "%s\n" "$price_keys" | rg -qx "gpt-image-1" >/dev/null; then
echo "OK: gpt-image-1 present in defaultModelPrice"
else
echo "Note: gpt-image-1 not present in defaultModelPrice"
fi
echo
echo "Checking whether hardcoded completion ratios cover o4..."
if rg -n 'HasPrefix\(name,\s*"o4"\)' "$ratio_file" >/dev/null; then
echo "OK: o4 present in getHardcodedCompletionModelRatio"
else
echo "Note: o4 not covered in getHardcodedCompletionModelRatio; will default to 1"
fiLength of output: 116360
Sanity check results — defaultModelRatio OK; defaultModelPrice missing gpt-image-1; o4 completion ratio not covered (fix required)
Ran the repo-local check you included. Findings:
- OK: All new models from relay/channel/openai/constant.go (gpt-4.1*, o3*, o4-mini*, o1-pro, gpt-image-1) are present in var defaultModelRatio (setting/ratio_setting/model_ratio.go).
- Action required: var defaultModelPrice in setting/ratio_setting/model_ratio.go does NOT include "gpt-image-1" — add a price entry if image pricing is used.
- Action required: getHardcodedCompletionModelRatio in setting/ratio_setting/model_ratio.go has no HasPrefix(name, "o4") branch — add coverage for the o4 family (otherwise completion ratio will default to 1).
Files to update:
- setting/ratio_setting/model_ratio.go (defaultModelPrice, getHardcodedCompletionModelRatio)
- (reference) relay/channel/openai/constant.go (ModelList)
Please add the missing price entry and an o4 case (with an appropriate completion ratio) and re-run the check.
…odels feat(relay): add OpenAI gpt-4.1 o3 o4 gpt-image-1 models
Add gpt-4.1 o3 o4-mini gpt-image-1 models and ratios.
Summary by CodeRabbit
New Features
Chores