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

openai-to-azure-openai-cli

v1.0.0

Published

CLI tool to convert OpenAI code (curl, Python, JavaScript/TypeScript) to Azure OpenAI compatible code

Readme

OpenAI to Azure OpenAI Converter CLI

A command-line tool that converts OpenAI code (curl, Python, JavaScript/TypeScript, LangChain) to Azure OpenAI compatible code.

Installation

# Install globally from npm
npm install -g openai-to-azure-openai-cli

# Or use directly with npx
npx openai-to-azure-openai-cli --help

From Source

# Clone the repository
git clone https://github.com/davidhou17/openai-to-azure-openai-cli.git
cd openai-to-azure-openai-cli

# Install dependencies
npm install

# Build the project
npm run build

# Link globally (optional)
npm link

Usage

Basic Usage

# From stdin
echo 'your code here' | openai-to-azure

# From file
openai-to-azure -f input.py

# From string argument
openai-to-azure 'curl https://api.openai.com/v1/chat/completions ...'

Options

Usage: openai-to-azure [options] [input]

Arguments:
  input                    Input code string or file path

Options:
  -V, --version            output the version number
  -f, --file <path>        Read input from a file
  -l, --language <lang>    Specify the language (curl, python, javascript, typescript, langchain)
  --no-comments            Disable adding environment variable comments to output
  -o, --output <path>      Write output to a file (default: stdout)
  -q, --quiet              Suppress warnings and info messages
  -h, --help               display help for command

Commands:
  detect [options] [input] Detect the language of the input code

Required Environment Variables

After conversion, your Azure OpenAI code will use these environment variables:

| Variable | Description | |----------|-------------| | AZURE_OPENAI_ENDPOINT | Your Azure OpenAI endpoint (e.g., https://your-resource.openai.azure.com) | | AZURE_OPENAI_API_KEY | Your Azure OpenAI API key | | OPENAI_API_VERSION | API version (e.g., 2024-02-15-preview) | | AZURE_OPENAI_DEPLOYMENT | Your deployment name |

Examples

cURL Conversion

Input:

curl https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello!"}]}'

Output:

curl ${AZURE_OPENAI_ENDPOINT}/openai/deployments/${AZURE_OPENAI_DEPLOYMENT}/chat/completions?api-version=${OPENAI_API_VERSION:-2024-02-15-preview} \
  -H "api-key: $AZURE_OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello!"}]}'

Python Conversion

Input:

from openai import OpenAI

client = OpenAI(api_key="sk-xxx")
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

Output:

from openai import AzureOpenAI
import os

client = AzureOpenAI(
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),
    api_version=os.getenv("OPENAI_API_VERSION", "2024-02-15-preview")
)
response = client.chat.completions.create(
    model=os.getenv("AZURE_OPENAI_DEPLOYMENT"),
    messages=[{"role": "user", "content": "Hello!"}]
)

JavaScript/TypeScript Conversion

Input:

import OpenAI from 'openai';

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const response = await client.chat.completions.create({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Hello!' }],
});

Output:

import { AzureOpenAI } from 'openai';

const client = new AzureOpenAI({
  apiKey: process.env.AZURE_OPENAI_API_KEY,
  endpoint: process.env.AZURE_OPENAI_ENDPOINT,
  apiVersion: process.env.OPENAI_API_VERSION || '2024-02-15-preview',
});
const response = await client.chat.completions.create({
  model: process.env.AZURE_OPENAI_DEPLOYMENT,
  messages: [{ role: 'user', content: 'Hello!' }],
});

LangChain Conversion

Input:

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gpt-4",
    temperature=0,
    max_tokens=None,
)

messages = [("system", "You are a helpful assistant."), ("human", "Hello!")]
response = llm.invoke(messages)

Output:

import os
from langchain_openai import AzureChatOpenAI

llm = AzureChatOpenAI(
    azure_deployment=os.getenv("AZURE_OPENAI_DEPLOYMENT"),
    api_version=os.getenv("OPENAI_API_VERSION", "2024-02-15-preview"),
)

messages = [("system", "You are a helpful assistant."), ("human", "Hello!")]
response = llm.invoke(messages)

Supported Conversions

OpenAI SDK

  • Python: OpenAIAzureOpenAI
  • JavaScript/TypeScript: OpenAIAzureOpenAI

LangChain

  • Python: ChatOpenAIAzureChatOpenAI

curl Endpoints

  • /v1/chat/completions → Chat completions
  • /v1/completions → Text completions
  • /v1/embeddings → Embeddings
  • /v1/images/generations → Image generation (DALL-E)
  • /v1/audio/transcriptions → Audio transcription (Whisper)
  • /v1/audio/translations → Audio translation (Whisper)

Development

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

Building

npm run build

License

MIT