Commit Graph

551 Commits

Author SHA1 Message Date
Luis Pater
92d96e0b72 fix(cliproxy): support base_URL-only config credentials and skip stale auth headers
- Preserve API key entries with empty `api_key` when `base_url` is configured, and extend config dedupe/ID logic to include base URL, proxy, prefix, and headers so identities are stable.
- Update config/auth handling so `auth_kind=apikey` is treated as config API-key auth even without an `api_key` field, enabling base_url-only credential records.
- Ensure Gemini/Codex/XAI request path clears `Authorization`/provider auth headers when token is empty to avoid leaking unrelated auth state.
2026-08-20 15:19:07 +08:00
Luis Pater
9dc51b1f87 feat(cliproxy): add OAuth request-scoped error rules support
- Add `oauth-request-scoped-errors` configuration with normalization, sanitization, and YAML management persistence/hot-reload hooks.
- Route request-scoped error classification to use per-provider rules only for OAuth auth entries.
- Add config diff reporting and management CRUD endpoints for `oauth-request-scoped-errors` (get/put/patch/delete) with input sanitization.

Closes: #5085
2026-08-20 02:55:49 +08:00
sususu
0f69f09a70 fix(logging): exclude HTTP 499 and client cancellations from forced error logs 2026-08-19 18:58:47 +08:00
sususu
aec70dfec4 fix(claude): gate CCH signing by upstream origin and validate fingerprint-profile
Claude Code 2.1.220 through 2.1.234 emit the cch attribution only for
firstParty on api.anthropic.com and for vertex; every other backend sends
the billing header unsigned. CPA had dropped its endpoint check, so an
opted-in API key signed a per-request hash on any gateway and could bust
that gateway's prompt cache.

- Restore the endpoint gate in claudeCCHSigningEnabled: a real Claude OAuth
  credential still signs on every upstream, because a downstream Claude Code
  pointed at CPA cannot produce that value itself, while a claude-code-cli
  API key signs only on api.anthropic.com or Vertex
- Drop the unused origin parameter from Claude fingerprint policy resolution
  and restore the original resolveClaudeWirePolicy signature; the wire profile
  follows the credential and only CCH follows the origin
- Add config.NormalizeClaudeFingerprintProfile / ValidateClaudeFingerprintProfile
  as the single source of truth for fingerprint-profile values
- Reject unknown fingerprint-profile values in the Management API, and warn
  once per distinct value at request time instead of on every resolution,
  which previously logged about four warnings per request for one typo
- Preserve unrecognized values through config sanitization so rewriting a
  config file never discards operator input
- Update config.example.yaml and tests for the origin-scoped CCH behavior
2026-08-18 18:06:40 +08:00
sususu98
f1b0431c77 feat(claude): add fingerprint-profile=claude-code-cli for API keys and delegated providers (#5047)
* feat(config): add fingerprint-profile to Claude keys and auth JSON

- Add FingerprintProfile to ClaudeKey configuration struct and normalizer
- Track fingerprint-profile in config diff
- Map fingerprint-profile / fingerprint_profile to auth attributes in file and config synthesizers
- Support fingerprint-profile in Management API PatchClaudeKey and normalization
- Add Claude billing attribution string manipulation utilities in internal/util
- Document fingerprint-profile options in config.example.yaml

* feat(claude): add fingerprint policy and request-local CLI identity

- Centralize Claude fingerprint policy resolution in claude_fingerprint_policy.go
- Support stable Claude CLI identity synthesis (UUIDv5 account_uuid and SHA-256 device_id)
  seeded from API keys or stable OAuth IDs, keeping access tokens isolated
- Warn on unrecognized fingerprint-profile values

* feat(claude): apply CLI fingerprint to Messages and keep API keys caller-owned

- Wire centralized fingerprint policy into Claude and Kimi executors
- Keep first-party Anthropic API keys and delegated providers caller-owned by default
- Apply Claude Code CLI wire profile (betas, metadata, diagnostics, MCP aliases)
  when fingerprint-profile=claude-code-cli is configured
- Strictly align CCH signing with native Claude Code 2.1.220: only first-party
  api.anthropic.com and Vertex sign dynamic CCH; third-party gateways and Kimi
  receive billing header without cch= to avoid prompt cache busting
- Respect caller-owned count_tokens bodies by default while aligning CLI shape on opt-in
- Fall back to CLIProxyAPI/<version> User-Agent when caller sends no UA in caller-owned mode
- Scope custom operator header overrides accurately in caller-owned mode
- Add comprehensive test coverage for policy resolution, gateway opt-in, Kimi, and token counting
2026-08-18 17:29:26 +08:00
hkfires
5bffd1514f Refactor cooling management across configuration and handlers
- Changed `DisableCooling` from a boolean to a pointer in various config types to allow explicit inheritance.
- Updated tests to reflect the new pointer usage for `DisableCooling`.
- Enhanced the `BuildConfigChangeDetails` function to handle optional boolean changes for `DisableCooling`.
- Added new tests to ensure proper handling of cooling overrides in configurations.
- Refactored the `SetQuotaCooldownDisabled` function and related logic to clarify the purpose of cooldown management.
- Introduced new tests for cooling override precedence in the auth manager.
- Ensured that all relevant handlers and synthesizers correctly manage the `DisableCooling` setting.
2026-08-17 10:54:07 +08:00
Luis Pater
aa10847e12 feat(auth): add request-scoped error action handling in conductor
- Add request-scoped error rule extraction from auth metadata or runtime provider config (including OpenAI compatibility fallback)
- Match rules by HTTP/status-code plus error body substring or regex patterns
- Support `stop`, `stop-and-cooldown`, `continue`, `continue-and-cooldown` actions with normalized validation
- Apply matched actions to execution results via request-scoped vs force-cooldown error codes and stop/continue flow control
- Introduce request-stop error wrappers/helpers for matching and unwrapping scoped stop state

Closes: #5006
2026-08-16 21:39:38 +08:00
Chén Mù
48d021813b Merge pull request #4994 from router-for-me/models
feat(models): add max_completion_tokens to model definitions and responses
2026-08-15 16:39:30 +08:00
hkfires
046b59ecc5 feat(models): add max_completion_tokens to model definitions and responses 2026-08-15 16:27:57 +08:00
Luis Pater
b90d8ee9eb fix(auth): preserve custom auth-file metadata during token refresh and relogin
- Added metadata merge helpers in `sdk/cliproxy/auth` to retain existing auth-file settings while excluding token lifecycle fields.
- Applied merge before saving in management handler and `sdk/auth.Manager.Login` so re-login overwrites credentials without discarding user-configured fields.
- Updated token save paths for Claude, Codex, Kimi, XAI, and Vertex to persist merged metadata payloads when writing auth files.

Closes: #4945
2026-08-15 00:07:27 +08:00
Luis Pater
db35b91e2a feat(openai): add xAI Grok Imagine Image 2.0 image model support
- Added `grok-imagine-image-2.0` as a first-class xAI image base model across validation, canonicalization, and routing checks.
- Registered the model in built-in model definitions so it appears in model metadata.
- Updated image model allowlists and request validation error messaging to include the new model.
- Marked the new model as hidden in client visibility override handling.
2026-08-13 14:37:29 +08:00
Luis Pater
6f2cea9484 feat(config): add per-credential request-retry override support
Closes: #4931
2026-08-13 01:50:47 +08:00
Luis Pater
17a479a8db feat(management): add request-scoped proxy override for APICall
- Add `proxy_url` to APICall request payload and document it as highest-priority proxy selection.
- Validate request-provided proxy URLs and reject invalid values with `400`.
- Pass request proxy through token resolution/Antigravity token refresh and APICall transport setup.
- Update transport precedence so `proxy_url` overrides credential/global proxies; invalid request proxy falls back to direct.
2026-08-12 15:26:32 +08:00
Luis Pater
bd34ceca04 feat(codex): add realtime hangup forwarding and local client-secret support
- Add Codex live handlers for unsupported translation/transcription/SIP endpoints, returning standardized `realtime_capability_not_supported` errors.
- Implement `HandleHangup` to validate call ownership, select/refresh pinned OAuth credentials, forward hangup requests to upstream, and complete local session on success.
- Add ephemeral client-secret infrastructure for local ephemeral auth: create/authenticate endpoints, token storage with expiry/capacity limits, session normalization/model mapping, and unified realtime error handling.

Closes: #4726
2026-08-10 22:52:56 +08:00
Luis Pater
e64cdbf559 fix(codex): resolve credential-aware model before forwarding API-key alpha search requests
Closes: #4714
2026-08-08 05:36:20 +08:00
Luis Pater
4b3cc55cdc fix(cliproxy): centralize client error status mapping and apply context cancellation/deadline HTTP codes
Closes: #4601
2026-08-08 04:53:34 +08:00
Luis Pater
32f1069a18 Merge pull request #4668 from oscarbrey/fix/grok-imagine-video-1.5-ga
fix(xai): support Grok Imagine Video 1.5 GA
2026-08-04 23:12:15 +08:00
Luis Pater
b782d4374f feat(api): add Grok Shell-aware /v1/models handling with dedicated model response formatting 2026-08-04 17:49:43 +08:00
Supra4E8C
0fc028613b chore: exclude test changes from Home fixes 2026-08-03 21:40:06 +08:00
Supra4E8C
a81b9e9ced fix(home): report every unauthorized attempt 2026-08-03 21:40:06 +08:00
Supra4E8C
1e38a3a544 fix: retry Home OAuth requests after unauthorized 2026-08-03 21:39:48 +08:00
sususu
f3e25ab2ba feat(claude): align OAuth wire identity and TLS with Claude Code 2.1.220
Detect confirmed CLI, sdk-cli and VSCode callers before mutation so native
software, system, tool, cache and beta shapes pass through, while unconfirmed
OAuth clients receive a coherent minimum CLI identity.

Persist each Claude OAuth credential's upstream account metadata and one stable
device ID, derive one stable session per agent conversation, and keep body and
header identity synchronized across Messages, streaming and count_tokens.

Alias every cloaked third-party custom tool through caller-stable opaque MCP
names and restore declarations, choices, history, references, non-stream
responses and SSE events without changing tool ownership.

Implement the Claude Code 2.1.220 CCH algorithm over the final serialized
request bytes, align currentDate and first-user cache layout, update the
official beta/header baseline, and use upstream count_tokens for OAuth and
first-party Anthropic credentials.

Match the 2.1.220 TLS ClientHello so the transport fingerprint agrees with the
identity the request now claims, and document the CLI defaults and automatic
OAuth signing / tool alias behaviour in config.example.yaml.
2026-08-03 14:47:26 +08:00
Luis Pater
08eb05ae87 feat(config): add support-prompt-cache-key option for OpenAI compatibility
- Introduced a new `support-prompt-cache-key` configuration option to enable optional prompt cache key derivation for supported models.
- Updated relevant API handlers and internal logic to handle the new configuration.
- Enhanced executor workflows to apply prompt cache keys conditionally during request processing.
- Added tests to validate prompt cache key behavior across various scenarios and providers.
- Updated configuration examples and documentation for the new option.

Closes: #4700
2026-08-01 11:39:50 +08:00
Luis Pater
198a26737c feat(codex): add Alpha Search API key support with configurable endpoint
- Introduced `alpha-search` flag for Codex API keys to enable Alpha Search functionality.
- Added `CredentialPolicyCodexAlphaSearchV1` for filtering and validating API keys compatible with Alpha Search.
- Extended configuration, synthesizer, and watcher functionality to track and manage `alpha-search` flag changes.
- Updated Codex executor to dynamically construct Alpha Search endpoint based on API key attributes.
- Enhanced tests to validate Alpha Search flag handling, endpoint construction, and credential filtering.

Closes: #4692
2026-08-01 00:31:26 +08:00
Supra4E8C
e8e39526b3 feat(auth): add support for credential weight parsing in auth file handling 2026-07-30 07:36:58 +08:00
oscarbrey
abaeb55bb2 fix(xai): support Grok Imagine Video 1.5 GA 2026-07-29 23:06:30 +02:00
Luis Pater
5dcca50fd9 feat(auth): introduce weighted round-robin scheduler and credential weight validation
- Added support for weighted round-robin authentication scheduling strategy.
- Implemented credential weight validation for attributes and metadata, with strict error handling for invalid weights.
- Enhanced scheduler with smooth weighted state handling and proportional selection logic.
- Introduced tests for credential weight parsing, validation, and weighted round-robin behavior.
- Updated configuration to include `weight` field for credentials with range validation.

Closes: #4470
2026-07-28 14:23:23 +08:00
Luis Pater
7b233fa316 test(server): add minimal reasoning level in Codex-supported levels test 2026-07-28 01:55:34 +08:00
Luis Pater
6914478562 feat(config): add support for disabling model list cloaking in Claude Code
- Introduced `DisableCloakingModelList` in `ClaudeCodeConfig` to control model ID cloaking in Anthropic model list responses.
- Updated relevant APIs and handlers to respect the new configuration.
- Added comprehensive tests for enabling/disabling cloaking behavior and config-driven hot reload scenarios.
- Extended example configuration and documentation to include the new setting.

Closes: #4473
2026-07-27 18:16:41 +08:00
Luis Pater
fe4ae4989c chore(pluginhost): refactor and remove unused interceptors and executor methods
- Removed deprecated interceptor and executor-related methods, including `callRequestInterceptor`, `callResponseInterceptor`, and `callStreamChunkInterceptor`.
- Consolidated unused logic and pruned redundant imports to streamline `adapters.go`.
- No functional changes.
2026-07-26 14:31:45 +08:00
Luis Pater
bda79b21bb feat(live): relay realtime WebRTC media 2026-07-25 05:11:28 +08:00
Luis Pater
46172dd452 feat(live): add Codex Live session handler and sideband support
- Implemented `live` package to handle Codex WebRTC session bootstrap requests.
- Introduced session forwarding, OAuth-based selection, and multipart payload handling.
- Added sideband WebSocket relay functionality with authorization pinning.
- Comprehensive tests for session handling, response validation, and header management included.

Closes: #4541
2026-07-25 03:44:41 +08:00
Luis Pater
0296600be6 feat(models): add Claude client model catalog and response builder
- Introduced a new `models` package for organizing Claude client model templates and building responses.
- Migrated Claude response handling to `claudemodels.BuildResponse`.
- Added comprehensive tests for model ID transformation, sorting, and metadata validation.
- Removed redundant utility functions and simplified integration with the API server.
2026-07-25 01:41:07 +08:00
Luis Pater
71d591296b feat(models): add Codex client model catalog and response builder
- Introduced a new `models` package for organizing Codex client model templates and building responses.
- Migrated Codex response handling to `codexmodels.BuildResponse`.
- Added comprehensive tests for model metadata, reasoning levels, and input modalities handling.
2026-07-25 01:24:22 +08:00
Luis Pater
84bf9376e5 feat(executor): replace sdktranslator.TranslateRequest with helps.TranslateRequestWithCodexMultiAgentV2
- Updated Kimi and Gemini executors to use `TranslateRequestWithCodexMultiAgentV2` for improved multi-agent v2 optimization.
- Enhanced configuration and API server to support `CodexOptimizeMultiAgentV2`.
- Added codex multi-agent V2 optimizations in `config`, `executor`, and `watcher` modules.
2026-07-25 00:32:37 +08:00
Luis Pater
b30e7d992a Merge branch 'credential-concurrency' into dev
# Conflicts:
#	internal/api/server.go
2026-07-23 13:53:11 +08:00
Luis Pater
3ecd4afe80 feat: add Home credential concurrency support 2026-07-23 13:42:08 +08:00
Luis Pater
f71ec0eb67 feat(server): add support for Codex Alpha Search model routing
- Implemented `codexAlphaSearchSelectionModel` and `codexAlphaSearchModelRouterHost` for dynamic model selection using plugin-based routing.
- Introduced new `codex-alpha-search` source format for model route requests.
- Integrated routing logic into the model selection pipeline to handle Codex Alpha Search requests with fallback mechanisms.
2026-07-22 22:46:10 +08:00
Luis Pater
36b45d57a3 Merge pull request #4083 from seakee/fix/auth-files-filter-by-index
fix(management): filter auth files by name and auth index
2026-07-21 22:06:35 +08:00
Luis Pater
366271969a feat(logging): add CPA trace ID middleware and enhance metadata handling
- Introduced CPA trace ID middleware to inject trace IDs in response headers.
- Added support for CPA trace ID generation and validation.
- Updated metadata handling to include stable auth indices and trace ID callbacks for enhanced request tracking.
- Enhanced tests to verify CPA trace ID propagation and reserved header handling across middleware, metadata, and handlers.

Closes: #4370
2026-07-17 22:58:28 +08:00
hkfires
5243b38ab7 feat(pluginstore): implement plugin synchronization and validation
- Introduced PluginSyncRequest and PluginSyncResponse types for managing plugin synchronization.
- Added validation logic for plugin sync responses, including checks for schema version and expiration.
- Implemented functionality to clear sensitive data from plugin sync requests and responses.
- Enhanced error handling for HTTP requests related to plugin synchronization.
- Updated manifest validation to reject artifact URLs containing credentials or query parameters.
- Added tests for plugin synchronization, ensuring proper validation and error handling.
- Refactored existing code to support resolved authentication configurations for plugin downloads.
2026-07-17 08:09:05 +08:00
Luis Pater
35a5f06612 feat(config): resolve plugin directory paths and handle tilde expansion
- Added `ResolvePluginsDir` to normalize plugin directory paths, including tilde (`~`) expansion.
- Integrated directory resolution into config loading, runtime setup, and plugin management flows.
- Updated tests across components to validate correct handling of unresolved and expanded plugin paths.
- Added error handling for invalid or unresolved plugin directories to prevent runtime issues.

Closes: #4313
2026-07-15 16:53:02 +08:00
Luis Pater
e57416731a feat(logging): add deferred request body capture for error handling
- Introduced `deferredRequestBodyCapture` for spooling and retaining large error-only request bodies for improved logging.
- Enhanced `RequestLoggingMiddleware` to capture request body based on size and error criteria.
- Implemented decompression and truncation for large request bodies with Zstd encoding.
- Added support for deferred API request logging and context tracking.
- Included extensive test coverage for error-specific body capture and serialization behavior.
2026-07-14 23:35:29 +08:00
Luis Pater
411d7d41ee feat(auth): add SelectAuthByKind method and enhance Codex Alpha Search handling
- Implemented `SelectAuthByKind` to filter and select credentials by kind with retry logic and error handling.
- Updated Codex Alpha Search to enforce OAuth credentials and sanitize upstream request body.
- Added unit tests to validate `SelectAuthByKind` behavior across scenarios.
- Introduced `sanitizeCodexAlphaSearchBody` for removing sensitive fields from API payloads.

Closes #4289
2026-07-14 16:31:45 +08:00
Luis Pater
423f3d5ff7 feat(xai): add xAI API key support with comprehensive handling and tests
- Introduced `xai-api-key` to configuration for supporting xAI provider integration.
- Added API key operations: creation, updates, deletion, and sanitization.
- Implemented backend enhancements for credential-specific routing, response filtering with model aliasing, and WebSocket handling for xAI services.
- Included extensive test coverage to validate configuration parsing, CRUD operations, and the new functionalities.
- Updated related modules to handle `xai-api-key`, including the watcher, management handlers, and configuration sanitizers.
2026-07-14 04:40:12 +08:00
sususu98
4fe2c60c51 feat(registry): remote-refresh Codex client model catalog (#4276)
Load codex_client_models.json like models.json with validation, revisioned
handler reloads, CI bake, and Home-aware updater gates so list IDs still
come from Home while templates can refresh on the edge.
2026-07-13 17:47:35 +08:00
Luis Pater
55f4d6ed1d feat(codex): pass Gin context to auth selection for Alpha search
- Introduced `codexSearchGinContextSelector` to capture and validate Gin context during credential selection.
- Added test case to verify context propagation and query parameter usage (`TestCodexAlphaSearchPassesGinContextToAuthSelection`).
- Updated `SelectAuth` implementation to include Gin context for enhanced compatibility with Home scheduling.
2026-07-12 23:06:38 +08:00
Luis Pater
9c3f720710 feat(codex): implement session affinity and request logging for alpha search
- Added `SelectAuth` method to enhance flexible credential selection.
- Introduced session affinity mechanism for consistent credential reuse per session.
- Enabled detailed request/response logging for Codex alpha search API.
- Updated tests to validate session affinity behavior and log capture.

Closes: #4166
2026-07-12 22:59:14 +08:00
Ozwasyd
46e2894ad3 fix(codex): proxy GPT-5.6 standalone search 2026-07-12 15:40:12 +08:00
Luis Pater
6e819ab622 feat(oauth): refactor for device flow and cancelable sessions, extend test coverage
- Replaced PKCE-based OAuth for xAI with device authorization flow for enhanced compatibility.
- Introduced cancelable OAuth sessions with server-side invalidation to prevent token persistence on flow interruption.
- Updated OAuth polling and session tracking to handle device flow specifics, such as `user_code` and extended timeouts.
- Refactored TUI OAuth model to track polling generations, distinguish device flow, and handle session cancellation gracefully.
- Extended test cases for device flow scenarios, stale session handling, and cancelation logic.
- Streamlined xAI device flow management in handler logic and improved error handling.
2026-07-11 02:50:23 +08:00