Skip to main content

Configuration

OSAPI is configured through a YAML file and optional environment variable overrides.

Config File

By default OSAPI looks for osapi.yaml in the current working directory. Override the path with the -f / --osapi-file flag:

osapi --osapi-file /etc/osapi/osapi.yaml api server start

Environment Variables

Every config key can be overridden with an environment variable using the OSAPI_ prefix. Dots and nested keys become underscores, and the name is uppercased:

Config KeyEnvironment Variable
debugOSAPI_DEBUG
api.server.portOSAPI_API_SERVER_PORT
api.server.security.signing_keyOSAPI_API_SERVER_SECURITY_SIGNING_KEY
api.client.security.bearer_tokenOSAPI_API_CLIENT_SECURITY_BEARER_TOKEN
nats.server.hostOSAPI_NATS_SERVER_HOST
job.worker.hostnameOSAPI_JOB_WORKER_HOSTNAME

Environment variables take precedence over file values.

Required Fields

Two fields carry a required validation tag and must be set before the server or client will start:

KeyPurpose
api.server.security.signing_keyHS256 key for signing JWTs
api.client.security.bearer_tokenJWT sent with client requests

Generate a signing key with openssl rand -hex 32. Generate a bearer token with osapi token generate.

Full Reference

Below is a complete osapi.yaml with every supported field and inline comments. Values shown are representative defaults from the repository's config file.

# Enable verbose logging.
debug: true

api:
client:
# Base URL the CLI client connects to.
url: 'http://0.0.0.0:8080'
security:
# JWT bearer token for client requests (REQUIRED).
# Generate with: osapi token generate
bearer_token: '<jwt>'

server:
# Port the REST API server listens on.
port: 8080
security:
# HS256 signing key for JWT validation (REQUIRED).
# Generate with: openssl rand -hex 32
signing_key: '<secret>'
cors:
# Origins allowed to make cross-origin requests.
# An empty list disables CORS headers entirely.
allow_origins:
- 'http://localhost:3001'
- 'https://osapi-io.github.io'

nats:
server:
# Hostname the embedded NATS server binds to.
host: 'localhost'
# Port the embedded NATS server binds to.
port: 4222
# Directory for JetStream file-based storage.
store_dir: '.nats/jetstream/'

job:
# ── Shared infrastructure names ──────────────────────────
# JetStream stream name for job notifications.
stream_name: 'JOBS'
# Subject filter for the JOBS stream.
stream_subjects: 'jobs.>'
# KV bucket for immutable job definitions and status events.
kv_bucket: 'job-queue'
# KV bucket for worker result storage.
kv_response_bucket: 'job-responses'
# Durable consumer name.
consumer_name: 'jobs-worker'

# ── Stream settings ─────────────────────────────────────
stream:
# Maximum age of messages in the stream (Go duration).
max_age: '24h'
# Maximum number of messages retained.
max_msgs: 10000
# Storage backend: "file" or "memory".
storage: 'file'
# Number of stream replicas (1 for single-node).
replicas: 1
# Discard policy when limits are reached: "old" or "new".
discard: 'old'

# ── Consumer settings ───────────────────────────────────
consumer:
# Maximum redelivery attempts before sending to DLQ.
max_deliver: 5
# Time to wait for an ACK before redelivering.
ack_wait: '2m'
# Maximum outstanding unacknowledged messages.
max_ack_pending: 1000
# Replay policy: "instant" or "original".
replay_policy: 'instant'
# Backoff durations between redelivery attempts.
back_off:
- '30s'
- '2m'
- '5m'
- '15m'
- '30m'

# ── KV bucket settings ─────────────────────────────────
kv:
# TTL for KV entries (Go duration).
ttl: '1h'
# Maximum total size of the bucket in bytes.
max_bytes: 104857600 # 100 MiB
# Storage backend: "file" or "memory".
storage: 'file'
# Number of KV replicas.
replicas: 1

# ── Dead Letter Queue settings ──────────────────────────
dlq:
# Maximum age of messages in the DLQ.
max_age: '7d'
# Maximum number of messages retained.
max_msgs: 1000
# Storage backend: "file" or "memory".
storage: 'file'
# Number of DLQ replicas.
replicas: 1

# ── Job client (CLI → NATS) ────────────────────────────
client:
# NATS server hostname for the job client.
host: 'localhost'
# NATS server port for the job client.
port: 4222
# Client name sent to NATS for identification.
client_name: 'osapi-jobs-cli'

# ── Job worker ─────────────────────────────────────────
worker:
# NATS server hostname for the worker.
host: 'localhost'
# NATS server port for the worker.
port: 4222
# Client name sent to NATS for identification.
client_name: 'osapi-job-worker'
# Queue group for load-balanced (_any) subscriptions.
queue_group: 'job-workers'
# Worker hostname for direct routing. Defaults to the
# system hostname when empty.
hostname: ''
# Maximum number of concurrent jobs to process.
max_jobs: 10
# Key-value labels for label-based routing.
# Values can be hierarchical with dot separators.
# See Job System Architecture for details.
labels:
group: 'web.dev.us-east'

Section Reference

api.client

KeyTypeDescription
urlstringBase URL the CLI client targets
security.bearer_tokenstringJWT for client auth (required)

api.server

KeyTypeDescription
portintPort the API server listens on
security.signing_keystringHS256 JWT signing key (required)
security.cors.allow_origins[]stringAllowed CORS origins

nats.server

KeyTypeDescription
hoststringHostname the NATS server binds to
portintPort the NATS server binds to
store_dirstringDirectory for JetStream file storage

job (top-level)

KeyTypeDescription
stream_namestringJetStream stream name
stream_subjectsstringSubject filter for the stream
kv_bucketstringKV bucket for job definitions and events
kv_response_bucketstringKV bucket for worker results
consumer_namestringDurable consumer name

job.stream

KeyTypeDescription
max_agestringMaximum message age (Go duration)
max_msgsintMaximum number of messages
storagestring"file" or "memory"
replicasintNumber of stream replicas
discardstringDiscard policy: "old" or "new"

job.consumer

KeyTypeDescription
max_deliverintMax redelivery attempts before DLQ
ack_waitstringACK timeout (Go duration)
max_ack_pendingintMax outstanding unacknowledged msgs
replay_policystring"instant" or "original"
back_off[]stringBackoff durations between redeliveries

job.kv

KeyTypeDescription
ttlstringEntry time-to-live (Go duration)
max_bytesintMaximum bucket size in bytes
storagestring"file" or "memory"
replicasintNumber of KV replicas

job.dlq

KeyTypeDescription
max_agestringMaximum message age (Go duration)
max_msgsintMaximum number of messages
storagestring"file" or "memory"
replicasintNumber of DLQ replicas

job.client

KeyTypeDescription
hoststringNATS server hostname
portintNATS server port
client_namestringNATS client identification name

job.worker

KeyTypeDescription
hoststringNATS server hostname
portintNATS server port
client_namestringNATS client identification name
queue_groupstringQueue group for load-balanced routing
hostnamestringWorker hostname (defaults to OS hostname)
max_jobsintMax concurrent jobs
labelsmap[string]stringKey-value pairs for label-based routing