Clinik class is the single entry point for all SDK operations. When you construct a client, it validates your API key format, configures retry logic, and exposes typed namespaces for every supported FHIR resource. Every method on those namespaces returns the same ApiResponse<T> envelope, which gives you the resource data alongside request metadata.
Constructor
Your secret API key. Keys follow the format
clk_live_* for production and clk_test_* for the sandbox environment. Never hardcode this value — read it from an environment variable.Optional configuration object. All fields have safe defaults.
ClinikOptions
Base URL for all API requests. The SDK enforces HTTPS and warns at startup if you provide an HTTP URL.
Request timeout in milliseconds. Requests that exceed the limit throw a
ClinikApiError with code timeout.Maximum retry attempts on
5xx errors, 429 rate-limit responses, and network failures. Uses jittered exponential backoff. Set to 0 to disable.Resource namespaces
After construction, the client exposes 14 resource namespaces. Each namespace maps to a FHIR R4 resource type and provides the same five standard methods.| Method | Description |
|---|---|
create(data) | Create a new resource |
read(id, options?) | Read a resource by ID |
update(id, data) | Partially update a resource (JSON Patch internally) |
delete(id) | Delete a resource |
search(params?) | Search with filters and cursor pagination |
clinik.intakes.submit() and clinik.consents.sign() — where the action name is more semantically meaningful than create.
FHIR passthrough
For raw FHIR R4 access beyond what the simplified namespaces provide, use thefhir namespace:
ApiResponse<T>
Every SDK method returnsPromise<ApiResponse<T>>. Destructure data for the resource and meta for request metadata.
The requested resource or result. The generic type parameter
T corresponds to the resource type returned by the method you called.A unique identifier for the request. Include this when filing support tickets — it lets the ClinikAPI team trace the exact server-side execution.
ISO 8601 timestamp of when the server processed the request.
HTTP status code returned by the API.
Total number of requests allowed in the current rate-limit window.
Number of requests you can still make before hitting the rate limit. Monitor this field to implement proactive throttling in high-throughput workflows.
Seconds until the rate-limit window resets. Use this alongside
rateLimitRemaining to schedule request bursts.Example: using meta fields
Security features
The SDK applies several security protections automatically:- Browser detection — warns if you import the SDK in a browser environment where the API key would be exposed.
- HTTPS enforcement — warns at startup if
baseUrlis not an HTTPS URL. - Path traversal protection — resource IDs are validated against the pattern
[a-zA-Z0-9\-_.]before being interpolated into URLs. - FHIR include injection prevention —
_includevalues are validated to prevent parameter injection. - Body size limits — request bodies over 1 MB are rejected client-side before being sent.
- PHI sanitization — error messages never include patient data values, only field names and constraint descriptions.
- Jittered retries — exponential backoff with random jitter prevents thundering-herd issues during outages.