codex-proxy 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. codex_proxy-3.1.0/.dockerignore +6 -0
  2. codex_proxy-3.1.0/.github/ISSUE_TEMPLATE/bug_report.md +22 -0
  3. codex_proxy-3.1.0/.github/ISSUE_TEMPLATE/feature_request.md +13 -0
  4. codex_proxy-3.1.0/.github/PULL_REQUEST_TEMPLATE.md +10 -0
  5. codex_proxy-3.1.0/.github/workflows/ci.yml +43 -0
  6. codex_proxy-3.1.0/.github/workflows/release.yml +22 -0
  7. codex_proxy-3.1.0/.gitignore +14 -0
  8. codex_proxy-3.1.0/.pre-commit-config.yaml +7 -0
  9. codex_proxy-3.1.0/CHANGELOG.md +74 -0
  10. codex_proxy-3.1.0/CODE_OF_CONDUCT.md +33 -0
  11. codex_proxy-3.1.0/CONTRIBUTING.md +127 -0
  12. codex_proxy-3.1.0/Dockerfile +9 -0
  13. codex_proxy-3.1.0/LICENSE +21 -0
  14. codex_proxy-3.1.0/PKG-INFO +25 -0
  15. codex_proxy-3.1.0/README.md +520 -0
  16. codex_proxy-3.1.0/assets/tui-dashboard.png +0 -0
  17. codex_proxy-3.1.0/docker-compose.yml +20 -0
  18. codex_proxy-3.1.0/pyproject.toml +61 -0
  19. codex_proxy-3.1.0/src/codex_proxy/__init__.py +3 -0
  20. codex_proxy-3.1.0/src/codex_proxy/__main__.py +66 -0
  21. codex_proxy-3.1.0/src/codex_proxy/circuit_breaker.py +83 -0
  22. codex_proxy-3.1.0/src/codex_proxy/compaction.py +42 -0
  23. codex_proxy-3.1.0/src/codex_proxy/config.py +313 -0
  24. codex_proxy-3.1.0/src/codex_proxy/key_rotation.py +108 -0
  25. codex_proxy-3.1.0/src/codex_proxy/plugins.py +110 -0
  26. codex_proxy-3.1.0/src/codex_proxy/plugins_builtin.py +34 -0
  27. codex_proxy-3.1.0/src/codex_proxy/providers.py +130 -0
  28. codex_proxy-3.1.0/src/codex_proxy/server.py +647 -0
  29. codex_proxy-3.1.0/src/codex_proxy/store.py +97 -0
  30. codex_proxy-3.1.0/src/codex_proxy/translator.py +360 -0
  31. codex_proxy-3.1.0/src/codex_proxy/tui.py +262 -0
  32. codex_proxy-3.1.0/tests/conftest.py +0 -0
  33. codex_proxy-3.1.0/tests/test_circuit_breaker.py +101 -0
  34. codex_proxy-3.1.0/tests/test_compaction.py +66 -0
  35. codex_proxy-3.1.0/tests/test_config.py +160 -0
  36. codex_proxy-3.1.0/tests/test_key_rotation.py +98 -0
  37. codex_proxy-3.1.0/tests/test_plugins.py +119 -0
  38. codex_proxy-3.1.0/tests/test_providers.py +179 -0
  39. codex_proxy-3.1.0/tests/test_server.py +195 -0
  40. codex_proxy-3.1.0/tests/test_store.py +128 -0
  41. codex_proxy-3.1.0/tests/test_translator.py +309 -0
  42. codex_proxy-3.1.0/tests/test_tui.py +120 -0
@@ -0,0 +1,6 @@
1
+ __pycache__
2
+ *.pyc
3
+ .git
4
+ .venv
5
+ .env
6
+ tests/
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report a problem with codex-proxy
4
+ ---
5
+
6
+ **Describe the bug**
7
+ A clear description of what the bug is.
8
+
9
+ **To Reproduce**
10
+ Steps to reproduce:
11
+ 1. Configure provider '...'
12
+ 2. Send request '...'
13
+ 3. See error
14
+
15
+ **Expected behavior**
16
+ What you expected to happen.
17
+
18
+ **Environment**
19
+ - codex-proxy version:
20
+ - Python version:
21
+ - Provider:
22
+ - OS:
@@ -0,0 +1,13 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest a feature for codex-proxy
4
+ ---
5
+
6
+ **Problem**
7
+ What problem does this feature solve?
8
+
9
+ **Proposed solution**
10
+ Describe the feature you'd like.
11
+
12
+ **Alternatives considered**
13
+ Any alternative approaches you've thought of.
@@ -0,0 +1,10 @@
1
+ ## Summary
2
+
3
+ <!-- Brief description of changes -->
4
+
5
+ ## Checklist
6
+
7
+ - [ ] All tests pass (`pytest tests/ -v`)
8
+ - [ ] No lint errors (`ruff check src/ tests/`)
9
+ - [ ] Type hints on new functions
10
+ - [ ] Docstrings on new classes/public functions
@@ -0,0 +1,43 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - name: Install dependencies
21
+ run: pip install -e ".[dev]"
22
+ - name: Lint with ruff
23
+ run: ruff check src/ tests/
24
+ - name: Run tests
25
+ run: pytest tests/ -v --tb=short
26
+
27
+ build:
28
+ runs-on: ubuntu-latest
29
+ needs: test
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: "3.12"
35
+ - name: Build package
36
+ run: |
37
+ pip install build
38
+ python -m build
39
+ - name: Upload artifacts
40
+ uses: actions/upload-artifact@v4
41
+ with:
42
+ name: dist
43
+ path: dist/
@@ -0,0 +1,22 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ id-token: write
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+ - name: Build
18
+ run: |
19
+ pip install build
20
+ python -m build
21
+ - name: Publish to PyPI
22
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,14 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .venv/
8
+ .env
9
+ *.log
10
+ .mypy_cache/
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+ codex_prompt.md
14
+ implementation_plan.md
@@ -0,0 +1,7 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ rev: v0.8.6
4
+ hooks:
5
+ - id: ruff
6
+ args: [--fix]
7
+ - id: ruff-format
@@ -0,0 +1,74 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+
7
+ ## [3.1.0] - 2026-06-01
8
+
9
+ ### Added
10
+ - Dynamic, unified configuration and service reloading across HTTP and TUI (`reload_config_internal`).
11
+ - Instant, non-blocking Unix/macOS keyboard input using `termios`/`tty` cbreak mode.
12
+
13
+ ## [2.0.1] - 2026-05-31
14
+
15
+ ### Fixed
16
+
17
+ - **Compaction config threading**: `max_messages` and `keep_last` from config.toml
18
+ are now correctly passed to the compaction engine (were previously hardcoded)
19
+ - **Circuit breaker type annotation**: `AppState.circuit_breaker` now correctly
20
+ typed as `CircuitBreaker | None`
21
+ - **Circuit breaker coverage**: Now protects streaming HTTP and WebSocket paths
22
+ (was only protecting non-streaming HTTP)
23
+ - **Config reload**: `/reload` now recreates circuit breaker with new config values
24
+ - **Example config**: `codex-proxy --init` now generates `[circuit_breaker]` and
25
+ `[compaction]` sections
26
+
27
+ ### Added
28
+
29
+ - `--print-config` now shows circuit_breaker and compaction settings
30
+ - MIT `LICENSE` file
31
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
32
+
33
+ ## [2.0.0] - 2026-05-31
34
+
35
+ ### Added
36
+
37
+ - **6 new provider adapters** for broader LLM ecosystem support:
38
+ - Anthropic — `x-api-key` header and `anthropic-version` handling
39
+ - Gemini — Google's OpenAI-compatible endpoint
40
+ - DeepSeek — stream_options stripping
41
+ - Mistral — OpenAI-compatible with stream_options handling
42
+ - Cohere — OpenAI-compatible endpoint
43
+ - NVIDIA — NIM OpenAI-compatible endpoint
44
+ - **Circuit breaker** for upstream resilience — protects against failing providers
45
+ with configurable failure threshold, recovery timeout, and half-open state
46
+ - **Context compaction** for long conversations — automatically trims message
47
+ history to fit within limits while preserving system prompts and recent context
48
+ - **CI/CD pipeline** (GitHub Actions) — automated lint, test, and release workflows
49
+ - **Docker Compose** support — one-command containerized deployment with health checks
50
+ - **Pre-commit hooks** — Ruff linting and formatting on every commit
51
+ - **112+ tests** covering translator, config, store, server, providers, circuit
52
+ breaker, and compaction modules
53
+ - **CONTRIBUTING.md** — development setup, code style, PR process, and commit conventions
54
+ - **CODE_OF_CONDUCT.md** — community guidelines
55
+ - **Issue templates** and **PR template** for structured contributions
56
+
57
+ ## [1.0.0] - 2026-05-19
58
+
59
+ ### Added
60
+
61
+ - Core **Responses API to Chat Completions** protocol translation
62
+ - **Streaming SSE** support with real-time token delivery
63
+ - **WebSocket** support with full Realtime API envelope handling
64
+ - **Reasoning/thinking token** passthrough from supported models
65
+ - **Tool calls** — full function calling support (definitions + results)
66
+ - **Multi-turn conversations** via `previous_response_id` with in-memory response store
67
+ - **Multi-provider** backend — switch between Z.AI, Groq, Together AI, OpenRouter,
68
+ Ollama, Fireworks, and more with a single config change
69
+ - **Usage tracking** — captures token counts from streaming responses
70
+ - **Auto-retry** — one retry on 5xx/transport errors for non-streaming requests
71
+ - **TOML configuration** file with env var and CLI flag overrides
72
+ - **FastAPI** server with `/responses`, `/models`, `/health`, `/status`, and `/reload` endpoints
73
+ - **Dockerfile** for containerized deployment
74
+ - **CLI** with `--init`, `--print-config`, `--port`, `--host`, and `--config` options
@@ -0,0 +1,33 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone.
7
+
8
+ ## Our Standards
9
+
10
+ Examples of behavior that contributes to a positive environment:
11
+
12
+ * Being respectful of differing viewpoints
13
+ * Giving and gracefully accepting constructive feedback
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior:
18
+
19
+ * Harassment, insulting comments, or personal attacks
20
+ * Publishing others' private information without permission
21
+ * Other conduct which could reasonably be considered inappropriate
22
+
23
+ ## Enforcement
24
+
25
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
26
+ reported by contacting the project team at zakarinoo@gmail.com.
27
+
28
+ ## Attribution
29
+
30
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
31
+ version 2.1.
32
+
33
+ [homepage]: https://www.contributor-covenant.org
@@ -0,0 +1,127 @@
1
+ # Contributing to codex-proxy
2
+
3
+ Thanks for your interest in contributing! This guide covers everything you need to get started.
4
+
5
+ ## Development Setup
6
+
7
+ 1. **Fork** the repository on GitHub
8
+ 2. **Clone** your fork locally:
9
+ ```bash
10
+ git clone https://github.com/YOUR_USERNAME/codex-proxy.git
11
+ cd codex-proxy
12
+ ```
13
+ 3. **Install** in editable mode with dev dependencies:
14
+ ```bash
15
+ pip install -e ".[dev]"
16
+ ```
17
+ 4. **Install pre-commit hooks** (optional but recommended):
18
+ ```bash
19
+ pre-commit install
20
+ ```
21
+
22
+ ## Code Style
23
+
24
+ - **Formatter & Linter**: [Ruff](https://docs.astral.sh/ruff/) — configuration lives in `pyproject.toml`
25
+ - **Target**: Python 3.10+
26
+ - **Line length**: 100 characters (E501 is ignored)
27
+ - **Type hints**: Encouraged on public APIs; `mypy` is available for checking
28
+ - **Data structures**: Use `@dataclass` for structured data (see `circuit_breaker.py` for reference)
29
+ - **Imports**: Sorted with isort via Ruff; first-party imports use `codex_proxy`
30
+
31
+ ### Running the linter
32
+
33
+ ```bash
34
+ ruff check src/ tests/
35
+ ruff format src/ tests/
36
+ ```
37
+
38
+ ### Type checking
39
+
40
+ ```bash
41
+ mypy src/
42
+ ```
43
+
44
+ ## Running Tests
45
+
46
+ ```bash
47
+ # Run full suite
48
+ pytest tests/ -v
49
+
50
+ # Run a specific test file
51
+ pytest tests/test_translator.py -v
52
+
53
+ # Run with coverage
54
+ pytest tests/ -v --tb=short
55
+ ```
56
+
57
+ The test suite uses **pytest** with 112+ tests covering the translator, config, store, server, providers, circuit breaker, and compaction modules.
58
+
59
+ ## Project Structure
60
+
61
+ ```
62
+ codex-proxy/
63
+ src/codex_proxy/ # Main package
64
+ __init__.py # Package init
65
+ __main__.py # CLI entry point
66
+ server.py # FastAPI app + endpoints
67
+ translator.py # Responses API <-> Chat Completions
68
+ config.py # TOML config loading
69
+ store.py # In-memory response store
70
+ providers.py # Provider-specific adapters
71
+ circuit_breaker.py # Upstream resilience
72
+ compaction.py # Context compaction
73
+ tests/ # Test suite
74
+ .github/workflows/ # CI/CD pipelines
75
+ ```
76
+
77
+ ## Pull Request Process
78
+
79
+ 1. **Create a branch** from `main`:
80
+ ```bash
81
+ git checkout -b feat/your-feature-name
82
+ ```
83
+ 2. **Make your changes** and add tests for new functionality
84
+ 3. **Run checks** before pushing:
85
+ ```bash
86
+ ruff check src/ tests/
87
+ pytest tests/ -v
88
+ ```
89
+ 4. **Push** to your fork:
90
+ ```bash
91
+ git push origin feat/your-feature-name
92
+ ```
93
+ 5. **Open a Pull Request** against the `main` branch
94
+
95
+ ### PR Guidelines
96
+
97
+ - Keep PRs focused — one feature or fix per PR
98
+ - Add tests for any new behavior
99
+ - Update `README.md` if you change user-facing functionality
100
+ - All CI checks must pass (lint + tests)
101
+
102
+ ## Commit Messages
103
+
104
+ Use [Conventional Commits](https://www.conventionalcommits.org/) style:
105
+
106
+ ```
107
+ feat: add streaming retry with exponential backoff
108
+ fix: correct WebSocket close frame handling
109
+ refactor: extract shared streaming core
110
+ test: add circuit breaker edge case tests
111
+ docs: update provider configuration examples
112
+ chore: bump ruff to v0.9
113
+ ```
114
+
115
+ **Format**: `type: short description`
116
+
117
+ Common types: `feat`, `fix`, `refactor`, `test`, `docs`, `chore`, `ci`, `perf`
118
+
119
+ ## Reporting Issues
120
+
121
+ - Use [GitHub Issues](https://github.com/ZakPro/codex-proxy/issues) for bugs and feature requests
122
+ - Include your Python version, OS, and relevant config (redact API keys)
123
+ - For bugs, provide steps to reproduce and any error output
124
+
125
+ ## License
126
+
127
+ By contributing, you agree that your contributions will be licensed under the [MIT License](LICENSE).
@@ -0,0 +1,9 @@
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY pyproject.toml .
4
+ COPY src/ src/
5
+ RUN pip install --no-cache-dir .
6
+ EXPOSE 4242
7
+ ENV CODEX_PROXY_API_KEY=""
8
+ ENV CODEX_PROXY_BASE_URL=""
9
+ CMD ["codex-proxy"]
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ZakPro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: codex-proxy
3
+ Version: 3.1.0
4
+ Summary: Responses API to Chat Completions bridge for OpenAI Codex CLI
5
+ Project-URL: Repository, https://github.com/ZiryaNoov/codex-proxy
6
+ Author-email: ZakPro <zakarinoo@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: chat-completions,codex,glm,openai,proxy,responses-api,z.ai
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Requires-Python: >=3.10
16
+ Requires-Dist: fastapi>=0.115
17
+ Requires-Dist: httpx>=0.27
18
+ Requires-Dist: tomli>=2.0; python_version < '3.11'
19
+ Requires-Dist: uvicorn>=0.30
20
+ Provides-Extra: dev
21
+ Requires-Dist: mypy>=1.13; extra == 'dev'
22
+ Requires-Dist: pytest>=8.0; extra == 'dev'
23
+ Requires-Dist: ruff>=0.8; extra == 'dev'
24
+ Provides-Extra: tui
25
+ Requires-Dist: rich>=13.0; extra == 'tui'