Client
Azion Lib client of the azion package that reaches Storage, SQL, Purge, Domains, Applications, and AI through one object.
The azion package carries the Azion Lib client. Its createClient function returns one object that holds a client for each of six modules: Storage, SQL, Purge, Domains, Applications, and AI. You pass your token once, to createClient. The azion package receives bug fixes only, and its maintenance ends in December 2026.
Install the package:
The samples on this page are JavaScript and TypeScript ES modules that use top-level await, and they run in Node.js. The TypeScript samples import types with import type, which keeps them loadable when the type annotations are stripped.
Authentication
The client takes your personal token in the token field of createClient. A function called directly from a module package, without a client, reads the token from the AZION_TOKEN environment variable instead.
For how the Azion Lib packages resolve the token and the debug setting, refer to How Azion Lib works.
createClient
Creates the client. createClient is also the default export of the azion package.
| Parameter | Type | Required | Description |
|---|---|---|---|
token | string | No | Your Azion personal token. |
options | AzionClientOptions | No | Request options. The type accepts debug only inside options: a top-level debug field is ignored, and TypeScript refuses it. |
Returns an AzionClient, with one property per module. Each property is that module’s client, and its methods return the response envelope the module page documents.
This sample creates a client and an SQL database through its sql module:
Output:
In TypeScript, import AzionClient from the azion root and the module types from the module subpath. This sample reads the database that the previous call created:
Output:
Modules
An AzionClient holds exactly six properties, one per module. Each property takes the same calls as the client that the module’s own package creates, and each module page documents those calls and their response envelope.
| Property | Type | What it reaches | Module page |
|---|---|---|---|
storage | AzionStorageClient | Object Storage buckets, and their objects through the methods each bucket carries. | Storage |
sql | AzionSQLClient | SQL databases: create, list, read, and delete. A database it returns carries query and execute methods. | SQL |
purge | AzionPurgeClient | Cache purges by URL, cache key, or wildcard. | Purge |
domains | AzionDomainsClient | Domains: create, list, read, update, and delete. Calls Azion API v3. | Domains |
applications | AzionApplicationsClient | Applications: create, list, read, update, and delete. Calls Azion API v3. | Applications |
ai | AzionAIClient | Chat completions, with chat and streamChat. | AI client |
Module clients and standalone functions
The aggregate client is one of three ways to call a module. Each module also has its own internal client, which its package creates with its own createClient, and each module function can be called on its own, without any client. A module client takes the token in its token field, like the aggregate client. A standalone function reads the token from the AZION_TOKEN environment variable, for example from a .env file.
The Storage and SQL modules have their own packages, @aziontech/storage and @aziontech/sql. Install them:
This sample creates a Storage module client from @aziontech/storage and creates a bucket with it:
Output:
This sample calls createDatabase from @aziontech/sql with no client. The token comes from AZION_TOKEN, and the second argument carries the request options:
Output:
Use the aggregate client to reach several modules from one object. Call a standalone function when you configure the token and the options through environment variables and want only the function you call.
Types
The azion root exports the AzionClient and AzionClientConfig types. Import them with import type. The root also exports defineConfig, processConfig, and convertJsonConfigToObject, which the Config page documents.
AzionClient
The client that createClient returns. For what each property reaches, refer to Modules.
| Property | Type | Required | Description |
|---|---|---|---|
storage | AzionStorageClient | Yes | The Storage module client. |
sql | AzionSQLClient | Yes | The SQL module client. |
purge | AzionPurgeClient | Yes | The Purge module client. |
domains | AzionDomainsClient | Yes | The Domains module client. |
applications | AzionApplicationsClient | Yes | The Applications module client. |
ai | AzionAIClient | Yes | The AI module client. |
AzionClientConfig
The object that createClient takes.
| Property | Type | Required | Description |
|---|---|---|---|
token | string | No | Your Azion personal token. |
options | AzionClientOptions | No | Request options. |
AzionClientOptions
The request options type of AzionClientConfig. The azion root does not export it: the client declares it from azion/sql, so import it from there when you need it.
| Property | Type | Required | Description |
|---|---|---|---|
debug | boolean | No | Turns on debug mode. |
force | boolean | No | Forces the operation, even when it can destroy data. |
env | AzionEnvironment | No | The environment the calls go to: 'development', 'staging', or 'production'. |
external | boolean | No | Forces the REST API instead of the API built into the runtime. |