API SDK
What it is
@senlerio/api is a typed client for the public Senler AI API. It is generated from the OpenAPI specification and provides the AiSenlerClient class, response models, and separate method groups such as client.projects, client.agents, and client.apps.
The SDK is intended primarily for server-side integrations. It also runs in an environment with global fetch, but an arbitrary external website cannot call the production API unless its origin is allowed by the CORS policy. Never put a project API key or Client Secret in browser code.
Installation
Install the current published version from GitHub using a pinned tag:
npm install github:SenlerBot/Senler-io-sdk#v0.8.0
The package requires Node.js 18+ and includes TypeScript declarations. The pinned tag prevents a newly generated SDK contract from being pulled during the next dependency installation.
Authorization
Pass only the token value to accessToken, without the Bearer prefix. The SDK adds the Authorization: Bearer <token> header to every request.
Two token sources are supported:
- a project API key in the
senler_sk_...format for an integration with one project; - an application OAuth access token for access granted by a user through OAuth.
Available methods depend on the token scope and permissions. A user OAuth token is additionally restricted by the user's current permissions in the target project or developer application.
First request
Example for a project API key or project-scoped OAuth token:
import { AiSenlerClient } from "@senlerio/api";
const client = new AiSenlerClient({
accessToken: process.env.SENLER_API_TOKEN!,
});
const currentProject = await client.projects.getMe();
const agents = await client.agents.agentsList({
projectId: currentProject.project.id,
limit: 20,
});
An external integration does not need X-Session-Id: that header belongs to a cabinet session and is not part of the generated SDK method parameters.
Methods and types
A client group corresponds to an API section, and a method corresponds to an operation in the public OpenAPI specification. For example:
client.projectscovers projects;client.agentscovers agents;client.dialogsMessagingcovers dialog messages;client.appscovers developer applications;client.appDocumentationcovers developer application documentation.
These are examples, not a complete catalog. Current groups and signatures are available through TypeScript completion for the installed SDK version. Endpoint behavior, required parameters, and permissions are documented in the API reference.
Method parameters are passed as one camelCase object. The SDK converts property names to the API JSON format and converts responses into typed models. For example, idempotencyKey is sent as idempotency_key. If a required parameter is missing, TypeScript reports it during compilation and the runtime check throws RequiredError.
Use client.leadVariables.leadVariablesGetValues2 to read lead-variable values. Lead search uses cursor pagination: omit cursor for the first page.
When sending or editing a message, choose its text format: plain text or Markdown. Formatting is adapted to the recipient's channel.
Developer application settings are updated through separate methods: client.apps.updateGeneralSettings for the name, description, and website, client.apps.updateToolsSettings for agent tools, and client.apps.updateEmbeddedPageSettings for the embedded page. Each method accepts only the fields from its section, so changing one form does not overwrite adjacent settings.
For available model objects in the SDK, supportedServerBindingModes lists the MCP modes compatible with the model and its active provider connections. In the raw API JSON response, this field is named supported_server_binding_modes. Use the installed SDK's field when selecting an agent model instead of hard-coding compatibility in an integration.
Client configuration
The constructor supports these parameters:
accessTokenis the required API key or OAuth access token;baseUrlis the API address and defaults tohttps://api.senler.io; an override is normally useful only for development and tests;fetchApisupplies a customfetchimplementation when required by a runtime or test.
For a long-lived integration, configure OAuth token refresh and error handling.
Application action decorators and CLI are described in SDK for NestJS.
Reference materials
-
Delivery recipients through the API: saved and unsaved filters, unique recipients, and audience scope checks before launch;
-
Import leads from Senler.ru: load a linked channel's subscriber base, choose a user token, and check the result;
-
Messages through the API: plain text, Markdown, and formatting in different channels;
-
Knowledge-base archives via API: background ZIP uploads, checking results, and replacing all materials;
-
Images via API and MCP: import from a URL or attachment without a separate PUT, saving, and retries;
-
Senler AI public API reference documents endpoints, parameters, responses, and required permissions;
-
SDK source code and README contain the published package and available versions;
-
Project API keys explains key creation and permission selection;
-
Developer application OAuth explains token issuance, refresh, and revocation.