# Claude to ChatGPT | Converts the API of Anthropic's Claude model to the OpenAI Chat API format

**URL:** <https://onehack.st/t/claude-to-chatgpt-converts-the-api-of-anthropics-claude-model-to-the-openai-chat-api-format/290705>\
**Category:** Tools & Scripts\
**Tags:** freebies, ai\
**Created:** [September 5, 2024, 9:34pm UTC](https://onehack.st/t/claude-to-chatgpt-converts-the-api-of-anthropics-claude-model-to-the-openai-chat-api-format/290705 "2024-09-05T21:34:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prometheus](https://onehack.st/user_avatar/onehack.st/prometheus/32/34950_2.png) [@Prometheus](https://onehack.st/u/Prometheus)\
**Post date:** [September 5, 2024, 9:34pm UTC](https://onehack.st/t/claude-to-chatgpt-converts-the-api-of-anthropics-claude-model-to-the-openai-chat-api-format/290705/1 "2024-09-05T21:34:31Z")

</div>

# Claude to ChatGPT

[![release](https://github.com/jtsang4/claude-to-chatgpt/actions/workflows/docker.yaml/badge.svg) ](https://github.com/jtsang4/claude-to-chatgpt/releases)[![GitHub Repo stars](https://camo.githubusercontent.com/58eff78203429183cd439ab26e314122dac8aa5a1e423368cdbef326c03c339a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a7473616e67342f636c617564652d746f2d636861746770743f7374796c653d666c6174) ](https://github.com/jtsang4/claude-to-chatgpt/releases)[![GitHub Repo Badge](https://camo.githubusercontent.com/cc90716164896443b6645bc5bf8a7abdcaa52046ccbda7736b899225e7e90e9d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616e7468726f7069632d636c617564652d6f72616e67653f7374796c653d666c6174) ](https://github.com/jtsang4/claude-to-chatgpt/releases)[![GitHub Repo Language](https://camo.githubusercontent.com/4819ec2b20d4098099ae7a96048be1f39de8f3dfa512048339fc0071f853d183/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c616e6775726167652d6a732f70792d627269676874677265656e3f7374796c653d666c617426636f6c6f723d626c7565)](https://github.com/jtsang4/claude-to-chatgpt/releases)

This project converts the API of Anthropic’s Claude model to the OpenAI Chat API format.

- ✨ Call Claude API like OpenAI ChatGPT API
- 💦 Support streaming response
- 🐻 Support `claude-instant-1`, `claude-2` models
- 🌩 Deploy by Cloudflare Workers or Docker

## Getting Started

You can run this project using Cloudflare Workers or Docker:

### Deployment

#### Using Cloudflare Workers

By using Cloudflare Workers, you don’t need a server to deploy this project.

1. Create a Cloudflare Worker
2. Paste the code in [`cloudflare-worker.js`](https://github.com/jtsang4/claude-to-chatgpt/blob/main/cloudflare-worker.js) to Cloudflare Worker “Quick Edit” Editor
3. Save and deploy
4. (Optional) Set custom domain for your Cloudflare Worker

The Cloudfalre Workers support 100k requests a day, If you need to call more than that, you can use Docker to deploy as below.

#### Using Docker

docker run -p 8000:8000 wtzeng/claude-to-chatgpt:latest

#### Using Docker Compose

docker-compose up

The API will then be available at [http://localhost:8000](http://localhost:8000/). API endpoint: `/v1/chat/completions`

### Usage

When you input the model parameter as `gpt-3.5-turbo` or `gpt-3.5-turbo-0613`, it will be substituted with `claude-instant-1`. otherwise, `claude-2` will be utilized.

#### GUI

Here are some recommended GUI software that supports this project:

- [Bin-Huang/chatbox](https://github.com/Bin-Huang/chatbox)
- [Yidadaa/ChatGPT-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web)

#### CLI

curl [http://localhost:8000/v1/chat/completions](http://localhost:8000/v1/chat/completions) \ -H “Content-Type: application/json” \ -H “Authorization: Bearer $CLAUDE\_API\_KEY” \ -d ‘{ “model”: “gpt-3.5-turbo”, “messages”: [{“role”: “user”, “content”: “Hello!”}] }’

## Conversion Details

The Claude Completion API has an endpoint `/v1/complete` which takes the following JSON request:

{ “prompt”: "\n\nHuman: Hello, AI.\n\nAssistant: ", “model”: “claude-instant-1”, “max\_tokens\_to\_sample”: 100, “temperature”: 1, “stream”: true }

And returns JSON with choices and completions.

The OpenAI Chat API has a similar `/v1/chat/completions` endpoint which takes:

{ “model”: “gpt-3.5-turbo”, “messages”: [{ “role”: “user”, “content”: “Hello, AI.” }], “max\_tokens”: 100, “temperature”: 1, “stream”: true }

And returns JSON with a response string.

This project converts between these two APIs, get completions from the Claude model and formatting them as OpenAI Chat responses.

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## GitHub:

[https://github.com/jtsang4/claude-to-chatgpt](https://github.com/jtsang4/claude-to-chatgpt)

---

<div class="post-metadata">

**Author:** ![Bob.Smit](https://onehack.st/user_avatar/onehack.st/bob.smit/32/161700_2.png) [@Bob.Smit](https://onehack.st/u/Bob.Smit)\
**Post date:** [September 8, 2024, 10:25pm UTC](https://onehack.st/t/claude-to-chatgpt-converts-the-api-of-anthropics-claude-model-to-the-openai-chat-api-format/290705/2 "2024-09-08T22:25:17Z")

</div>

Another great program. Thanks
