npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

claude2openai

v1.0.5

Published

A proxy service to convert between Claude and OpenAI API formats

Readme

Claude to OpenAI API Adapter

A TypeScript-based proxy service that converts Claude API requests to OpenAI API format and vice versa. This allows applications built for the Claude API to work with OpenAI models, and potentially other LLM APIs in the future.

Features

  • Convert Claude API requests to OpenAI API format
  • Convert OpenAI API responses back to Claude format
  • Support for both Claude Completions API and Claude Messages API
  • Support for both streaming and non-streaming completions
  • Optional support for function calls/tools (configurable)
  • Customizable OpenAI API URL, API key, and model
  • Extensible architecture for adding support for other API formats (e.g., Gemini)
  • Configurable via environment variables

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/claude2openai.git
cd claude2openai
  1. Install dependencies:
npm install
  1. Build the project:
npm run build

Configuration

The service can be configured using environment variables:

  • PORT: The port to run the server on (default: 3000)
  • OPENAI_API_KEY: Your OpenAI API key
  • CLAUDE_API_KEY: Your Claude API key (for future use)
  • OPENAI_API_URL: The OpenAI API URL (default: https://api.openai.com/v1)
  • CLAUDE_API_URL: The Claude API URL (default: https://api.anthropic.com/v1)
  • OPENAI_MODEL: The OpenAI model to use (default: gpt-4-turbo)
  • ENABLE_TOOLS: Enable function calls/tools support (default: false)
  • LOG_LEVEL: The log level (default: info)

Create a .env file in the root directory with your configuration:

PORT=3000
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_API_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4-turbo
ENABLE_TOOLS=false
LOG_LEVEL=info

Usage

  1. Start the server in development mode:
npm run dev

Or in production mode:

npm start
  1. Install claude code
npm install -g @anthropic-ai/claude-code

export ANTHROPIC_AUTH_TOKEN=sk-litellm-static-key
export ANTHROPIC_BASE_URL=http://127.0.0.1:3000
claude
  1. Send Claude API requests to the proxy:

Using Claude Completions API

curl -X POST http://localhost:3000/v1/complete \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-opus-20240229",
    "max_tokens_to_sample": 1000,
    "temperature": 0.7,
    "messages": [
      {
        "role": "user",
        "content": "Hello, Claude!"
      }
    ]
  }'

Using Claude Messages API

curl -X POST http://localhost:3000/v1/messages \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-3-opus-20240229",
    "max_tokens": 1000,
    "temperature": 0.7,
    "messages": [
      {
        "role": "user",
        "content": "Hello, Claude!"
      }
    ]
  }'

The proxy will convert the Claude request to OpenAI format, send it to the OpenAI API, and return the response in Claude format.

API Endpoints

  • POST /v1/complete: Handle Claude Completions API requests
  • POST /v1/complete_stream: Handle Claude Completions API streaming requests
  • POST /v1/messages: Handle Claude Messages API requests (supports both streaming and non-streaming)
  • GET /health: Health check endpoint

Project Structure

src/
├── adapters/           # API format adapters
│   ├── base.adapter.ts         # Base adapter class
│   ├── claude-to-openai.adapter.ts  # Claude to OpenAI adapter
│   └── adapter-registry.ts     # Registry for managing adapters
├── config/             # Configuration
│   └── config.ts              # Application configuration
├── routes/             # API routes
│   └── claude-to-openai.route.ts  # Claude to OpenAI route
├── types/              # Type definitions
│   └── index.ts               # API type definitions
├── utils/              # Utility functions
│   ├── http-client.ts         # HTTP client for API requests
│   └── logger.ts              # Logger utility
└── index.ts            # Main application entry point

Model Mapping

By default, the adapter will use the model specified in the OPENAI_MODEL environment variable. If not specified, it will map Claude models to OpenAI models as follows:

  • claude-3-opus-20240229gpt-4-turbo
  • claude-3-sonnet-20240229gpt-4
  • claude-3-haiku-20240307gpt-3.5-turbo
  • claude-2.1gpt-4
  • claude-2.0gpt-4
  • claude-instant-1.2gpt-3.5-turbo

Custom OpenAI API Endpoints

You can configure the adapter to use a custom OpenAI API endpoint by setting the OPENAI_API_URL environment variable. This is useful if you want to use a self-hosted OpenAI-compatible API or a different provider that supports the OpenAI API format.

Example:

OPENAI_API_URL=http://localhost:8000/v1

Function Calls / Tools Support

The adapter includes optional support for Claude's tools feature (equivalent to OpenAI's function calls). This feature is disabled by default due to potential compatibility issues with some OpenAI-compatible backends.

To enable tools support:

  1. Set the ENABLE_TOOLS environment variable to true
  2. Send Claude API requests with the tools parameter

Example request with tools:

curl -X POST http://localhost:3000/v1/messages \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-3-opus-20240229",
    "max_tokens": 1000,
    "temperature": 0.7,
    "messages": [
      {
        "role": "user",
        "content": "What is the weather in San Francisco?"
      }
    ],
    "tools": [
      {
        "name": "get_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            },
            "unit": {
              "type": "string",
              "enum": ["celsius", "fahrenheit"],
              "description": "The temperature unit to use"
            }
          },
          "required": ["location"]
        }
      }
    ]
  }'

Future Enhancements

  • Add support for Gemini API
  • Add authentication and rate limiting
  • Add support for more Claude API features
  • Add tests

License

ISC