Skip to content

feat(relay): add OpenAI gpt-4.1 o3 o4 gpt-image-1 models - #1597

Merged
Calcium-Ion merged 2 commits into
QuantumNous:alphafrom
wzxjohn:feature/add_openai_models
Aug 16, 2025
Merged

feat(relay): add OpenAI gpt-4.1 o3 o4 gpt-image-1 models#1597
Calcium-Ion merged 2 commits into
QuantumNous:alphafrom
wzxjohn:feature/add_openai_models

Conversation

@wzxjohn

@wzxjohn wzxjohn commented Aug 15, 2025

Copy link
Copy Markdown
Contributor

Add gpt-4.1 o3 o4-mini gpt-image-1 models and ratios.

Summary by CodeRabbit

  • New Features

    • Added support for latest models: GPT-4.1 (standard/mini/nano), O1/O1 Pro, O3 (standard/pro/deep research), and O4 Mini (including deep research), with dated variants.
    • Enabled the gpt-image-1 image generation model alongside DALL·E 3.
    • Introduced per-model pricing/ratio defaults for new models to reflect their capabilities.
  • Chores

    • Reordered the model list and removed duplicates for consistency.

@coderabbitai

coderabbitai Bot commented Aug 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Updates 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

Cohort / File(s) Summary
OpenAI Model Registry
relay/channel/openai/constant.go
Expanded ModelList with gpt-4.1 family, o1 (incl. dated/pro variants), o3 (incl. pro, deep-research, dated), and o4-mini (incl. deep-research, dated); added gpt-image-1; minor reordering and duplicate cleanup.
Model Ratios and Pricing
setting/ratio_setting/model_ratio.go
Extended defaultModelRatio with ratios for gpt-4.1 (base/mini/nano + dated), gpt-image-1, o1/o1-pro (+ dated), o3/o3-pro/o3-deep-research (+ dated), and o4-mini/o4-mini-deep-research (+ dated). Fallback ratio behavior unchanged.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

A rabbit taps its models list—click, click, hooray!
Ratios lined like carrots, neatly on display.
gpt-4.1 hops in, o3 joins the run,
o1 and o4-mini bask in pricing sun.
With ears up high, I ship—job done! 🥕✨

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-3

You 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 1

GetHardcodedCompletionModelRatio 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 price

Would 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.

📥 Commits

Reviewing files that changed from the base of the PR and between b57e97d and 0edc707.

📒 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 good

The 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 — OK

Adding "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 complete

The 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 assumptions

Ratios 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 path

defaultModelRatio 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 premium

The entries for o1/o1-mini/o1-preview and the new o1-pro variants look internally consistent with comments. Nothing blocking here.

Comment on lines +55 to +61
"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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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"
fi

Length 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.

@Calcium-Ion
Calcium-Ion merged commit 5829bc6 into QuantumNous:alpha Aug 16, 2025
3 checks passed
@wzxjohn
wzxjohn deleted the feature/add_openai_models branch August 27, 2025 01:58
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…odels

feat(relay): add OpenAI gpt-4.1 o3 o4 gpt-image-1 models
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