Skip to content

Configuration

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),
});
OptionTypeDescription
apiKeystringAPI key for server-side authentication
accessTokenstringOAuth token for user-scoped operations
OptionTypeDefaultDescription
baseUrlstringhttps://api.acme.dev/v1API base URL
timeoutnumber30000Request timeout (ms)
maxRetriesnumber3Maximum retry attempts
retryDelaynumber1000Base delay between retries (ms)
OptionTypeDefaultDescription
logLevelstring"warn""debug", "info", "warn", "error", "silent"
OptionTypeDescription
onRequestfunctionCalled before each request is sent
onResponsefunctionCalled after each successful response
onErrorfunctionCalled when a request fails

The SDK automatically reads these environment variables:

VariableMaps ToDescription
ACME_API_KEYapiKeyAPI key
ACME_BASE_URLbaseUrlCustom API URL
ACME_LOG_LEVELlogLevelLogging verbosity
ACME_TIMEOUTtimeoutRequest timeout

Failed requests are retried automatically for these status codes:

  • 408 — Request Timeout
  • 429 — Too Many Requests
  • 500 — Internal Server Error
  • 502 — Bad Gateway
  • 503 — Service Unavailable
  • 504 — Gateway Timeout

The delay between retries follows exponential backoff:

delay = retryDelay * 2^(attemptNumber - 1) + random jitter