AEO API TypeScript SDK
Use @aeoapi/aeo-sdk on a server running Node.js 20 or later. The client has a method for each v2 operation and helpers for reading lists and waiting for runs.
Install the package
Use Git and npm to clone the Node.js SDK repository and build the package. npm pack runs the build and prints the archive filename.
git clone https://github.com/aeo-api/aeoapi-nodejs-sdk.git
cd aeoapi-nodejs-sdk
npm ci
npm packFrom your application directory, install the archive. Substitute the path and filename from your build.
npm install /path/to/aeoapi-nodejs-sdk/aeoapi-aeo-sdk-0.3.0.tgzSet up the client
Set AEO_API_KEY on your server. To check your connection, use a key with account:read and request the account overview. Set baseUrl to the API origin without /v2.
import { AeoClient } from "@aeoapi/aeo-sdk";
const apiKey = process.env.AEO_API_KEY;
if (!apiKey) throw new Error("Set AEO_API_KEY on your server.");
const client = new AeoClient(apiKey, { baseUrl: "https://api.aeoapi.dev" });
const account = await client.v2GetAccount();
console.log(account.status, account.body);HTTP 200 returns your plan and limits in body.data. Endpoint methods return ApiResponse<unknown>. Check or narrow the body type before accessing its fields in TypeScript.
Read the response
statusis the HTTP status.bodyholds parsed JSON, a CSV string for CSV exports, ornullfor an empty body.headerscontains the HTTP headers.requestIdidentifies the request andetagholds the revision header when available.usageUnitsis the number fromX-Usage-Units, ornullif the header is missing or contains anything other than digits.
Handle errors
For AeoApiError, read status and code to decide what to do next. Validation errors can include fieldErrors. Keep requestId if you contact support.
If the connection fails or the client cannot finish reading a successful response, it throws AeoTransportError after any allowed retries. If a successful response contains invalid JSON, the client throws SyntaxError without retrying.
import { AeoApiError, AeoTransportError } from "@aeoapi/aeo-sdk";
import { AeoClient } from "@aeoapi/aeo-sdk";
const apiKey = process.env.AEO_API_KEY;
if (!apiKey) throw new Error("Set AEO_API_KEY on your server.");
const client = new AeoClient(apiKey, { baseUrl: "https://api.aeoapi.dev" });
try {
const account = await client.v2GetAccount();
console.log(account.body);
} catch (error) {
if (error instanceof AeoApiError) {
console.error(error.status, error.code, error.requestId, error.fieldErrors);
} else if (error instanceof AeoTransportError) {
console.error(error.message);
} else if (error instanceof SyntaxError) {
console.error("The response contained invalid JSON.");
} else {
throw error;
}
}See the API error codes for recovery steps. Invalid client options can throw a JavaScript Error or TypeError before the request is sent.
Retries and request keys
The SDK retries GET requests and writes that require Idempotency-Key. It allows two retries by default after a network failure, HTTP 429, or HTTP 503 when the error is marked retryable. A write that accepts the header as optional does not qualify for automatic retries.
For a required key, the SDK generates one per call and sends the same value on every retry. To retry a write from your own job, persist the body and pass the same options.idempotencyKey on the next call. Keys must contain 8 to 128 visible ASCII characters.
Pass retry in the constructor to change the policy. The default randomized backoff starts with a 500 ms upper bound and caps at 8000 ms. A numeric Retry-After of up to 60 seconds takes precedence. A longer delay returns the error to your application.
Set a deadline
Requests have no default timeout. Pass an AbortSignal to cancel an active request at your deadline. In waitForRun, timeoutMs controls whether another wait can start. An active request can run past that deadline. If you abort during a wait, the next request receives the aborted signal when the wait ends.
import { AeoClient } from "@aeoapi/aeo-sdk";
const apiKey = process.env.AEO_API_KEY;
if (!apiKey) throw new Error("Set AEO_API_KEY on your server.");
const client = new AeoClient(apiKey, { baseUrl: "https://api.aeoapi.dev" });
const controller = new AbortController();
const deadline = setTimeout(() => controller.abort(), 10_000);
try {
const account = await client.v2GetAccount({ signal: controller.signal });
console.log(account.body);
} finally {
clearTimeout(deadline);
}Read more than one page
Use paginate for whole pages or iterItems for individual records when a response returns meta.next_cursor. For the draft list, pass data.next_offset as offset instead.
Wait for a run
Pass a qualified run ID or poll URL to waitForRun. For Brave submissions, it returns at submitted or failed. To check the status yourself, follow the Brave polling example.
Method reference
Some features share a method. For example, a site audit and a collection run both start with v2PostRuns. The workflow field selects the work.