1138 Commits

Author SHA1 Message Date
Luis Pater ae06f13e0e Extract argument parsing logic into parseArgsToMap helper function
Simplifies parsing and error handling for function arguments across OpenAI response processing methods. Replaces repeated logic with a reusable utility function.
2025-09-03 00:41:16 +08:00
Luis Pater 0652241519 Update README to rename gpt-5-nano to gpt-5-minimal in usage examples 2025-09-03 00:20:47 +08:00
Luis Pater edf9d9b747 Merge branch 'main' of github.com:luispater/CLIProxyAPI 2025-09-03 00:16:04 +08:00
Luis Pater 3acdec51bd Add OpenAI Responses support 2025-09-03 00:15:35 +08:00
Luis Pater ce5d2bad97 Add OpenAI Responses support 2025-09-03 00:09:23 +08:00
Luis Pater 34855bc647 **Fix model switch logic when quota is exceeded**
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
Ensure `modelName` is updated after switching to a new model, avoiding inconsistencies in subsequent iterations.
v5.0.4
2025-09-01 21:37:03 +08:00
Luis Pater 56c8297f6b **Handle data: without trailing space in streaming responses**
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
Add support for API providers that emit `data:` (no space) in Server‑Sent Events. Introduces a new `dataUglyTag` and corresponding parsing logic to correctly process and forward these lines, ensuring compatibility with non‑standard streaming formats.

Fuck for them all
v5.0.3
2025-09-01 17:38:24 +08:00
Luis Pater e11637dc62 Refactor translator packages for OpenAI Chat Completions
- Renamed `openai` packages to `chat_completions` across translator modules.
- Introduced `openai_responses_handlers` with handlers for `/v1/models` and OpenAI-compatible chat completions endpoints.
- Updated constants and registry identifiers for OpenAI response type.
- Simplified request/response conversions and added detailed retry/error handling.
- Added `golang.org/x/crypto` for additional cryptographic functions.
2025-09-01 11:00:47 +08:00
Luis Pater e0bff9f212 Refactor translator packages for OpenAI Chat Completions
- Renamed `openai` packages to `chat_completions` across translator modules.
- Introduced `openai_responses_handlers` with handlers for `/v1/models` and OpenAI-compatible chat completions endpoints.
- Updated constants and registry identifiers for OpenAI response type.
- Simplified request/response conversions and added detailed retry/error handling.
- Added `golang.org/x/crypto` for additional cryptographic functions.
2025-09-01 10:28:29 +08:00
Luis Pater bff6f6679b Refactor translator packages for OpenAI Chat Completions
- Renamed `openai` packages to `chat_completions` across translator modules.
- Introduced `openai_responses_handlers` with handlers for `/v1/models` and OpenAI-compatible chat completions endpoints.
- Updated constants and registry identifiers for OpenAI response type.
- Simplified request/response conversions and added detailed retry/error handling.
- Added `golang.org/x/crypto` for additional cryptographic functions.
2025-09-01 10:20:50 +08:00
Luis Pater 305916f5a9 Refactor translator packages for OpenAI Chat Completions
- Renamed `openai` packages to `chat_completions` across translator modules.
- Introduced `openai_responses_handlers` with handlers for `/v1/models` and OpenAI-compatible chat completions endpoints.
- Updated constants and registry identifiers for OpenAI response type.
- Simplified request/response conversions and added detailed retry/error handling.
- Added `golang.org/x/crypto` for additional cryptographic functions.
2025-09-01 10:07:33 +08:00
Luis Pater 1f46dc2715 Refactor translator packages for OpenAI Chat Completions
- Renamed `openai` packages to `chat_completions` across translator modules.
- Introduced `openai_responses_handlers` with handlers for `/v1/models` and OpenAI-compatible chat completions endpoints.
- Updated constants and registry identifiers for OpenAI response type.
- Simplified request/response conversions and added detailed retry/error handling.
- Added `golang.org/x/crypto` for additional cryptographic functions.
2025-09-01 08:37:41 +08:00
Luis Pater e3994ace33 Refactor translator packages for OpenAI Chat Completions
- Renamed `openai` packages to `chat_completions` across translator modules.
- Introduced `openai_responses_handlers` with handlers for `/v1/models` and OpenAI-compatible chat completions endpoints.
- Updated constants and registry identifiers for OpenAI response type.
- Simplified request/response conversions and added detailed retry/error handling.
- Added `golang.org/x/crypto` for additional cryptographic functions.
2025-09-01 08:18:59 +08:00
Luis Pater bdac24bb4e Update PassthroughGeminiResponseStream to handle [DONE] marker
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Added logic to return an empty slice when the raw JSON equals the `[DONE]` marker.
- Ensures proper termination of streamed Gemini responses.
v5.0.2
2025-09-01 02:00:55 +08:00
Luis Pater 6d30faf9c9 Update Management API CN docs for authentication requirements
- Changed authentication requirements to mandate management keys for all requests, including local access.
- Clarified remote access setup and key provision methods.
- Adjusted the section header.
2025-08-31 15:29:20 +08:00
Luis Pater c0eaa41c7a Add Gemini-to-Gemini request normalization and passthrough support
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Introduced a `ConvertGeminiRequestToGemini` function to normalize Gemini v1beta requests by ensuring valid or default roles.
- Added passthrough response handlers for both streamed and non-streamed Gemini responses.
- Registered translators for Gemini-to-Gemini traffic in the initialization process.
- Updated `gemini-cli` request normalization to align with the new Gemini translator logic.
v5.0.1
2025-08-31 15:05:16 +08:00
Luis Pater 8a2285e706 Reorganize and reintroduce Management API section in README files 2025-08-31 14:41:57 +08:00
Luis Pater db43930b98 Add management API handlers for config and auth file management
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Implemented CRUD operations for authentication files.
- Added endpoints for managing API keys, quotas, proxy settings, and other configurations.
- Enhanced management access with robust validation, remote access control, and persistence support.
- Updated README with new configuration details.

Fixed OpenAI Chat Completions for codex
v5.0.0
2025-08-31 14:29:23 +08:00
Luis Pater b1254106ee Enhance client reload process with new OpenAI compatibility support
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Added handling for OpenAI-compatible providers during client reload.
- Implemented client unregistration for old clients during reload.
- Improved logging for detailed client reload insights.

Expand `AuthDir` handling to support tilde (`~`) for home directory resolution

- Added logic to replace `~` with the user's home directory in `AuthDir`.
- Prevents errors when using `~` in configuration paths.
v4.1.12
2025-08-31 03:04:46 +08:00
Luis Pater 9c9ea99380 Add support for new GPT-5 model variants
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Renamed existing GPT-5 variants for consistency (`nano` → `minimal`, `mini` → `low`, etc.).
- Added metadata definitions for new variants: `gpt-5-minimal`, `gpt-5-low`, `gpt-5-medium`, and updated logic to reflect variant-specific reasoning efforts.
v4.1.11
2025-08-30 22:00:37 +08:00
Luis Pater ba4c11428c Merge pull request #16 from hkfires/main
Set the default Docker timezone to Asia/Shanghai
2025-08-30 19:05:32 +08:00
Luis Pater 0331660fe2 Add token refresh handling for 401 responses across clients
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Implemented `RefreshTokens` method in client interfaces and Gemini clients.
- Updated handlers to call `RefreshTokens` on 401 responses and retry requests if token refresh succeeds.
- Enhanced error handling and retry logic to accommodate token refresh flow.

Update README to include Qwen login instructions

- Added Qwen OAuth login command instructions in both English and Chinese README files.
- Made minor updates to existing command examples for consistency.
v4.1.10
2025-08-30 17:26:41 +08:00
hkfires 3f7840188e Set the default Docker timezone to Asia/Shanghai 2025-08-30 16:41:27 +08:00
Luis Pater 512c8b600a Add token refresh handling for 401 responses across clients
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Implemented `RefreshTokens` method in client interfaces and Gemini clients.
- Updated handlers to call `RefreshTokens` on 401 responses and retry requests if token refresh succeeds.
- Enhanced error handling and retry logic to accommodate token refresh flow.
v4.1.9
2025-08-30 16:10:56 +08:00
Luis Pater 1aad033fec Update issue templates 2025-08-30 04:18:17 +08:00
Luis Pater f1d9364ef4 Update README documentation to clarify auth-dir configuration for Windows users
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Added a note for setting `auth-dir` on Windows systems in both English and Chinese README files.
- Improved descriptions for existing configuration options.

Address Qwen3 tool injection issue to prevent random token insertions

- Modify Qwen client to insert a placeholder tool when none is defined, avoiding erratic behavior in streaming responses.
v4.1.8
2025-08-29 17:28:55 +08:00
Luis Pater c2b2c9eafe Update README documentation to clarify auth-dir configuration for Windows users
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Added a note for setting `auth-dir` on Windows systems in both English and Chinese README files.
- Improved descriptions for existing configuration options.
v4.1.7
2025-08-29 09:52:10 +08:00
Luis Pater 09b9d3b3fa Unlock mutex before returning error in handlers.go to prevent deadlocks
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
v4.1.6
2025-08-29 09:46:12 +08:00
Luis Pater e9e0016a63 Fix some bugs. 2025-08-29 04:05:08 +08:00
Luis Pater 3704dae342 Add nil-check for GetRequestMutex across handlers to prevent potential panics
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Updated all handlers to safely unlock the request mutex only if it's non-nil.
- Enhanced mutex locking and unlocking logic to avoid runtime errors.
- Improved robustness of resource cleanup across clients.

Add `GetRequestMutex` method for synchronization across clients

- Introduced a new `GetRequestMutex` method in OpenAICompatibilityClient, CodexClient, GeminiCLIClient, GeminiClient, and QwenClient for request synchronization.
- Ensures only one request is processed at a time to manage quotas effectively.
v4.1.5
2025-08-29 00:23:37 +08:00
Luis Pater bea5f97cbf Add /v1/completions endpoint with OpenAI compatibility
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Implemented `/v1/completions` endpoint mirroring OpenAI's completions API specification.
- Added conversion functions to translate between completions and chat completions formats.
- Introduced streaming and non-streaming response handling for completions requests.
- Updated `server.go` to register the new endpoint and include it in the API's metadata.
v4.1.4
2025-08-28 00:30:46 +08:00
Luis Pater 7a6adfa97e Suppress debug logs for model routing and ignore empty tools arrays
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Comment out verbose routing logs in the API server to reduce noise.
- Remove the `tools` field from Qwen client requests when it is an empty array.
- Add guards in Claude, Codex, Gemini‑CLI, and Gemini translators to skip tool conversion when the `tools` array is empty, preventing unnecessary payload modifications.
v4.1.3
2025-08-27 22:29:08 +08:00
Luis Pater 1c4183d943 Add support for localhost unauthenticated requests
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Introduced `AllowLocalhostUnauthenticated` flag allowing unauthenticated requests from localhost.
- Updated authentication middleware to bypass checks for localhost when enabled.

Add new Gemini CLI models and update model registry function

- Introduced `GetGeminiCLIModels` for updated Gemini CLI model definitions.
- Added new models: "Gemini 2.5 Flash Lite" and "Gemini 2.5 Pro".
- Updated `RegisterModels` to use `GetGeminiCLIModels` in Gemini client initialization.
v4.1.2
2025-08-27 21:20:25 +08:00
Luis Pater dff31a7a4c Improved the /v1/models endpoint
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
v4.1.1
2025-08-27 21:01:37 +08:00
Luis Pater ed8873fbb0 Add OpenAI compatibility support and improve resource cleanup
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Introduced OpenAI compatibility configurations for external providers, enabling model alias routing via the OpenAI API format.
- Enhanced provider logic in `GetProviderName` to handle OpenAI aliases and added new helper functions for compatibility checks.
- Updated API handlers and client initialization to support OpenAI compatibility models.
- Improved resource cleanup across clients by closing response bodies and streams using deferred functions.
v4.1.0
2025-08-26 03:33:46 +08:00
Luis Pater 9102ff031d Refactor API handlers to implement retry mechanism with configurable limits and improved error handling
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Introduced retry counter with a configurable ` RequestRetry ` limit in all handlers.
- Enhanced error handling with specific HTTP status codes for switching clients.
- Standardized response forwarding for non-retriable errors.
- Improved logging for quota and client switch scenarios.
v4.0.1
2025-08-25 23:43:49 +08:00
Luis Pater 8c555c4e69 Refactor codebase
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
v4.0.0
2025-08-25 16:58:16 +08:00
Luis Pater 2b1762be16 Update README to reflect usage of Qwen models instead of Claude models 2025-08-22 00:34:09 +08:00
Luis Pater aa2f37d54d Add Qwen support
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
v3.2.0
2025-08-21 15:22:53 +08:00
Luis Pater d58cc55cb2 Add claude code support
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
v3.1.0
2025-08-21 02:53:28 +08:00
Luis Pater c5cc238308 Refactor error handling and variable declarations in browser and logging modules
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Simplified variable initialization in `browser.go` for readability.
- Updated error handling in `request_logger.go` with better resource cleanup using deferred anonymous functions.

Refactor API handlers to use `GetContextWithCancel` for streamlined context creation and response handling

- Replaced redundant `context.WithCancel` and `context.WithValue` logic with the new `GetContextWithCancel` utility in all handlers.
- Centralized API response storage in the given context during cancellation.
- Updated associated cancellation calls for consistency and improved resource management.

- Replaced `apiResponseData` with `AddAPIResponseData` for centralized response recording.
- Simplified cancellation logic by switching to a boolean-based `cliCancel` method.
- Removed unused `apiResponseData` slices across handlers to reduce memory usage.
- Updated `handlers.go` to support unified response data storage per request context.
v3.0.4
2025-08-17 20:13:45 +08:00
Luis Pater 6bbdf67f96 Refactor Gemini API handlers to standardize response field names and improve model descriptions
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
v3.0.3
2025-08-17 00:28:13 +08:00
Luis Pater fcadf08921 Add request logging capabilities to API handlers and update .gitignore
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
Enhance API response handling by storing responses in context and updating request logger to include API responses
v3.0.2
2025-08-16 06:09:04 +08:00
Luis Pater 4155805ad6 Add support for Codex model in provider logic and update documentation for claude code
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
v3.0.1
2025-08-16 02:02:44 +08:00
Luis Pater de7b8501cc Add openai codex support
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
v3.0.0
2025-08-16 01:22:33 +08:00
Luis Pater d2394b0be9 Update .goreleaser.yml to specify archive formats for different OS targets
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Added `tar.gz` as the default archive format.
- Introduced `zip` format override for Windows builds.
v2.4.2
2025-08-08 14:28:02 +08:00
Luis Pater ebcd4dbf3d Fix activation URL extraction logic and improve warning message formatting
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Corrected JSON path for error code and activation URL extraction in client error handling.
- Improved readability of the activation warning message with better spacing.
v2.4.1
2025-08-05 23:58:43 +08:00
Luis Pater 1483c31c73 Refactor API handlers organization and simplify error response handling
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Modularized handlers into dedicated packages (`gemini`, `claude`, `cli`) for better structure.
- Centralized `ErrorResponse` and `ErrorDetail` types under `handlers` package for reuse.
- Updated all handlers to utilize the shared `ErrorResponse` model.
- Introduced specialization of handler structs (`GeminiAPIHandlers`, `ClaudeCodeAPIHandlers`, `GeminiCLIAPIHandlers`) for improved clarity and separation of concerns.
- Refactored `getClient` logic with additional properties and better state management.

Refactor `translator` package by modularizing code for `claude` and `gemini`

- Moved Claude-specific logic (`PrepareClaudeRequest`, `ConvertCliToClaude`) to `translator/claude/code`.
- Moved Gemini-specific logic (`FixCLIToolResponse`) to `translator/gemini/cli` for better package structure.
- Updated affected handler imports and method references.

Add comprehensive package-level documentation across key modules

- Introduced detailed package-level documentation for core modules: `auth`, `client`, `cmd`, `handlers`, `util`, `watcher`, `config`, `translator`, and `api`.
- Enhanced code readability and maintainability by clarifying the purpose and functionality of each package.
- Aligned documentation style and tone with existing codebase conventions.

Refactor API handlers and translator modules for improved clarity and consistency

- Standardized handler struct names (`GeminiAPIHandlers`, `ClaudeCodeAPIHandlers`, `GeminiCLIAPIHandlers`, `OpenAIAPIHandlers`) and updated related comments.
- Fixed unnecessary `else` blocks in streaming logic for cleaner error handling.
- Renamed variables for better readability (`responseIdResult` to `responseIDResult`, `activationUrl` to `activationURL`, etc.).
- Addressed minor inconsistencies in API handler comments and SSE header initialization.
- Improved modularization of `claude` and `gemini` translator components.

Standardize configuration field naming for consistency across modules

- Renamed `ProxyUrl` to `ProxyURL`, `ApiKeys` to `APIKeys`, and `ConfigQuotaExceeded` to `QuotaExceeded`.
- Updated all relevant references and comments in `config`, `auth`, `api`, `util`, and `watcher`.
- Ensured consistent casing for `GlAPIKey` debug logs.
v2.4.0
2025-08-05 23:11:31 +08:00
Luis Pater 00f33f5f3a Enhance Gemini request handling for contents support and improve error logging
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Added conditional logic to process `contents` in Gemini request templates, ensuring fallback behavior.
- Introduced detailed debug logs for quota errors and request issues.
- Updated handling of `rawJson` to construct templates more dynamically.
v2.3.1
2025-08-04 02:51:00 +08:00
Luis Pater 3c4dc07980 Add file watcher for dynamic configuration and client reloading
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Introduced `Watcher` for monitoring updates to the configuration file and authentication directory.
- Integrated file watching into `StartService` to handle dynamic changes without restarting.
- Enhanced API server and handlers to support client and configuration updates.
- Updated `.gitignore` to include `docs/` directory.
- Modified go dependencies to include `fsnotify` for the file watcher.
v2.3.0
2025-08-02 16:15:56 +08:00