claude2openai

command module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2025 License: MIT Imports: 14 Imported by: 0

README

Claude2OpenAI

Used to convert the Claude API to OpenAI compatible API. Easily use Claude with any OpenAI compatible client.

Compatibility

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.

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:

# Example: Setting custom allowed models
export ALLOWED_MODELS="claude-3-5-haiku-20241022,claude-3-5-sonnet-20241022,claude-3-haiku-20240307"

The first model in the list will be used as the default model.

Request Example

curl http://127.0.0.1:6600/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-ant-xxxxxxxxxxxxxxxx" \
  -d '{
    "model": "claude-3-5-haiku-20241022",
    "messages": [
      {
        "role": "system",
        "content": "翻译为中文!"
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ],
    "stream": true
  }'

Features

Image Support

Claude2OpenAI supports images in the same format as OpenAI. You can include images in your messages using either base64-encoded images or URLs.

curl http://127.0.0.1:6600/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-ant-xxxxxxxxxxxxxxxx" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What's in this image?"
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://example.com/image.jpg"
            }
          }
        ]
      }
    ]
  }'
Debug Mode

You can enable debug mode to help troubleshoot issues:

  1. Using an environment variable:
DEBUG=true ./claude2openai
  1. Using the command-line flag:
./claude2openai -debug

In debug mode, detailed information about requests and responses will be logged to help with troubleshooting.

Usage

Homebrew (MacOS)

Special thanks to Sma1lboy for his contribution.

brew tap owo-network/brew
brew install claude2openai
Docker
docker run -d --restart always -p 6600:6600 ghcr.io/missuo/claude2openai:latest
docker run -d --restart always -p 6600:6600 missuo/claude2openai:latest

To set custom allowed models with Docker:

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
Docker Compose

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.

+version: "3.9"
mkdir claude2openai && cd claude2openai
wget -O compose.yaml https://raw.githubusercontent.com/missuo/claude2openai/main/compose.yaml
docker compose up -d
Manual

Download the latest release from the release page.

chmod +x claude2openai
./claude2openai

License

MIT

Documentation

Overview

* @Author: Vincent Yang * @Date: 2024-03-29 23:11:29 * @LastEditors: Vincent Yang * @LastEditTime: 2024-03-30 00:00:44 * @FilePath: /claude2openai/types.go * @Telegram: https://t.me/missuo * @GitHub: https://github.com/missuo * * Copyright © 2024 by Vincent, All Rights Reserved.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL