Skip to content

Installation

OpenAI Mock API can be used in several ways depending on your needs.

The fastest way to get started - no installation required:

Terminal window
npx openai-mock-api --config config.yaml

This downloads and runs the latest version directly. Perfect for:

  • Quick testing and prototyping
  • CI/CD environments
  • One-off usage

Install globally to use the openai-mock-api command anywhere:

Terminal window
npm install -g openai-mock-api
openai-mock-api --config config.yaml

Add to your project as a development dependency:

Terminal window
# npm
npm install --save-dev openai-mock-api
# yarn
yarn add --dev openai-mock-api
# pnpm
pnpm add --save-dev openai-mock-api

Then use via npm scripts in package.json:

{
"scripts": {
"mock-api": "openai-mock-api --config test-config.yaml",
"test:integration": "openai-mock-api --config test-config.yaml & npm run test && pkill -f openai-mock-api"
}
}

Create a Dockerfile for containerized usage:

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install -g openai-mock-api
COPY config.yaml ./
EXPOSE 3000
CMD ["openai-mock-api", "--config", "config.yaml"]

Or use with docker-compose:

docker-compose.yml
version: '3.8'
services:
openai-mock:
image: node:18-alpine
command: sh -c "npm install -g openai-mock-api && openai-mock-api --config /config/config.yaml"
ports:
- '3000:3000'
volumes:
- ./config.yaml:/config/config.yaml
  • Node.js: Version 16.0.0 or higher
  • npm/yarn/pnpm: Any modern package manager

Verify your installation:

Terminal window
# Check version
openai-mock-api --version
# View help
openai-mock-api --help

If you want to contribute or modify the source:

Terminal window
# Clone the repository
git clone https://github.com/patrickjm/openai-mock-api.git
cd openai-mock-api
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Start in development mode
npm run dev -- --config example-config.yaml

If you get “command not found” after global installation:

  • Ensure npm’s global bin directory is in your PATH
  • Try npm list -g openai-mock-api to verify installation

On Unix systems, you might need sudo for global installation:

Terminal window
sudo npm install -g openai-mock-api

Or use a Node version manager like nvm to avoid permission issues.

If port 3000 is busy:

Terminal window
openai-mock-api --config config.yaml --port 3001

Or specify port in your config file:

port: 3001
# ... rest of config