Skip to content

feat(pricing): add price field to pricing API response - #2816

Closed
zhaolion wants to merge 40 commits into
QuantumNous:mainfrom
CherryInternal:feat/pricing
Closed

feat(pricing): add price field to pricing API response#2816
zhaolion wants to merge 40 commits into
QuantumNous:mainfrom
CherryInternal:feat/pricing

Conversation

@zhaolion

@zhaolion zhaolion commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add price field from operation_setting.Price to the GetPricing endpoint response
  • Exposes pricing configuration to API clients

Test plan

  • Verify /api/pricing endpoint returns the new price field
  • Confirm existing fields remain unchanged
  • Test with different price configurations

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added OAuth authentication system with login and consent flows via Hydra integration.
    • Added OAuth API endpoints for user account management, token operations, and usage data retrieval.
    • Added OAuth client management interface in admin console.
    • Added Streamlake channel support.
    • Added Stripe managed payments configuration option.
    • Added Pyroscope profiling support.
  • Infrastructure

    • Streamlined Docker deployment with integrated Hydra support.
    • Transitioned CI/CD to Docker-centric workflow.
  • Dependencies

    • Upgraded Stripe SDK from v81 to v83.

zhaolion and others added 30 commits January 4, 2026 16:42
Add new channel type (57) for StreamLake integration with URL path
handling that trims the /v1 prefix from request URLs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add a new docker job to build and push images to ghcr.io/zhaolion/newapi:{tag}
when tags are pushed, running in parallel with existing release jobs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove deprecated workflow files that are no longer needed:
- docker-image-alpha.yml (alpha Docker builds)
- docker-image-arm64.yml (multi-arch Docker builds, now handled by release workflow)
- electron-build.yml (Electron app builds)
- sync-to-gitee.yml (Gitee release sync)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add repository name normalization to lowercase for GHCR compatibility
- Replace hardcoded image path with dynamic $GITHUB_REPOSITORY
- Add metadata extraction for proper image labels
- Add latest tag alongside version tag

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove macOS and Windows build jobs to simplify the release workflow,
keeping only Linux binary builds and Docker image publishing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
… image handling

# Conflicts:
#	go.mod
#	go.sum
#	relay/channel/ali/dto.go
#	relay/channel/ali/image_wan.go
- Update Stripe-Version header to 2025-03-31.basil
- Reorder managed_payments parameter after headers setup
- Remove StripeAutoTaxEnabled feature and related code
- Change STRIPE_MANAGED_PAYMENTS_ENABLED default to false

Co-Authored-By: Claude <noreply@anthropic.com>
fix: update Stripe managed payments configuration and disable auto-tax
Add a dedicated test endpoint mapping that includes rerank endpoint
for channel testing purposes, separate from the main endpoint defaults.

Co-Authored-By: Claude <noreply@anthropic.com>
feat: add separate test endpoint defaults for channel testing
…payments by default

- Add /v1/rerank endpoint detection for rerank models in channel testing
- Change STRIPE_MANAGED_PAYMENTS_ENABLED default from true to false

Co-Authored-By: Claude <noreply@anthropic.com>
feat: add rerank model endpoint detection and disable Stripe managed payments by default
feat: enhance channel testing with extended model type detection
* feat: enhance channel testing with extended model type detection

- Exclude image edit models from testing (not supported)
- Add endpoint type tracking for embeddings and rerank models
- Add image generation detection for qwen and gpt image models
- Add response endpoint detection for gpt-5.2 models

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: add kwai-kolors image generation model detection

Add endpoint detection for kwai-kolors image generation models
to use /v1/images/generations endpoint during channel testing.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: exclude rerank models from embedding detection in channel test

Rerank models like BAAI/bge-reranker-v2-m3 contain "bge-" in their name
and were incorrectly matched as embedding models. This fix ensures
rerank models are properly routed to the /v1/rerank endpoint.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
* feat: implement oauth

* chore: modify image

* fix:  make error message consistent add avoid magic number

* chore: clean unused env

* chore: clean again

* feat(oauth): oauth client

* feat(ui): oauth test

* feat(oauth): implement oauth clients

* fix: clean local yaml
DeJeune and others added 10 commits January 29, 2026 14:43
feat: integrate Pyroscope for performance monitoring (#9)
- Add registration link on OAuth login page with login_challenge param
- Handle login_challenge in RegisterForm to redirect back to OAuth flow
- Auto-create default token on consent when tokens:write scope granted

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Ensure tokens:write is both requested by client AND granted by user
before auto-creating default token, preventing scope escalation attacks.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change Hydra proxy to redirect /oauth/login to /register
- Make AuthRedirect OAuth-aware to not redirect when login_challenge present
- Add OAuth session check in RegisterForm to auto-continue for logged-in users

This improves the OAuth UX by showing registration first for new users,
while existing users can click to login or are auto-redirected if already
logged in.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
feat(oauth): redirect to register page first in OAuth flow
- Add comprehensive request context (method, path, query, client IP, request ID)
- Include request body with truncation for large payloads
- Add full stack trace for debugging
- Use common.GetRequestBody() helper for consistent body retrieval
Include operation_setting.Price in the GetPricing endpoint response
to expose pricing configuration to clients.
Copilot AI review requested due to automatic review settings February 3, 2026 06:25
@zhaolion zhaolion closed this Feb 3, 2026
@coderabbitai

coderabbitai Bot commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces comprehensive OAuth/Hydra integration for third-party application authorization, adds Pyroscope profiling support, modernizes Docker-based release workflows, integrates Ali-Qwen image generation endpoints, and updates dependencies including Stripe v83. Frontend gains OAuth login/consent flows and OAuth client management interface.

Changes

Cohort / File(s) Summary
OAuth/Hydra Core Configuration
.env.example, common/constants.go, common/init.go, model/option.go
Added Hydra OAuth provider configuration with flags, URLs, trusted clients, and session remember durations. Integrated configuration initialization and runtime option updates.
Hydra Service Layer
service/hydra/interface.go, service/hydra/service.go, service/hydra/mock.go, service/hydra/mock_test.go, service/hydra/introspect_test.go
Implemented complete Hydra service abstraction with login/consent/logout flows, token introspection, OAuth2 client management, and comprehensive mock provider for testing.
OAuth API Controllers
controller/oauth_api.go, controller/oauth_api_test.go
Added REST API endpoints for OAuth clients to retrieve user info, balance, usage, and manage tokens. Includes authorization checks and scope enforcement.
OAuth Provider Controllers & Routes
controller/oauth_provider.go, controller/oauth_provider_test.go, router/oauth-provider.go, router/oauth-api.go
Implemented full OAuth provider flow handling (login, consent, logout, 2FA) with admin endpoints for OAuth client management. Wired routes with appropriate rate limiting and authentication.
OAuth Middleware & Auth
middleware/oauth.go, middleware/oauth_test.go
Added OAuth token authentication middleware with Bearer token extraction, Hydra introspection, and scope-based authorization enforcement.
Docker Infrastructure
.github/workflows/docker-image-alpha.yml, .github/workflows/docker-image-arm64.yml, .github/workflows/electron-build.yml, .github/workflows/sync-to-gitee.yml, .github/workflows/release.yml, Dockerfile, docker-compose.yml, docker/entrypoint.sh
Removed legacy multi-arch Docker build workflows; consolidated release to Docker-only approach via Buildx. Introduced Hydra sidecar in docker-compose. Updated Dockerfile to include Hydra binary and conditional startup via entrypoint script.
Hydra Proxy & Router
router/hydra-proxy.go, router/main.go
Added reverse proxy for Hydra public endpoints with redirect rewriting, path mapping, and scheme/host normalization. Integrated proxy and OAuth routes into main router.
OAuth Data Models
model/oauth_client.go, model/main.go
Introduced OAuthClient model with CRUD operations, supporting both public and confidential client types. Integrated migrations into database initialization.
OAuth Frontend Pages & Components
web/src/pages/OAuth/OAuthLogin.jsx, web/src/pages/OAuth/OAuthConsent.jsx, web/src/pages/OAuth/index.jsx, web/src/pages/OAuthClients/index.jsx
Added complete OAuth UI flows: login page with 2FA support, consent page with scope approval, and OAuth client management dashboard.
OAuth Frontend Table Components
web/src/components/table/oauth-clients/OAuthClientsTable.jsx, web/src/components/table/oauth-clients/OAuthClientsActions.jsx, web/src/components/table/oauth-clients/OAuthClientsColumnDefs.jsx, web/src/components/table/oauth-clients/OAuthClientsFilters.jsx, web/src/components/table/oauth-clients/modals/EditOAuthClientModal.jsx
Implemented full CRUD UI for OAuth clients with table, actions, filters, and edit modal. Includes scope/URI rendering, client type indicators, and copy-to-clipboard support.
OAuth Frontend Hooks & Utilities
web/src/hooks/oauth-clients/useOAuthClientsData.jsx
Created comprehensive React hook for OAuth client state management, API integration, pagination, search, and batch operations.
OAuth Frontend Integration
web/src/App.jsx, web/src/components/auth/RegisterForm.jsx, web/src/components/layout/SiderBar.jsx, web/src/helpers/auth.jsx, web/src/helpers/render.jsx, web/src/hooks/common/useSidebar.js
Integrated OAuth routes, added OAuth client admin section to sidebar, preserved login_challenge through registration flow, updated icon handling for OAuth clients.
Internationalization
web/src/i18n/locales/en.json, web/src/i18n/locales/zh.json
Added comprehensive translation keys for OAuth authorization flows, consent prompts, error messages, and client management UI.
Profiling Integration
common/pyro.go, main.go
Introduced Pyroscope profiling initialization with configurable endpoints, app names, and profiling rates. Integrated into main with error handling and enhanced panic recovery.
Ali Channel Qwen Image Support
relay/channel/ali/dto.go, relay/channel/ali/image.go, relay/channel/ali/image_wan.go, relay/channel/ali/adaptor.go
Added Qwen image generation request/response handling with multimodal-generation endpoint support. Includes model detection and appropriate handler routing.
Channel & Relay Refinements
constant/channel.go, relay/channel/claude/adaptor.go, relay/channel/claude/relay-claude.go, relay/common/relay_utils.go, controller/channel-test.go
Added ChannelTypeStreamlake constant, enhanced Claude error handling with nil checks, added Streamlake URL handling, extended test channel routing with endpoint-aware model detection.
Additional Controller Updates
controller/user.go, controller/pricing.go, controller/task.go, controller/topup_stripe.go, middleware/distributor.go
Added Hydra logout support in user controller, exposed price field in pricing, fixed error formatting in task controller, upgraded Stripe to v83 with managed payments support, fixed Midjourney error handling.
Configuration & Dependencies
.go-version, .golangci.yml, mise.toml, go.mod, common/endpoint_defaults.go, model/twofa.go, setting/payment_stripe.go
Added Go 1.25.1 version file, GolangCI-Lint configuration, Mise tooling config. Updated dependencies (Pyroscope, Hydra, Stripe). Added test endpoint defaults and backup code wrapper. Added StripeManagedPaymentsEnabled flag.

Sequence Diagram(s)

sequenceDiagram
    participant User as User Agent
    participant App as New-API Frontend
    participant API as New-API Backend
    participant Hydra as Hydra Server
    participant DB as Database

    User->>App: Click "Authorize" on 3rd-party app
    App->>Hydra: Redirect to /oauth/login?login_challenge=X
    Hydra->>User: Display login form
    User->>Hydra: Submit username/password
    Hydra->>API: POST /api/oauth/login<br/>(with login_challenge)
    API->>DB: Validate credentials
    DB-->>API: User ID
    API->>Hydra: AcceptLogin(challenge, userID)
    Hydra-->>API: Redirect to consent
    API-->>User: Redirect to /oauth/consent
    User->>App: Shown consent page with scopes
    User->>App: Click "Approve"
    App->>API: POST /api/oauth/consent<br/>(with challenge & scopes)
    API->>Hydra: AcceptConsent(challenge, scopes)
    Hydra-->>API: Redirect to 3rd-party app
    API-->>User: Redirect to callback URL<br/>with authorization code
    User->>Hydra: Exchange code for token
    Hydra->>DB: Validate code
    DB-->>Hydra: Authorization valid
    Hydra-->>User: Return access_token
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

oauth, hydra-integration, docker-refactor, feature, backend, frontend, infrastructure

Suggested reviewers

  • Calcium-Ion

Poem

🐰 Hops through OAuth's woodland deep,
Hydra guards the secrets we keep,
Consent flows dance, tokens align,
Frontend and backend in harmony shine,
Docker wrapped tight, profiles take flight! 🚀

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

@zhaolion
zhaolion deleted the feat/pricing branch February 3, 2026 06:26
@zhaolion
zhaolion restored the feat/pricing branch February 3, 2026 06:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot reviewed 72 out of 73 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread controller/pricing.go
"usable_group": usableGroup,
"supported_endpoint": model.GetSupportedEndpointMap(),
"auto_groups": service.GetUserAutoGroup(group),
"price": operation_setting.Price,

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

This is the only change that matches the PR title and description. All other changes in this PR implement a complete OAuth 2.0 provider system which is not mentioned in the PR description. This represents a massive scope creep and should either be:

  1. Split into separate PRs (recommended)
  2. The PR title and description should be completely rewritten to accurately reflect the OAuth implementation

The current PR description is misleading and makes code review extremely difficult.

Copilot uses AI. Check for mistakes.
Comment thread main.go
HttpOnly: true,
Secure: false,
SameSite: http.SameSiteStrictMode,
SameSite: http.SameSiteLaxMode, // Lax allows OAuth redirect flows while preventing CSRF

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

This change modifies the SameSite cookie policy from Strict to Lax. While the comment explains this is for OAuth redirect flows, this is a security-relevant change that should be explicitly documented in the PR description and carefully reviewed. SameSite=Lax allows cookies to be sent in top-level navigation from external sites, which enables OAuth flows but also slightly weakens CSRF protection.

Copilot uses AI. Check for mistakes.
Comment thread router/hydra-proxy.go
Comment on lines +19 to +23
"/oauth2/fallbacks/login": "/register",
"/oauth2/fallbacks/consent": "/oauth/consent",
"/oauth2/fallbacks/logout": "/oauth/logout",
// Configured OAuth paths - redirect login to register page
"/oauth/login": "/register",

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

The redirect path mapping shows that /oauth/login redirects to /register instead of /oauth/login. This means all OAuth login attempts will be redirected to the registration page. This appears to be intentional based on the comment "redirect login to register page", but this is unusual OAuth behavior and may confuse users who already have accounts. Consider providing a clearer path for existing users to login during OAuth flows.

Copilot uses AI. Check for mistakes.
Comment on lines +2110 to +2111
"已发起跳转,请返回应用完成登录": "已发起跳转,请返回应用完成登录",
"已发起跳转,请返回应用完成登录": "已发起跳转,请返回应用完成登录",

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

The Chinese translation key appears twice at lines 2110 and 2111 with the same value. This is a duplication that should be removed.

Copilot uses AI. Check for mistakes.
Comment thread Dockerfile
COPY --from=builder /build/dist ./web/dist
RUN go build -ldflags "-s -w -X 'github.com/QuantumNous/new-api/common.Version=$(cat VERSION)'" -o new-api

FROM oryd/hydra:v25.4.0 AS hydra

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

The Hydra version in the Dockerfile (v25.4.0) doesn't match the Go dependency version in go.mod (v2.2.1). This version mismatch could cause compatibility issues. Ensure these versions are compatible or update them to match.

Suggested change
FROM oryd/hydra:v25.4.0 AS hydra
FROM oryd/hydra:v2.2.1 AS hydra

Copilot uses AI. Check for mistakes.
Comment thread docker/entrypoint.sh
#!/bin/sh
set -e

if [ "${HYDRA_ENABLED:-true}" = "true" ]; then

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

The entrypoint script has HYDRA_ENABLED defaulting to "true" if the environment variable is not set. This means Hydra will run by default even if users don't intend to use OAuth. Consider defaulting to "false" to avoid unexpected resource consumption and to make this opt-in rather than opt-out.

Copilot uses AI. Check for mistakes.
For commercial licensing, please contact support@quantumnous.com
*/

import React, { useState } from 'react';

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

Unused import useState.

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +47
import {
IconLink,
IconSave,
IconClose,
IconKey,
IconCopy,
} from '@douyinfe/semi-icons';

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

Unused import IconCopy.

Copilot uses AI. Check for mistakes.
const isMobile = useIsMobile();
const formApiRef = useRef(null);
const isEdit = props.editingClient?.client_id !== undefined;
const [newClientSecret, setNewClientSecret] = useState(null);

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

Unused variable newClientSecret.

Copilot uses AI. Check for mistakes.
Comment thread docker/entrypoint.sh
Comment on lines +4 to +6
if [ "${HYDRA_ENABLED:-true}" = "true" ]; then
/usr/bin/hydra migrate sql -e --yes
/usr/bin/hydra serve all --dev &

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

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

This entrypoint starts ORY Hydra using hydra serve all --dev, which runs the OAuth provider in development mode even for this production image, enabling insecure defaults that are explicitly not safe outside local testing. If this container is deployed in a real environment, an attacker who can reach Hydra’s endpoints could abuse those relaxed settings (e.g., permissive redirect/CORS or weaker secret/TLS handling) to register arbitrary OAuth clients or otherwise weaken your authentication flows. Run Hydra with a proper production configuration (without --dev) and gate enabling Hydra behind explicit environment- or deployment-specific settings rather than a default-on flag.

Suggested change
if [ "${HYDRA_ENABLED:-true}" = "true" ]; then
/usr/bin/hydra migrate sql -e --yes
/usr/bin/hydra serve all --dev &
if [ "${HYDRA_ENABLED:-false}" = "true" ]; then
/usr/bin/hydra migrate sql -e --yes
/usr/bin/hydra serve ${HYDRA_SERVE_ARGS:-all} &

Copilot uses AI. Check for mistakes.
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.

3 participants