Configuration¶
Environment Variables¶
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 8082 |
NODE_ENV |
Environment mode | development |
OPENAI_API_KEY |
OpenAI API key | - |
OPENAI_DEFAULT_MODEL |
Default OpenAI model | gpt-5.2 |
RATE_LIMIT_ENABLED |
Enable rate limiting | false |
RATE_LIMIT_TYPE |
Rate limiter type (memory or redis) |
memory |
REDIS_URL |
Redis connection URL | - |
CORS_ORIGIN |
CORS allowed origins | * |
ROUTE_PREFIX |
Route prefix for all endpoints | /ai |
CONFIG_FILE |
Path to JSON config file | - |
Standalone Server¶
The package ships a ready-to-run entry point at jodit-ai-adapter/run.
This is the fastest way to spin up a local server — no custom code required:
It reads all settings from environment variables (see table above).
To use a JSON config file instead, set CONFIG_FILE:
Configuration File Format¶
{
"port": 8082,
"routePrefix": "/ai",
"providers": {
"openai": {
"type": "openai",
"apiKey": "sk-...",
"defaultModel": "gpt-5.2"
}
},
"rateLimit": {
"enabled": true,
"type": "memory",
"maxRequests": 100,
"windowMs": 60000
}
}
Docker¶
The Docker image uses the same standalone entry point internally:
With a config file:
docker run -p 8082:8082 \
-v ./config.json:/app/config.json \
-e CONFIG_FILE=/app/config.json \
xdsoft/jodit-ai-adapter
CORS Configuration¶
By default the server allows all origins (*). For fine-grained control, use the cors object
(it takes precedence over the legacy corsOrigin / CORS_ORIGIN setting):
| Option | Type | Default | Description |
|---|---|---|---|
origin |
string \| string[] \| RegExp |
* |
Allowed origin(s) |
methods |
string |
GET, POST, OPTIONS, PUT, DELETE |
Allowed HTTP methods |
allowedHeaders |
string |
Content-Type, Authorization, x-api-key, x-requested-with |
Allowed request headers |
credentials |
boolean |
true |
Send Access-Control-Allow-Credentials |
maxAge |
number |
86400 |
Preflight cache duration in seconds |
JSON config file¶
{
"cors": {
"origin": "https://app.example.com",
"methods": "GET, POST",
"credentials": true,
"maxAge": 3600
}
}
Programmatic usage¶
import { createApp } from 'jodit-ai-adapter';
const { app } = createApp({
cors: {
origin: ['https://app.example.com', 'https://admin.example.com'],
methods: 'GET, POST',
allowedHeaders: 'Content-Type, Authorization',
credentials: true,
maxAge: 3600
},
providers: { /* ... */ }
});
Tip
For simple cases you can still use just corsOrigin: '*' or CORS_ORIGIN=https://example.com.
The cors object is only needed when you want to customise methods, headers, credentials or max-age.
Programmatic Configuration¶
When using the package as a library in your own app:
import { start } from 'jodit-ai-adapter';
const { app, cleanup } = await start({
port: 8082,
config: {
routePrefix: '/api/v1',
providers: {
openai: {
type: 'openai',
apiKey: process.env.OPENAI_API_KEY,
defaultModel: 'gpt-5.2'
}
},
rateLimit: {
enabled: true,
type: 'memory',
maxRequests: 100,
windowMs: 60000
}
}
});
// To gracefully shut down (stops server + releases resources):
// await cleanup();
See Rate Limiting for advanced rate limiting options (Redis, per-user limits, etc.).