Configuration
Client Options
Section titled “Client Options”Full list of options accepted by the AcmeClient constructor.
const client = new AcmeClient({ // Authentication (one required) apiKey: "sk_live_...", accessToken: "at_...",
// Network baseUrl: "https://api.acme.dev/v1", timeout: 30000, maxRetries: 3, retryDelay: 1000,
// Logging logLevel: "warn",
// Hooks onRequest: (req) => console.log("Request:", req.url), onResponse: (res) => console.log("Response:", res.status), onError: (err) => console.error("Error:", err.code),});Options Reference
Section titled “Options Reference”Authentication
Section titled “Authentication”| Option | Type | Description |
|---|---|---|
apiKey | string | API key for server-side authentication |
accessToken | string | OAuth token for user-scoped operations |
Network
Section titled “Network”| Option | Type | Default | Description |
|---|---|---|---|
baseUrl | string | https://api.acme.dev/v1 | API base URL |
timeout | number | 30000 | Request timeout (ms) |
maxRetries | number | 3 | Maximum retry attempts |
retryDelay | number | 1000 | Base delay between retries (ms) |
Logging
Section titled “Logging”| Option | Type | Default | Description |
|---|---|---|---|
logLevel | string | "warn" | "debug", "info", "warn", "error", "silent" |
| Option | Type | Description |
|---|---|---|
onRequest | function | Called before each request is sent |
onResponse | function | Called after each successful response |
onError | function | Called when a request fails |
Environment Variables
Section titled “Environment Variables”The SDK automatically reads these environment variables:
| Variable | Maps To | Description |
|---|---|---|
ACME_API_KEY | apiKey | API key |
ACME_BASE_URL | baseUrl | Custom API URL |
ACME_LOG_LEVEL | logLevel | Logging verbosity |
ACME_TIMEOUT | timeout | Request timeout |
Retry Behavior
Section titled “Retry Behavior”Failed requests are retried automatically for these status codes:
408— Request Timeout429— Too Many Requests500— Internal Server Error502— Bad Gateway503— Service Unavailable504— Gateway Timeout
The delay between retries follows exponential backoff:
delay = retryDelay * 2^(attemptNumber - 1) + random jitter