Skip to content

feat(providers): add openai-discount provider - #2471

Closed
steebchen wants to merge 1 commit into
mainfrom
openai-discount-provider
Closed

steebchen wants to merge 1 commit into
mainfrom
openai-discount-provider

Conversation

@steebchen

@steebchen steebchen commented May 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds a new openai-discount provider that behaves exactly like upstream OpenAI for all request/response handling, mirroring the existing anthropic-discount pattern, with two differences:

  • Base URL + API key come from environment variables (LLM_OPENAI_DISCOUNT_BASE_URL / LLM_OPENAI_DISCOUNT_API_KEY), following the same stealth pattern as anthropic-discount / glacier / quartz.
  • Pricing carries a 10% discount relative to the upstream prices.

What changed

  • packages/models: new openai-discount provider definition (env-based apiKey + baseUrl); the existing gpt-5.5 model gains an openai-discount provider mapping with discount: "0.1" and supportsResponsesApi: true.
  • packages/actions: endpoint resolution reads LLM_OPENAI_DISCOUNT_BASE_URL and appends /v1/responses (or /v1/chat/completions); the request-body transform (Responses + chat completions paths) treats openai-discount identically to openai. The responses-API capability lookup now keys on the actual provider instead of a hardcoded "openai".
  • apps/gateway: OpenAI-specific branches (Responses-API streaming/non-streaming transforms, tool-call extraction, usage extraction, web-search counting) now also match openai-discount.
  • .env.example: documents the two new env vars.

Token, header (Bearer), and response parsing flow through the existing generic / OpenAI-default machinery, so no further plumbing was needed.

Testing

  • pnpm format ✅
  • pnpm build ✅
  • pnpm test:unit ✅ (1696 passed)

End-to-end verification against the real discounted endpoint is pending — the proxy will be configured separately.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added support for a new OpenAI-compatible provider with discount pricing.
    • Added gpt-5.5 model availability for the new discount provider.
    • Configured environment variables for the new provider's API key and endpoint configuration.

Adds an `openai-discount` provider mirroring the `anthropic-discount`
pattern: base URL + API key come from env vars
(LLM_OPENAI_DISCOUNT_BASE_URL / LLM_OPENAI_DISCOUNT_API_KEY), pricing
carries a 10% discount, and request/response handling is identical to
upstream OpenAI (Responses API included).

Exposes GPT-5.5 via `openai-discount/gpt-5.5` (kie.ai external id
`gpt-5-5`, https://docs.kie.ai/market/chat/gpt-5-5).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 31, 2026 19:16
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR adds a new openai-discount provider as an OpenAI-compatible endpoint. The changes declare the provider in the model registry, configure required environment variables, add gpt-5.5 model support, and wire the provider through all chat/streaming request and response transformation pipelines to behave identically to the standard openai provider.

Changes

OpenAI Discount Provider Integration

Layer / File(s) Summary
Provider definition and environment configuration
packages/models/src/providers.ts, .env.example
openai-discount provider is declared with environment variables LLM_OPENAI_DISCOUNT_API_KEY and LLM_OPENAI_DISCOUNT_BASE_URL, priority 1.5, and streaming/cancellation enabled.
Model pricing and capability configuration for openai-discount
packages/models/src/models/openai.ts
gpt-5.5 model gains an openai-discount provider entry with 0.1 discount factor, matching input/output pricing and feature support (web search, reasoning, JSON schema).
Endpoint and base URL resolution
packages/actions/src/get-provider-endpoint.ts
Base-URL loader retrieves openai-discount config from environment; endpoint selector routes openai-discount alongside openai for Responses API and image generation paths.
Request body preparation and parameter handling
packages/actions/src/prepare-request-body.ts
openai-discount is added to reasoning-effort native handlers, image generation support, main provider switch, and prompt-cache parameter logic (both Responses API and Chat Completions paths).
Response transformation and streaming format conversion
apps/gateway/src/chat/tools/transform-response-to-openai.ts, apps/gateway/src/chat/tools/transform-streaming-to-openai.ts, apps/gateway/src/chat/tools/extract-tool-calls.ts
Response and streaming transforms route openai-discount through OpenAI-compatible handling; tool-call extraction uses same logic as openai.
Streaming token tracking and web-search counting
apps/gateway/src/chat/chat.ts
Streaming SSE processing extracts transformedData.usage tokens and counts response.web_search_call.completed events for openai-discount.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • theopenco/llmgateway#2076: Introduced the initial gpt-5.5 model providers that this PR extends with the openai-discount provider entry.
  • theopenco/llmgateway#2051: Extended OpenAI-compatible provider routing in chat transformation files (transform-streaming-to-openai.ts, get-provider-endpoint.ts) in a similar pattern to this PR.
  • theopenco/llmgateway#2201: Introduced prompt-cache control wiring (prompt_cache_key and prompt_cache_retention) that this PR now extends to openai-discount in prepare-request-body.ts.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(providers): add openai-discount provider' directly and clearly summarizes the main change—adding a new OpenAI-discount provider to the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch openai-discount-provider

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.

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.

Pull request overview

Adds a new openai-discount provider that mirrors the upstream openai request/response handling but resolves its base URL and API key from environment variables (following the existing anthropic-discount stealth pattern).

Changes:

  • New openai-discount provider definition in packages/models with env-driven apiKey/baseUrl, plus an openai-discount mapping (external id gpt-5-5, discount: "0.1", supportsResponsesApi: true) added to the gpt-5.5 model.
  • Endpoint resolution (get-provider-endpoint.ts) reads LLM_OPENAI_DISCOUNT_BASE_URL and now keys the Responses-API capability lookup on the actual provider rather than a hardcoded "openai"; request-body transforms in prepare-request-body.ts treat openai-discount like openai on both Responses-API and chat-completions paths.
  • Gateway-side OpenAI branches (streaming/non-streaming transform-to-openai, tool-call extraction, usage extraction, web-search counting) extended to also match openai-discount; .env.example documents the two new vars.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/models/src/providers.ts Registers openai-discount provider with env-based credentials, priority 1.5, mirroring anthropic-discount.
packages/models/src/models/openai.ts Adds openai-discount provider mapping for gpt-5.5 (external id gpt-5-5, 10% discount, Responses API).
packages/actions/src/get-provider-endpoint.ts Resolves base URL from env for openai-discount and uses provider (not hardcoded "openai") when looking up Responses-API capability.
packages/actions/src/prepare-request-body.ts Treats openai-discount identically to openai for none-effort, image-gen guard, and prompt-cache field handling on both Responses and chat-completions paths.
apps/gateway/src/chat/tools/transform-streaming-to-openai.ts Routes streaming transform for openai-discount through the OpenAI/Azure branch.
apps/gateway/src/chat/tools/transform-response-to-openai.ts Routes non-streaming response transform for openai-discount through the OpenAI branch.
apps/gateway/src/chat/tools/extract-tool-calls.ts Extracts streaming tool-call deltas for openai-discount like openai/azure.
apps/gateway/src/chat/chat.ts Includes openai-discount in Responses-API usage extraction and web_search_call.completed counting.
.env.example Documents LLM_OPENAI_DISCOUNT_BASE_URL / LLM_OPENAI_DISCOUNT_API_KEY.

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

@steebchen steebchen closed this Jun 3, 2026
@steebchen
steebchen deleted the openai-discount-provider branch June 3, 2026 18:03
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