Skip to main content
Elastly publishes a client for TypeScript and a client for Python. Both are generated from the same API document as the API reference, so every endpoint, field and error code in the reference is available with types. This page covers installing a client, making a first request, handling errors and the three helpers in the TypeScript package. For any other language, call the API over HTTPS as the guides show, or generate a client from the API document.

Install

The TypeScript package needs Node.js 20 or later. The Python package needs Python 3.11 or later.

Create a client

Create one client with your API key and reuse it. See Authentication for the key types.

Make a request

Each endpoint in the API reference is one method in TypeScript and one module in Python, named after the operation.
In Python, every operation has four forms: sync and asyncio return the parsed body, and sync_detailed and asyncio_detailed return the status, headers and parsed body together.

API version

A client sends the API version it was generated from in the Elastly-Version header on every request, so a request never depends on the version pinned on the key. To call another version, pass apiVersion to createElastly in TypeScript or elastly_version to an operation in Python. See Versioning.

Handle errors

In TypeScript, a method resolves with data, error and response. answerOf returns the body of a successful response and throws for anything else. code is the error code from Errors.
TypeScript
In Python, an operation returns the parsed success body or an ApiError with error and request_id.

Idempotency keys

Endpoints that need an Idempotency-Key take it as a required header in TypeScript and a required idempotency_key argument in Python. See Idempotency.

TypeScript helpers

The TypeScript package adds three helpers on top of the generated client.

Verify a webhook

verifyWebhook checks the signature and the age of a delivery and returns the typed event. Pass the request body exactly as received. It throws WebhookVerificationError with a code of missing_header, timestamp_out_of_tolerance, signature_mismatch or invalid_payload.
TypeScript
webhookSecret is the endpoint’s signing secret, which starts with whsec_. A delivery older than five minutes is refused. Set toleranceSeconds to change that. See Webhooks and events.

Apply queued prices

drainWriteback claims queued prices, calls your apply function for each one, keeps the lease alive while apply runs and reports every result in one request. It runs until you abort its signal. See Write-back queue.
TypeScript
Return { outcome: "rejected", code, message } for a price your system will never accept and { outcome: "retry" } to try again later. If apply throws, the item is reported as retry with the error message.

Keep serving prices during an outage

createFailOpenPricing remembers the last successful response for each request. When the API cannot be reached, does not answer within the timeout or answers with a 5xx status, it returns the remembered response with stale: true. A remembered line is served only until its validUntil; after that the line is left out and the call fails if no line remains.
TypeScript
A remembered response is served only for the same buyer, currency and lines. A request the API refuses, such as invalid_request or insufficient_scope, is never answered from memory. Responses are kept in the memory of the process and are lost when it restarts.

Price requests

Price lines and quotes, report outcomes and read decisions.

Write-back queue

Claim approved prices and report the result of each one.