Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 6bc7e1f

Browse files
authored
Merge pull request #10 from dtinth/main
Add image support, allow setting a list of models, etc.
2 parents 66b245c + f5d3d0c commit 6bc7e1f

File tree

5 files changed

+391
-29
lines changed

5 files changed

+391
-29
lines changed

.github/workflows/docker.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434

3535
- name: Login to DockerHub
3636
uses: docker/login-action@v2
37+
if: env.DOCKER_USERNAME != ''
3738
with:
3839
registry: docker.io
3940
username: ${{ env.DOCKER_USERNAME }}
@@ -46,12 +47,21 @@ jobs:
4647
username: ${{ env.GHCR_USERNAME }}
4748
password: ${{ env.GHCR_TOKEN }}
4849

50+
- name: Set Docker Hub image flag
51+
id: dockerhub_image
52+
run: |
53+
if [ -n "${{ env.DOCKER_USERNAME }}" ]; then
54+
echo "enabled=true" >> $GITHUB_OUTPUT
55+
else
56+
echo "enabled=false" >> $GITHUB_OUTPUT
57+
fi
58+
4959
- name: Docker meta
5060
id: meta
5161
uses: docker/metadata-action@v4
5262
with:
5363
images: |
54-
docker.io/${{ env.DOCKER_IMAGE_NAME }}
64+
${{ steps.dockerhub_image.outputs.enabled == 'true' && format('docker.io/{0}', env.DOCKER_IMAGE_NAME) || '' }}
5565
ghcr.io/${{ env.GHCR_IMAGE_NAME }}
5666
tags: |
5767
type=ref,event=tag

CLAUDE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Claude2OpenAI Development Guide
2+
3+
## Build & Run Commands
4+
```bash
5+
# Build the application
6+
go build -o claude2openai .
7+
8+
# Run locally (default port: 6600)
9+
./claude2openai
10+
11+
# Run with custom port
12+
./claude2openai -p 8080
13+
14+
# Docker build
15+
docker build -t claude2openai .
16+
17+
# Docker run
18+
docker run -d --restart always -p 6600:6600 claude2openai
19+
```
20+
21+
## Code Style Guidelines
22+
- **Naming**: Use camelCase for functions and variables
23+
- **Error Handling**: Return JSON responses with descriptive error messages and appropriate HTTP status codes
24+
- **Comments**: Add comments for non-obvious code sections, consider bilingual (English/Chinese) for key components
25+
- **Imports**: Group standard library imports separate from external dependencies
26+
- **Formatting**: Maintain consistent struct definitions with appropriate JSON tags
27+
- **Types**: Follow Go idioms with proper type definitions in types.go
28+
- **Structure**: Maintain separation between OpenAI and Claude data structures
29+
30+
This project is a proxy service that converts Anthropic's Claude API to an OpenAI-compatible format.

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ Used to convert the Claude API to OpenAI compatible API. **Easily use Claude wit
44
## Compatibility
55
Currently it is only compatible with the Claude-3 family of models, if you pass in any other model, the default will be to use **claude-3-5-haiku-20241022**.
66

7+
You can customize the list of allowed models by setting the `ALLOWED_MODELS` environment variable with a comma-separated list of model names. This is useful when new Claude models are released, allowing you to add support without rebuilding:
8+
9+
```bash
10+
# Example: Setting custom allowed models
11+
export ALLOWED_MODELS="claude-3-5-haiku-20241022,claude-3-5-sonnet-20241022,claude-3-haiku-20240307"
12+
```
13+
14+
The first model in the list will be used as the default model.
15+
716
## Request Example
817
```bash
918
curl http://127.0.0.1:6600/v1/chat/completions \
@@ -25,6 +34,54 @@ curl http://127.0.0.1:6600/v1/chat/completions \
2534
}'
2635
```
2736

37+
## Features
38+
39+
### Image Support
40+
41+
Claude2OpenAI supports images in the same format as OpenAI. You can include images in your messages using either base64-encoded images or URLs.
42+
43+
```bash
44+
curl http://127.0.0.1:6600/v1/chat/completions \
45+
-H "Content-Type: application/json" \
46+
-H "Authorization: Bearer sk-ant-xxxxxxxxxxxxxxxx" \
47+
-d '{
48+
"model": "claude-3-5-sonnet-20241022",
49+
"messages": [
50+
{
51+
"role": "user",
52+
"content": [
53+
{
54+
"type": "text",
55+
"text": "What's in this image?"
56+
},
57+
{
58+
"type": "image_url",
59+
"image_url": {
60+
"url": "https://example.com/image.jpg"
61+
}
62+
}
63+
]
64+
}
65+
]
66+
}'
67+
```
68+
69+
### Debug Mode
70+
71+
You can enable debug mode to help troubleshoot issues:
72+
73+
1. Using an environment variable:
74+
```bash
75+
DEBUG=true ./claude2openai
76+
```
77+
78+
2. Using the command-line flag:
79+
```bash
80+
./claude2openai -debug
81+
```
82+
83+
In debug mode, detailed information about requests and responses will be logged to help with troubleshooting.
84+
2885
## Usage
2986
### Homebrew (MacOS)
3087
@@ -46,6 +103,12 @@ docker run -d --restart always -p 6600:6600 ghcr.io/missuo/claude2openai:latest
46103
docker run -d --restart always -p 6600:6600 missuo/claude2openai:latest
47104
```
48105
106+
To set custom allowed models with Docker:
107+
108+
```bash
109+
docker run -d --restart always -p 6600:6600 -e ALLOWED_MODELS="claude-3-5-haiku-20241022,claude-3-5-sonnet-20241022" ghcr.io/missuo/claude2openai:latest
110+
```
111+
49112
### Docker Compose
50113
It is recommended that you use docker version **26.0.0** or higher, otherwise you need to specify the version in the `compose.yaml` file.
51114
```diff

0 commit comments

Comments
 (0)