@naturali/sdk

中文文档
0.220.3发布于 2026/11/02UNLICENSEDTypeScriptESM + CJS零依赖

TypeScript SDK for the naturali.ai API, generated from its OpenAPI specs

原始使用文档
文档目录6 节
  1. Usage
  2. Options
  3. Call shape
  4. Types
  5. Generation
  6. Versioning

@naturali/sdk

TypeScript SDK for the naturali.ai API, generated from its OpenAPI specs.

pnpm add @naturali/sdk

Usage

import { NaturaliClient } from '@naturali/sdk';

const naturali = new NaturaliClient({
  token: process.env.NATURALI_TOKEN, // nat_sk_… or a session access JWT
});

const { data, error } = await naturali.agents.listAgents({
  path: { project_id: 'proj_V1StGXR8Z5jdHi6B' },
  query: { limit: 10 },
});

if (error) {
  // The platform's error envelope, typed: { error: { code, message, details } }
  console.error(error);
} else {
  console.log(data.data);
}

A method never throws on a non-2xx response — it resolves to { data, error }, so the machine-readable code (approval_required, budget_exceeded, access_denied, …) is available as typed data.

Options

The client always talks to https://api.naturali.ai — the only naturali.ai API origin, and not configurable.

OptionPurpose
tokenSent as Authorization: Bearer …. Accepts a nat_sk_… API key or a session access JWT.
headersMerged last, so it can override the header above or add your own.

There is no project option: a project-scoped operation takes project_id in its path, and that is the only thing the API authorizes against.

Call shape

Each resource property mirrors a generated service class, with the configured HTTP client already bound. Arguments follow the spec's own structure and snake_case field names:

await naturali.sessions.addSessionMessage({
  path: { project_id, agent_id, session_id },
  body: { message: 'What is the capital of France?' },
});

await naturali.knowledge.queryKnowledgeCollection({
  path: { project_id, collection_id },
  body: { query: 'refund policy', limit: 5 },
});

Resources: agents, apiKeys, auth, channels, contacts, generations, knowledge, models, projects, providers, sessions, tools, traces.

naturali.http exposes the underlying client for interceptors or a one-off request (naturali.http.get({ url: '/health' })).

Types

Every schema in the specs is exported as a type:

import type { Agent, AgentCreate, ErrorResponse } from '@naturali/sdk';

created_at / updated_at are handed to callers as Date objects; everything else matches the wire shape exactly.

Generation

src/generated/ is build output — never edit it, and never commit it. It is rebuilt from api/openapi/v1/*.yaml by pnpm generate, which typecheck, test and build all run first. See ../README.md for the pipeline.

The only hand-written source is src/naturaliClient.ts.

Versioning

Releases are automatic, and the version is shared with the API and with @naturali/cli — one number, one git tag, three packages. @naturali/[email protected] is the client for API 0.28.0, so the version you installed names the contract you are holding.

Any change to api/openapi/v1/*.yaml regenerates this package and publishes it, because the specs are what it is generated from — so a new version can mean the API gained a resource, not that the hand-written client changed.

fix:/chore: changes release a patch and feat: a minor, inferred from the squashed commit subject. Every case publishes on merge, breaking changes included. See the repository's PIPELINE.md and CHANGELOG.md.

版本与发布记录

@naturali/sdk 共发布 420 个版本,首次发布于 2026/07/29;过去 12 个月发布了 420 个版本。

版本发布日期距今
0.220.3latest2026/11/021 天前
0.220.22026/11/021 天前
0.220.12026/11/021 天前
0.220.02026/11/021 天前
0.219.12026/11/011 天前
0.219.02026/11/012 天前

关于 @naturali/sdk 的常见问题

@naturali/sdk 是什么?

TypeScript SDK用于naturali。ai API,由OpenAPI规范生成

如何安装 @naturali/sdk?

在项目目录运行 npm install @naturali/sdk,或使用 pnpm add / yarn add / bun add。

@naturali/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@naturali/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@naturali/sdk 可以商用吗?

@naturali/sdk 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@naturali/sdk 还在维护吗?

最新版本 0.220.3 发布于 2026/11/02(1 天前);至今共发布 420 个版本,其中过去 12 个月发布了 420 个;首次发布于 2026/07/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。