local-openai2anthropic 0.2.9__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.
- local_openai2anthropic-0.2.9/.github/workflows/publish.yml +38 -0
- local_openai2anthropic-0.2.9/.gitignore +63 -0
- local_openai2anthropic-0.2.9/LICENSE +201 -0
- local_openai2anthropic-0.2.9/PKG-INFO +373 -0
- local_openai2anthropic-0.2.9/README.md +338 -0
- local_openai2anthropic-0.2.9/README_zh.md +338 -0
- local_openai2anthropic-0.2.9/examples/basic_chat.py +55 -0
- local_openai2anthropic-0.2.9/examples/streaming.py +49 -0
- local_openai2anthropic-0.2.9/examples/thinking_mode.py +85 -0
- local_openai2anthropic-0.2.9/examples/tool_calling.py +99 -0
- local_openai2anthropic-0.2.9/examples/vision.py +72 -0
- local_openai2anthropic-0.2.9/examples/web_search.py +57 -0
- local_openai2anthropic-0.2.9/pyproject.toml +69 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/__init__.py +51 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/__main__.py +7 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/config.py +68 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/converter.py +463 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/daemon.py +382 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/daemon_runner.py +116 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/main.py +316 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/openai_types.py +149 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/protocol.py +213 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/router.py +1036 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/server_tools/__init__.py +24 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/server_tools/base.py +193 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/server_tools/web_search.py +209 -0
- local_openai2anthropic-0.2.9/src/local_openai2anthropic/tavily_client.py +116 -0
- local_openai2anthropic-0.2.9/tests/__init__.py +1 -0
- local_openai2anthropic-0.2.9/tests/test_converter.py +308 -0
- local_openai2anthropic-0.2.9/tests/test_integration.py +360 -0
- local_openai2anthropic-0.2.9/tests/test_router.py +171 -0
- local_openai2anthropic-0.2.9/tests/test_upstream.sh +79 -0
- local_openai2anthropic-0.2.9/uv.lock +963 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build-and-publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout code
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: '3.12'
|
|
23
|
+
|
|
24
|
+
- name: Install build dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install build twine
|
|
28
|
+
|
|
29
|
+
- name: Build package
|
|
30
|
+
run: python -m build
|
|
31
|
+
|
|
32
|
+
- name: Check package
|
|
33
|
+
run: twine check dist/*
|
|
34
|
+
|
|
35
|
+
- name: Publish to PyPI
|
|
36
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
37
|
+
with:
|
|
38
|
+
skip-existing: true
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
share/python-wheels/
|
|
20
|
+
*.egg-info/
|
|
21
|
+
.installed.cfg
|
|
22
|
+
*.egg
|
|
23
|
+
MANIFEST
|
|
24
|
+
|
|
25
|
+
# Virtual environments
|
|
26
|
+
.env
|
|
27
|
+
.venv
|
|
28
|
+
env/
|
|
29
|
+
venv/
|
|
30
|
+
ENV/
|
|
31
|
+
env.bak/
|
|
32
|
+
venv.bak/
|
|
33
|
+
|
|
34
|
+
# IDE
|
|
35
|
+
.idea/
|
|
36
|
+
.vscode/
|
|
37
|
+
*.swp
|
|
38
|
+
*.swo
|
|
39
|
+
*~
|
|
40
|
+
|
|
41
|
+
# Testing
|
|
42
|
+
.pytest_cache/
|
|
43
|
+
.coverage
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
|
|
48
|
+
# Distribution
|
|
49
|
+
*.tar.gz
|
|
50
|
+
*.whl
|
|
51
|
+
|
|
52
|
+
# Logs
|
|
53
|
+
*.log
|
|
54
|
+
logs/
|
|
55
|
+
|
|
56
|
+
# OS
|
|
57
|
+
.DS_Store
|
|
58
|
+
Thumbs.db
|
|
59
|
+
|
|
60
|
+
# Local development
|
|
61
|
+
.env.local
|
|
62
|
+
.env.*.local
|
|
63
|
+
.env*
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 local-openai2anthropic contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: local-openai2anthropic
|
|
3
|
+
Version: 0.2.9
|
|
4
|
+
Summary: A lightweight proxy server that converts Anthropic Messages API to OpenAI API
|
|
5
|
+
Project-URL: Homepage, https://github.com/dongfangzan/local-openai2anthropic
|
|
6
|
+
Project-URL: Repository, https://github.com/dongfangzan/local-openai2anthropic
|
|
7
|
+
Project-URL: Issues, https://github.com/dongfangzan/local-openai2anthropic/issues
|
|
8
|
+
Author-email: dongfangzan <zsybook0124@163.com>
|
|
9
|
+
Maintainer-email: dongfangzan <zsybook0124@163.com>
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: anthropic,api,claude,messages,openai,proxy
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: anthropic>=0.30.0
|
|
22
|
+
Requires-Dist: fastapi>=0.100.0
|
|
23
|
+
Requires-Dist: httpx>=0.25.0
|
|
24
|
+
Requires-Dist: openai>=1.30.0
|
|
25
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
26
|
+
Requires-Dist: pydantic>=2.0.0
|
|
27
|
+
Requires-Dist: uvicorn[standard]>=0.23.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# local-openai2anthropic
|
|
37
|
+
|
|
38
|
+
[](https://www.python.org/downloads/)
|
|
39
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
40
|
+
[](https://pypi.org/project/local-openai2anthropic/)
|
|
41
|
+
|
|
42
|
+
**English | [中文](README_zh.md)**
|
|
43
|
+
|
|
44
|
+
A lightweight proxy that lets applications built with [Claude SDK](https://github.com/anthropics/anthropic-sdk-python) talk to locally-hosted OpenAI-compatible LLMs.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## What Problem This Solves
|
|
49
|
+
|
|
50
|
+
Many local LLM tools (vLLM, SGLang, etc.) provide an OpenAI-compatible API. But if you've built your app using Anthropic's Claude SDK, you can't use them directly.
|
|
51
|
+
|
|
52
|
+
This proxy translates Claude SDK calls to OpenAI API format in real-time, enabling:
|
|
53
|
+
|
|
54
|
+
- **Local LLM inference** with Claude-based apps
|
|
55
|
+
- **Offline development** without cloud API costs
|
|
56
|
+
- **Privacy-first AI** - data never leaves your machine
|
|
57
|
+
- **Seamless model switching** between cloud and local
|
|
58
|
+
- **Web Search tool** - built-in Tavily web search for local models
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Supported Local Backends
|
|
63
|
+
|
|
64
|
+
Currently tested and supported:
|
|
65
|
+
|
|
66
|
+
| Backend | Description | Status |
|
|
67
|
+
|---------|-------------|--------|
|
|
68
|
+
| [vLLM](https://github.com/vllm-project/vllm) | High-throughput LLM inference | ✅ Fully supported |
|
|
69
|
+
| [SGLang](https://github.com/sgl-project/sglang) | Fast structured language model serving | ✅ Fully supported |
|
|
70
|
+
|
|
71
|
+
Other OpenAI-compatible backends may work but are not fully tested.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Quick Start
|
|
76
|
+
|
|
77
|
+
### 1. Install
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install local-openai2anthropic
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 2. Configure Your LLM Backend (Optional)
|
|
84
|
+
|
|
85
|
+
**Option A: Start a local LLM server**
|
|
86
|
+
|
|
87
|
+
If you don't have an LLM server running, you can start one locally:
|
|
88
|
+
|
|
89
|
+
Example with vLLM:
|
|
90
|
+
```bash
|
|
91
|
+
vllm serve meta-llama/Llama-2-7b-chat-hf
|
|
92
|
+
# vLLM starts OpenAI-compatible API at http://localhost:8000/v1
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Or with SGLang:
|
|
96
|
+
```bash
|
|
97
|
+
sglang launch --model-path meta-llama/Llama-2-7b-chat-hf --port 8000
|
|
98
|
+
# SGLang starts at http://localhost:8000/v1
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Option B: Use an existing OpenAI-compatible API**
|
|
102
|
+
|
|
103
|
+
If you already have a deployed OpenAI-compatible API (local or remote), you can use it directly. Just note the base URL for the next step.
|
|
104
|
+
|
|
105
|
+
Examples:
|
|
106
|
+
- Local vLLM/SGLang: `http://localhost:8000/v1`
|
|
107
|
+
- Remote API: `https://api.example.com/v1`
|
|
108
|
+
|
|
109
|
+
> **Note:** If you're using [Ollama](https://ollama.com), it natively supports the Anthropic API format, so you don't need this proxy. Just point your Claude SDK directly to `http://localhost:11434/v1`.
|
|
110
|
+
|
|
111
|
+
### 3. Start the Proxy
|
|
112
|
+
|
|
113
|
+
**Option A: Run in background (recommended)**
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
export OA2A_OPENAI_BASE_URL=http://localhost:8000/v1 # Your local LLM endpoint
|
|
117
|
+
export OA2A_OPENAI_API_KEY=dummy # Any value, not used by local backends
|
|
118
|
+
|
|
119
|
+
oa2a start # Start server in background
|
|
120
|
+
# Server starts at http://localhost:8080
|
|
121
|
+
|
|
122
|
+
# View logs
|
|
123
|
+
oa2a logs # Show last 50 lines of logs
|
|
124
|
+
oa2a logs -f # Follow logs in real-time (Ctrl+C to exit)
|
|
125
|
+
|
|
126
|
+
# Check status
|
|
127
|
+
oa2a status # Check if server is running
|
|
128
|
+
|
|
129
|
+
# Stop server
|
|
130
|
+
oa2a stop # Stop background server
|
|
131
|
+
|
|
132
|
+
# Restart server
|
|
133
|
+
oa2a restart # Restart with same settings
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Option B: Run in foreground**
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
export OA2A_OPENAI_BASE_URL=http://localhost:8000/v1
|
|
140
|
+
export OA2A_OPENAI_API_KEY=dummy
|
|
141
|
+
|
|
142
|
+
oa2a # Run server in foreground (blocking)
|
|
143
|
+
# Press Ctrl+C to stop
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 4. Use in Your App
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
import anthropic
|
|
150
|
+
|
|
151
|
+
client = anthropic.Anthropic(
|
|
152
|
+
base_url="http://localhost:8080", # Point to proxy
|
|
153
|
+
api_key="dummy-key", # Not used
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
message = client.messages.create(
|
|
157
|
+
model="meta-llama/Llama-2-7b-chat-hf", # Your local model name
|
|
158
|
+
max_tokens=1024,
|
|
159
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
print(message.content[0].text)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Using with Claude Code
|
|
168
|
+
|
|
169
|
+
You can configure [Claude Code](https://github.com/anthropics/claude-code) to use your local LLM through this proxy.
|
|
170
|
+
|
|
171
|
+
### Configuration Steps
|
|
172
|
+
|
|
173
|
+
1. **Edit Claude Code config file** at `~/.claude/settings.json`:
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"env": {
|
|
178
|
+
"ANTHROPIC_BASE_URL": "http://localhost:8080",
|
|
179
|
+
"ANTHROPIC_API_KEY": "dummy-key",
|
|
180
|
+
"ANTHROPIC_MODEL": "meta-llama/Llama-2-7b-chat-hf",
|
|
181
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "meta-llama/Llama-2-7b-chat-hf",
|
|
182
|
+
"ANTHROPIC_DEFAULT_OPUS_MODEL": "meta-llama/Llama-2-7b-chat-hf",
|
|
183
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "meta-llama/Llama-2-7b-chat-hf",
|
|
184
|
+
"ANTHROPIC_REASONING_MODEL": "meta-llama/Llama-2-7b-chat-hf"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
| Variable | Description |
|
|
190
|
+
|----------|-------------|
|
|
191
|
+
| `ANTHROPIC_MODEL` | General model setting |
|
|
192
|
+
| `ANTHROPIC_DEFAULT_SONNET_MODEL` | Default model for Sonnet mode (Claude Code default) |
|
|
193
|
+
| `ANTHROPIC_DEFAULT_OPUS_MODEL` | Default model for Opus mode |
|
|
194
|
+
| `ANTHROPIC_DEFAULT_HAIKU_MODEL` | Default model for Haiku mode |
|
|
195
|
+
| `ANTHROPIC_REASONING_MODEL` | Default model for reasoning tasks |
|
|
196
|
+
|
|
197
|
+
2. **Or set environment variables** before running Claude Code:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
export ANTHROPIC_BASE_URL=http://localhost:8080
|
|
201
|
+
export ANTHROPIC_API_KEY=dummy-key
|
|
202
|
+
|
|
203
|
+
claude
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Complete Workflow Example
|
|
207
|
+
|
|
208
|
+
Make sure `~/.claude/settings.json` is configured as described above.
|
|
209
|
+
|
|
210
|
+
Terminal 1 - Start your local LLM:
|
|
211
|
+
```bash
|
|
212
|
+
vllm serve meta-llama/Llama-2-7b-chat-hf
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Terminal 2 - Start the proxy (background mode):
|
|
216
|
+
```bash
|
|
217
|
+
export OA2A_OPENAI_BASE_URL=http://localhost:8000/v1
|
|
218
|
+
export OA2A_OPENAI_API_KEY=dummy
|
|
219
|
+
export OA2A_TAVILY_API_KEY="tvly-your-tavily-api-key" # Optional: enable web search
|
|
220
|
+
|
|
221
|
+
oa2a start
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Terminal 3 - Launch Claude Code:
|
|
225
|
+
```bash
|
|
226
|
+
claude
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Now Claude Code will use your local LLM instead of the cloud API.
|
|
230
|
+
|
|
231
|
+
To stop the proxy:
|
|
232
|
+
```bash
|
|
233
|
+
oa2a stop
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Features
|
|
239
|
+
|
|
240
|
+
- ✅ **Streaming responses** - Real-time token streaming via SSE
|
|
241
|
+
- ✅ **Tool calling** - Local LLM function calling support
|
|
242
|
+
- ✅ **Vision models** - Multi-modal input for vision-capable models
|
|
243
|
+
- ✅ **Web Search** - Give your local LLM internet access (see below)
|
|
244
|
+
- ✅ **Thinking mode** - Supports reasoning/thinking model outputs
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Web Search Capability 🔍
|
|
249
|
+
|
|
250
|
+
**Bridge the gap: Give your local LLM the web search power that Claude Code users enjoy!**
|
|
251
|
+
|
|
252
|
+
When using locally-hosted models with Claude Code, you lose access to the built-in web search tool. This proxy fills that gap by providing a server-side web search implementation powered by [Tavily](https://tavily.com).
|
|
253
|
+
|
|
254
|
+
### The Problem
|
|
255
|
+
|
|
256
|
+
| Scenario | Web Search Available? |
|
|
257
|
+
|----------|----------------------|
|
|
258
|
+
| Using Claude (cloud) in Claude Code | ✅ Built-in |
|
|
259
|
+
| Using local vLLM/SGLang in Claude Code | ❌ Not available |
|
|
260
|
+
| **Using this proxy + local LLM** | ✅ **Enabled via Tavily** |
|
|
261
|
+
|
|
262
|
+
### How It Works
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
Claude Code → Anthropic SDK → This Proxy → Local LLM
|
|
266
|
+
↓
|
|
267
|
+
Tavily API (Web Search)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
The proxy intercepts `web_search_20250305` tool calls and handles them directly, regardless of whether your local model supports web search natively.
|
|
271
|
+
|
|
272
|
+
### Setup Tavily Search
|
|
273
|
+
|
|
274
|
+
1. **Get a free API key** at [tavily.com](https://tavily.com) - generous free tier available
|
|
275
|
+
|
|
276
|
+
2. **Configure the proxy:**
|
|
277
|
+
```bash
|
|
278
|
+
export OA2A_OPENAI_BASE_URL=http://localhost:8000/v1
|
|
279
|
+
export OA2A_OPENAI_API_KEY=dummy
|
|
280
|
+
export OA2A_TAVILY_API_KEY="tvly-your-tavily-api-key" # Enable web search
|
|
281
|
+
|
|
282
|
+
oa2a
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
3. **Use in your app:**
|
|
286
|
+
```python
|
|
287
|
+
import anthropic
|
|
288
|
+
|
|
289
|
+
client = anthropic.Anthropic(
|
|
290
|
+
base_url="http://localhost:8080",
|
|
291
|
+
api_key="dummy-key",
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
message = client.messages.create(
|
|
295
|
+
model="meta-llama/Llama-2-7b-chat-hf",
|
|
296
|
+
max_tokens=1024,
|
|
297
|
+
tools=[
|
|
298
|
+
{
|
|
299
|
+
"name": "web_search_20250305",
|
|
300
|
+
"description": "Search the web for current information",
|
|
301
|
+
"input_schema": {
|
|
302
|
+
"type": "object",
|
|
303
|
+
"properties": {
|
|
304
|
+
"query": {"type": "string", "description": "Search query"},
|
|
305
|
+
},
|
|
306
|
+
"required": ["query"],
|
|
307
|
+
},
|
|
308
|
+
}
|
|
309
|
+
],
|
|
310
|
+
messages=[{"role": "user", "content": "What happened in AI today?"}],
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
if message.stop_reason == "tool_use":
|
|
314
|
+
tool_use = message.content[-1]
|
|
315
|
+
print(f"Searching: {tool_use.input}")
|
|
316
|
+
# The proxy automatically calls Tavily and returns results
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Tavily Configuration Options
|
|
320
|
+
|
|
321
|
+
| Variable | Default | Description |
|
|
322
|
+
|----------|---------|-------------|
|
|
323
|
+
| `OA2A_TAVILY_API_KEY` | - | Your Tavily API key ([get free at tavily.com](https://tavily.com)) |
|
|
324
|
+
| `OA2A_TAVILY_MAX_RESULTS` | 5 | Number of search results to return |
|
|
325
|
+
| `OA2A_TAVILY_TIMEOUT` | 30 | Search timeout in seconds |
|
|
326
|
+
| `OA2A_WEBSEARCH_MAX_USES` | 5 | Max search calls per request |
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## Configuration
|
|
331
|
+
|
|
332
|
+
| Variable | Required | Default | Description |
|
|
333
|
+
|----------|----------|---------|-------------|
|
|
334
|
+
| `OA2A_OPENAI_BASE_URL` | ✅ | - | Your local LLM's OpenAI-compatible endpoint |
|
|
335
|
+
| `OA2A_OPENAI_API_KEY` | ✅ | - | Any value (local backends usually ignore this) |
|
|
336
|
+
| `OA2A_PORT` | ❌ | 8080 | Proxy server port |
|
|
337
|
+
| `OA2A_HOST` | ❌ | 0.0.0.0 | Proxy server host |
|
|
338
|
+
| `OA2A_TAVILY_API_KEY` | ❌ | - | Enable web search ([tavily.com](https://tavily.com)) |
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Architecture
|
|
343
|
+
|
|
344
|
+
```
|
|
345
|
+
Your App (Claude SDK)
|
|
346
|
+
│
|
|
347
|
+
▼
|
|
348
|
+
┌─────────────────────┐
|
|
349
|
+
│ local-openai2anthropic │ ← This proxy
|
|
350
|
+
│ (Port 8080) │
|
|
351
|
+
└─────────────────────┘
|
|
352
|
+
│
|
|
353
|
+
▼
|
|
354
|
+
Your Local LLM Server
|
|
355
|
+
(vLLM / SGLang)
|
|
356
|
+
(OpenAI-compatible API)
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Development
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
git clone https://github.com/dongfangzan/local-openai2anthropic.git
|
|
365
|
+
cd local-openai2anthropic
|
|
366
|
+
pip install -e ".[dev]"
|
|
367
|
+
|
|
368
|
+
pytest
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
Apache License 2.0
|