From 702a407007a9d5d3ec9600d90f1bb75c7c30a5fe Mon Sep 17 00:00:00 2001 From: Koosha Paridehpour Date: Tue, 24 Feb 2026 23:29:37 -0700 Subject: [PATCH 1/2] Layer 3: cherry-pick full-sdk type unification --- .../active/pkg/llmproxy/config/sdk_config.go | 13 ------ .../active/pkg/llmproxy/config/sdk_types.go | 43 +++++++++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) delete mode 100644 .worktrees/config/m/config-build/active/pkg/llmproxy/config/sdk_config.go create mode 100644 .worktrees/config/m/config-build/active/pkg/llmproxy/config/sdk_types.go diff --git a/.worktrees/config/m/config-build/active/pkg/llmproxy/config/sdk_config.go b/.worktrees/config/m/config-build/active/pkg/llmproxy/config/sdk_config.go deleted file mode 100644 index 63e25a079b..0000000000 --- a/.worktrees/config/m/config-build/active/pkg/llmproxy/config/sdk_config.go +++ /dev/null @@ -1,13 +0,0 @@ -// Package config provides configuration management for the CLI Proxy API server. -// It handles loading and parsing YAML configuration files, and provides structured -// access to application settings including server port, authentication directory, -// debug settings, proxy configuration, and API keys. -package config - -import internalconfig "github.com/router-for-me/CLIProxyAPI/v6/internal/config" - -// SDKConfig is an alias to internal/config.SDKConfig. -type SDKConfig = internalconfig.SDKConfig - -// StreamingConfig is an alias to internal/config.StreamingConfig. -type StreamingConfig = internalconfig.StreamingConfig diff --git a/.worktrees/config/m/config-build/active/pkg/llmproxy/config/sdk_types.go b/.worktrees/config/m/config-build/active/pkg/llmproxy/config/sdk_types.go new file mode 100644 index 0000000000..bf4fb90ecf --- /dev/null +++ b/.worktrees/config/m/config-build/active/pkg/llmproxy/config/sdk_types.go @@ -0,0 +1,43 @@ +// Package config provides configuration types for CLI Proxy API. +// This file contains SDK-specific config types that are used by internal/* packages. +package config + +// SDKConfig represents the SDK-level configuration embedded in Config. +type SDKConfig struct { + // ProxyURL is the URL of an optional proxy server to use for outbound requests. + ProxyURL string `yaml:"proxy-url" json:"proxy-url"` + + // ForceModelPrefix requires explicit model prefixes (e.g., "teamA/gemini-3-pro-preview") + // to target prefixed credentials. When false, unprefixed model requests may use prefixed + // credentials as well. + ForceModelPrefix bool `yaml:"force-model-prefix" json:"force-model-prefix"` + + // RequestLog enables or disables detailed request logging functionality. + RequestLog bool `yaml:"request-log" json:"request-log"` + + // APIKeys is a list of keys for authenticating clients to this proxy server. + APIKeys []string `yaml:"api-keys" json:"api-keys"` + + // PassthroughHeaders controls whether upstream response headers are forwarded to downstream clients. + // Default is false (disabled). + PassthroughHeaders bool `yaml:"passthrough-headers" json:"passthrough-headers"` + + // Streaming configures server-side streaming behavior (keep-alives and safe bootstrap retries). + Streaming StreamingConfig `yaml:"streaming" json:"streaming"` + + // NonStreamKeepAliveInterval controls how often blank lines are emitted for non-streaming responses. + // <= 0 disables keep-alives. Value is in seconds. + NonStreamKeepAliveInterval int `yaml:"nonstream-keepalive-interval,omitempty" json:"nonstream-keepalive-interval,omitempty"` +} + +// StreamingConfig holds server streaming behavior configuration. +type StreamingConfig struct { + // KeepAliveSeconds controls how often the server emits SSE heartbeats (": keep-alive\n\n"). + // <= 0 disables keep-alives. Default is 0. + KeepAliveSeconds int `yaml:"keepalive-seconds,omitempty" json:"keepalive-seconds,omitempty"` + + // BootstrapRetries controls how many times the server may retry a streaming request before any bytes are sent, + // to allow auth rotation / transient recovery. + // <= 0 disables bootstrap retries. Default is 0. + BootstrapRetries int `yaml:"bootstrap-retries,omitempty" json:"bootstrap-retries,omitempty"` +} From 05c8cbb0c3f8ddd60a30e2b4634434f18ee84da4 Mon Sep 17 00:00:00 2001 From: Koosha Paridehpour Date: Tue, 24 Feb 2026 23:30:15 -0700 Subject: [PATCH 2/2] Layer 4: apply test-cleanups README/doc cleanup --- README.md | 240 ++++++++++++++++-------------------------------------- 1 file changed, 69 insertions(+), 171 deletions(-) diff --git a/README.md b/README.md index 12eaec1040..2d950a4c86 100644 --- a/README.md +++ b/README.md @@ -1,202 +1,100 @@ -# CLIProxyAPI++ (KooshaPari Fork) +# CLIProxyAPI Plus -This repository works with Claude and other AI agents as autonomous software engineers. +English | [Chinese](README_CN.md) -## Quick Start +This is the Plus version of [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI), adding support for third-party providers on top of the mainline project. -```bash -# Docker -docker run -p 8317:8317 eceasy/cli-proxy-api-plus:latest +All third-party provider support is maintained by community contributors; CLIProxyAPI does not provide technical support. Please contact the corresponding community maintainer if you need assistance. -# Or build from source -go build -o cliproxy ./cmd/cliproxy -./cliproxy --config config.yaml +The Plus release stays in lockstep with the mainline features. -# Health check -curl http://localhost:8317/health -``` +## Differences from the Mainline -## Multi-Provider Routing +- Added GitHub Copilot support (OAuth login), provided by [em4go](https://github.com/em4go/CLIProxyAPI/tree/feature/github-copilot-auth) +- Added Kiro (AWS CodeWhisperer) support (OAuth login), provided by [fuko2935](https://github.com/fuko2935/CLIProxyAPI/tree/feature/kiro-integration), [Ravens2121](https://github.com/Ravens2121/CLIProxyAPIPlus/) -Route OpenAI-compatible requests to any provider: +## New Features (Plus Enhanced) -```bash -# List models -curl http://localhost:8317/v1/models - -# Chat completion (OpenAI) -curl -X POST http://localhost:8317/v1/chat/completions \ - -H "Content-Type: application/json" \ - -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}' - -# Chat completion (Anthropic) -curl -X POST http://localhost:8317/v1/chat/completions \ - -H "Content-Type: application/json" \ - -d '{"model": "claude-3-5-sonnet", "messages": [{"role": "user", "content": "Hello"}]}' -``` +- **OAuth Web Authentication**: Browser-based OAuth login for Kiro with beautiful web UI +- **Rate Limiter**: Built-in request rate limiting to prevent API abuse +- **Background Token Refresh**: Automatic token refresh 10 minutes before expiration +- **Metrics & Monitoring**: Request metrics collection for monitoring and debugging +- **Device Fingerprint**: Device fingerprint generation for enhanced security +- **Cooldown Management**: Smart cooldown mechanism for API rate limits +- **Usage Checker**: Real-time usage monitoring and quota management +- **Model Converter**: Unified model name conversion across providers +- **UTF-8 Stream Processing**: Improved streaming response handling -### Provider Configuration +## Kiro Authentication -```yaml -providers: - openai: - api_key: ${OPENAI_API_KEY} - anthropic: - api_key: ${ANTHROPIC_API_KEY} - kiro: - enabled: true - github_copilot: - enabled: true - ollama: - enabled: true - base_url: http://localhost:11434 -``` +### Web-based OAuth Login -## Supported Providers +Access the Kiro OAuth web interface at: -| Provider | Auth | Status | -|----------|------|--------| -| OpenAI | API Key | ✅ | -| Anthropic | API Key | ✅ | -| Azure OpenAI | API Key/OAuth | ✅ | -| Google Gemini | API Key | ✅ | -| AWS Bedrock | IAM | ✅ | -| Kiro (CodeWhisperer) | OAuth | ✅ | -| GitHub Copilot | OAuth | ✅ | -| Ollama | Local | ✅ | -| LM Studio | Local | ✅ | +``` +http://your-server:8080/v0/oauth/kiro +``` -## Documentation +This provides a browser-based OAuth flow for Kiro (AWS CodeWhisperer) authentication with: +- AWS Builder ID login +- AWS Identity Center (IDC) login +- Token import from Kiro IDE -- `docs/start-here.md` - Getting started guide -- `docs/provider-usage.md` - Provider configuration -- `docs/provider-quickstarts.md` - Per-provider guides -- `docs/api/` - API reference -- `docs/sdk-usage.md` - SDK guides +## Quick Deployment with Docker -## Environment +### One-Command Deployment ```bash -export OPENAI_API_KEY="sk-..." -export ANTHROPIC_API_KEY="sk-..." -export CLIPROXY_PORT=8317 +# Create deployment directory +mkdir -p ~/cli-proxy && cd ~/cli-proxy + +# Create docker-compose.yml +cat > docker-compose.yml << 'EOF' +services: + cli-proxy-api: + image: eceasy/cli-proxy-api-plus:latest + container_name: cli-proxy-api-plus + ports: + - "8317:8317" + volumes: + - ./config.yaml:/CLIProxyAPI/config.yaml + - ./auths:/root/.cli-proxy-api + - ./logs:/CLIProxyAPI/logs + restart: unless-stopped +EOF + +# Download example config +curl -o config.yaml https://raw.githubusercontent.com/router-for-me/CLIProxyAPIPlus/main/config.example.yaml + +# Pull and start +docker compose pull && docker compose up -d ``` ---- - -## Development Philosophy - -### Extend, Never Duplicate - -- NEVER create a v2 file. Refactor the original. -- NEVER create a new class if an existing one can be made generic. -- NEVER create custom implementations when an OSS library exists. -- Before writing ANY new code: search the codebase for existing patterns. - -### Primitives First - -- Build generic building blocks before application logic. -- A provider interface + registry is better than N isolated classes. -- Template strings > hardcoded messages. Config-driven > code-driven. - -### Research Before Implementing - -- Check pkg.go.dev for existing libraries. -- Search GitHub for 80%+ implementations to fork/adapt. - ---- - -## Library Preferences (DO NOT REINVENT) - -| Need | Use | NOT | -|------|-----|-----| -| HTTP router | chi | custom router | -| Logging | zerolog | fmt.Print | -| Config | viper | manual env parsing | -| Validation | go-playground/validator | manual if/else | -| Rate limiting | golang.org/x/time/rate | custom limiter | - ---- - -## Code Quality Non-Negotiables +### Configuration -- Zero new lint suppressions without inline justification -- All new code must pass: go fmt, go vet, golint -- Max function: 40 lines -- No placeholder TODOs in committed code +Edit `config.yaml` before starting: -### Go-Specific Rules - -- Use `go fmt` for formatting -- Use `go vet` for linting -- Use `golangci-lint` for comprehensive linting -- All public APIs must have godoc comments - ---- - -## Verifiable Constraints - -| Metric | Threshold | Enforcement | -|--------|-----------|-------------| -| Tests | 80% coverage | CI gate | -| Lint | 0 errors | golangci-lint | -| Security | 0 critical | trivy scan | - ---- - -## Domain-Specific Patterns - -### What CLIProxyAPI++ Is - -CLIProxyAPI++ is an **OpenAI-compatible API gateway** that translates client requests to multiple upstream LLM providers. The core domain is: provide a single API surface that routes to heterogeneous providers with auth, rate limiting, and metrics. - -### Key Interfaces - -| Interface | Responsibility | Location | -|-----------|---------------|----------| -| **Router** | Request routing to providers | `pkg/llmproxy/router/` | -| **Provider** | Provider abstraction | `pkg/llmproxy/providers/` | -| **Auth** | Credential management | `pkg/llmproxy/auth/` | -| **Rate Limiter** | Throttling | `pkg/llmproxy/ratelimit/` | - -### Request Flow +```yaml +# Basic configuration example +server: + port: 8317 +# Add your provider configurations here ``` -1. Client Request → Router -2. Router → Auth Validation -3. Auth → Provider Selection -4. Provider → Upstream API -5. Response ← Provider -6. Metrics → Response -``` - -### Common Anti-Patterns to Avoid - -- **Hardcoded provider URLs** -- Use configuration -- **Blocking on upstream** -- Use timeouts and circuit breakers -- **No fallbacks** -- Implement provider failover -- **Missing metrics** -- Always track latency/cost ---- +### Update to Latest Version -## Kush Ecosystem +```bash +cd ~/cli-proxy +docker compose pull && docker compose up -d +``` -This project is part of the Kush multi-repo system: +## Contributing -``` -kush/ -├── thegent/ # Agent orchestration -├── agentapi++/ # HTTP API for coding agents -├── cliproxy++/ # LLM proxy (this repo) -├── tokenledger/ # Token and cost tracking -├── 4sgm/ # Python tooling workspace -├── civ/ # Deterministic simulation -├── parpour/ # Spec-first planning -└── pheno-sdk/ # Python SDK -``` +This project only accepts pull requests that relate to third-party provider support. Any pull requests unrelated to third-party provider support will be rejected. ---- +If you need to submit any non-third-party provider changes, please open them against the [mainline](https://github.com/router-for-me/CLIProxyAPI) repository. ## License -MIT License - see LICENSE file +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.