CLI Options
CLI Options
Section titled “CLI Options”Complete reference for the openai-mock-api
command-line interface.
Synopsis
Section titled “Synopsis”openai-mock-api [options]
Configuration Options
Section titled “Configuration Options”-c, --config <path>
Section titled “-c, --config <path>”Path to the YAML configuration file. Use -
to read from stdin.
# From fileopenai-mock-api --config config.yamlopenai-mock-api -c /path/to/config.yaml
# From stdincat config.yaml | openai-mock-api --config -openai-mock-api --config - < config.yaml
# Without --config flag (defaults to stdin)cat config.yaml | openai-mock-api
The configuration must be a valid YAML containing your API key, responses, and other settings. If no config option is provided, the tool will attempt to read from stdin.
Optional Options
Section titled “Optional Options”-p, --port <number>
Section titled “-p, --port <number>”Port number to run the server on. Defaults to 3000
.
openai-mock-api --config config.yaml --port 8080openai-mock-api -c config.yaml -p 8080
If both the CLI option and config file specify a port, the CLI option takes precedence.
-l, --log-file <path>
Section titled “-l, --log-file <path>”Path to a log file. If not specified, logs are written to stdout.
openai-mock-api --config config.yaml --log-file server.logopenai-mock-api -c config.yaml -l /var/log/openai-mock.log
The log file will be created if it doesn’t exist. The directory must exist.
-v, --verbose
Section titled “-v, --verbose”Enable verbose logging. Shows debug-level information including:
- Request details
- Matcher evaluation process
- Response selection logic
- Timing information
openai-mock-api --config config.yaml --verboseopenai-mock-api -c config.yaml -v
-h, --help
Section titled “-h, --help”Display help information and exit.
openai-mock-api --helpopenai-mock-api -h
--version
Section titled “--version”Display version information and exit.
openai-mock-api --version
Examples
Section titled “Examples”Basic Usage
Section titled “Basic Usage”# Minimal setupopenai-mock-api --config config.yaml
# From stdincat config.yaml | openai-mock-api
# Custom portopenai-mock-api --config config.yaml --port 3001
# With loggingopenai-mock-api --config config.yaml --log-file api.log
# Verbose mode for debuggingopenai-mock-api --config config.yaml --verbose
# All options combinedopenai-mock-api \ --config config.yaml \ --port 3001 \ --log-file api.log \ --verbose
Development Usage
Section titled “Development Usage”# Start with verbose logging for developmentopenai-mock-api -c dev-config.yaml -v
# Use a different port to avoid conflictsopenai-mock-api -c config.yaml -p 3001
# Log to a specific file for debuggingopenai-mock-api -c config.yaml -l debug.log -v
# Quick test with inline configecho 'apiKey: test-keyport: 3000responses: - id: test messages: - role: user content: Hello - role: assistant content: Hi!' | openai-mock-api -v
Production Usage
Section titled “Production Usage”# Production with specific port and loggingopenai-mock-api \ --config production-config.yaml \ --port 8080 \ --log-file /var/log/openai-mock.log
# Using environment variablesPORT=8080 LOG_FILE=/var/log/api.log openai-mock-api -c config.yaml
Configuration File Priority
Section titled “Configuration File Priority”Settings are applied in this order (later options override earlier ones):
- Configuration file values
- Environment variables
- Command-line options
port: 3000
# This will run on port 8080, not 3000openai-mock-api --config config.yaml --port 8080
Environment Variables
Section titled “Environment Variables”While not directly supported by CLI options, you can use environment variables in your shell:
# Set defaults via environmentexport OPENAI_MOCK_PORT=3001export OPENAI_MOCK_CONFIG=config.yaml
# Use in commandsopenai-mock-api --config "$OPENAI_MOCK_CONFIG" --port "$OPENAI_MOCK_PORT"
Exit Codes
Section titled “Exit Codes”Code | Description |
---|---|
0 | Success |
1 | Configuration error or server startup failure |
2 | Invalid command-line arguments |
130 | Interrupted (Ctrl+C) |
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”“Configuration file not found”
# Check the pathls -la config.yaml
# Use absolute pathopenai-mock-api --config /full/path/to/config.yaml
“Port already in use”
# Check what's using the portlsof -i :3000
# Use a different portopenai-mock-api --config config.yaml --port 3001
“Permission denied” for log file
# Check directory permissionsls -la /var/log/
# Use a writable locationopenai-mock-api --config config.yaml --log-file ./api.log
Debug Information
Section titled “Debug Information”Use verbose mode to get detailed information:
openai-mock-api --config config.yaml --verbose
This will show:
- Configuration loading process
- Server startup details
- Request processing information
- Matcher evaluation steps