Installation
Installation
Section titled “Installation”OpenAI Mock API can be used in several ways depending on your needs.
NPX (Recommended)
Section titled “NPX (Recommended)”The fastest way to get started - no installation required:
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
Global Installation
Section titled “Global Installation”Install globally to use the openai-mock-api
command anywhere:
npm install -g openai-mock-apiopenai-mock-api --config config.yaml
Local Installation
Section titled “Local Installation”Add to your project as a development dependency:
# npmnpm install --save-dev openai-mock-api
# yarnyarn add --dev openai-mock-api
# pnpmpnpm 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" }}
Docker Usage
Section titled “Docker Usage”Create a Dockerfile for containerized usage:
FROM node:18-alpineWORKDIR /appCOPY package*.json ./RUN npm install -g openai-mock-apiCOPY config.yaml ./EXPOSE 3000CMD ["openai-mock-api", "--config", "config.yaml"]
Or use with docker-compose:
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
Requirements
Section titled “Requirements”- Node.js: Version 16.0.0 or higher
- npm/yarn/pnpm: Any modern package manager
Verification
Section titled “Verification”Verify your installation:
# Check versionopenai-mock-api --version
# View helpopenai-mock-api --help
Development Setup
Section titled “Development Setup”If you want to contribute or modify the source:
# Clone the repositorygit clone https://github.com/patrickjm/openai-mock-api.gitcd openai-mock-api
# Install dependenciesnpm install
# Build the projectnpm run build
# Run testsnpm test
# Start in development modenpm run dev -- --config example-config.yaml
Troubleshooting
Section titled “Troubleshooting”Command Not Found
Section titled “Command Not Found”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
Permission Issues
Section titled “Permission Issues”On Unix systems, you might need sudo for global installation:
sudo npm install -g openai-mock-api
Or use a Node version manager like nvm to avoid permission issues.
Port Already in Use
Section titled “Port Already in Use”If port 3000 is busy:
openai-mock-api --config config.yaml --port 3001
Or specify port in your config file:
port: 3001# ... rest of config