@cognite/sdk

中文文档
10.19.0发布于 2026/11/06Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 4.6万

The package @cognite/sdk provides convenient access to the stable Cognite API from applications written in client- or server-side javascript.

原始使用文档
文档目录13 节
  1. Installation
  2. Usage
  3. Using ES modules
  4. Using typescript
  5. Quickstart
  6. Web
  7. Backend
  8. Documentation
  9. Concurrency
  10. Data Modeling concurrency
  11. Best practices
  12. No submodule imports
  13. Guides

Cognite Javascript SDK

The package @cognite/sdk provides convenient access to the stable Cognite API from applications written in client- or server-side javascript.

The SDK supports authentication through bearer tokens. See Authentication Guide.

Installation

Install the package with yarn:

$ yarn add @cognite/sdk

or npm

$ npm install @cognite/sdk --save

Usage

const { CogniteClient } = require('@cognite/sdk');

Using ES modules

import { CogniteClient } from '@cognite/sdk';

Using typescript

The SDK is written in native typescript, so no extra types need to be defined.

Quickstart

Web

import { CogniteClient } from '@cognite/sdk';

async function quickstart() {
  const project = 'publicdata';
  const oidcTokenProvider = async () => {
    return 'YOUR_OIDC_ACCESS_TOKEN';
  };

  const client = new CogniteClient({
    appId: 'YOUR APPLICATION NAME',
    project,
    oidcTokenProvider,
  });

  const assets = await client.assets.list().autoPagingToArray({ limit: 100 });
}
quickstart();

For more details about SDK authentication see this document. Also, more comprehensive intro guide can be found here

Backend

const { CogniteClient } = require('@cognite/sdk');

async function quickstart() {
  const client = new CogniteClient({
    appId: 'YOUR APPLICATION NAME',
    oidcTokenProvider: () => Promise.resolve('YOUR_OIDC_ACCESS_TOKEN'),
  });

  const assets = await client.assets.list().autoPagingToArray({ limit: 100 });
}
quickstart();

Documentation

Concurrency

Experimental: the concurrency option is experimental. Breaking changes are to be expected in any release, including patch and minor versions.

Concurrency limits control how many HTTP requests the SDK can have in flight at the same time, not how many requests it sends per second. Limits are applied per client and operation category. Requests that reach a category's limit wait in a queue; other categories and separate clients have independent limits.

The SDK uses semaphores to manage these queues. Each HTTP attempt acquires a slot and holds it until the response body has been read or the attempt fails. Slots are released during retry backoff, allowing queued requests to proceed. A retry must acquire a slot again; backoff pauses only that request, not the category.

Queued attempts are admitted in FIFO (first-in, first-out) order, but calls are not guaranteed to complete in invocation order. Continue to await dependent mutations explicitly.

The SDK imposes no request timeout. A request that never settles, including a stalled response body, retains its slot indefinitely. Timing out an outer promise, for example with Promise.race, does not cancel the underlying request or release its slot.

Concurrency limits are opt-in: requests are not limited unless you pass the concurrency client option. Pass an empty object to enable the defaults. Currently, the SDK applies concurrency limits only to Data Modeling requests. Other API requests are not limited by this mechanism.

Note: CDF is a shared backend service. Excessive concurrency can degrade performance for other workloads in your organization. Start with the default limits and increase them cautiously, monitoring latency and throttling responses (HTTP 429). Higher concurrency does not necessarily mean higher throughput.

Data Modeling concurrency

Once concurrency is set, Data Modeling requests are limited by the defaults below. Each client has independent budgets shared across all endpoints in the Data Modeling /models namespace and Data Modeling GraphQL routes, including raw client HTTP calls:

CategoryDefaultOperations
read1Instance list, retrieve, query, sync, inspect, and DM user GraphQL queries and mutations
search2Instance search and aggregate
write1Instance upsert/apply
delete1Instance deletes
readSchema2Reads of spaces, containers, views, and data models; statistics
writeSchema1Schema upserts and deletes, container index/constraint/property retries, and GraphQL DML writes

Data Modeling GraphQL queries and mutations under /userapis/spaces/{space}/datamodels/{model}/versions/{version}/graphql all use read. Classification is based on the endpoint, not the GraphQL request body, so these mutations do not acquire the REST write or delete budgets. Increasing read also increases the allowed concurrency for these mutations. GraphQL DML writes to /dml/graphql use writeSchema.

Unknown operations within known schema namespaces use readSchema; other unknown operations within the Data Modeling /models namespace use read. Project routes remain limited behind proxy path prefixes, for example https://proxy.example/cdf/api/v1/projects/my-project/models/instances/query. Categories have independent budgets, so requests in different categories can run at the same time. If every category is saturated, the defaults allow at most 8 requests in flight per client (1 + 2 + 1 + 1 + 2 + 1).

To enable the default limits:

const client = new CogniteClient({
  appId: 'YOUR APPLICATION NAME',
  project: 'YOUR PROJECT',
  oidcTokenProvider: async () => 'YOUR_OIDC_ACCESS_TOKEN',
  concurrency: {},
});

To set specific limits:

const client = new CogniteClient({
  appId: 'YOUR APPLICATION NAME',
  project: 'YOUR PROJECT',
  oidcTokenProvider: async () => 'YOUR_OIDC_ACCESS_TOKEN',
  concurrency: {
    dataModeling: { read: 2, write: 2 },
  },
});

Omitted or undefined category values retain their defaults. Limits must be positive integers or Infinity; invalid values throw during client construction. Infinity disables a category's limit (i.e. no concurrency control).

With the default read: 1, a stalled instance read blocks other non-schema Data Modeling reads on the same client. Schema reads and other categories remain independent.

Best practices

No submodule imports

We highly recommend avoiding importing anything from internal SDK modules.

All interfaces and functions should only be imported from the top level, otherwise you might face compatibility issues when our internal structure changes.

Bad:

import { CogniteAsyncIterator } from '@cognite/sdk/dist/src/autoPagination'; // ❌
import { AssetsAPI } from '@cognite/sdk/dist/src/resources/assets/assetsApi'; // ❌

let assetsApi: AssetsAPI; // ❌

Good:

import { CogniteAsyncIterator } from '@cognite/sdk'; // ✅

let assetsApi: CogniteClient['assets']; // ✅

We recommend the usage of eslint to ensure this best practice is enforced without having to memorize the patterns:

.eslintrc.json:

"rules": {
  "no-restricted-imports": ["error", { "patterns": ["@cognite/sdk/**"] }]
}

The API reference documentation contains snippets for each endpoint, giving examples of SDK use. See also the samples section in this repo.

Guides

版本与发布记录

@cognite/sdk 共发布 269 个版本,首次发布于 2018/12/19;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
10.19.0latest2026/11/063 天前
10.18.02026/11/027 天前
10.17.12026/10/2911 天前
10.17.02026/10/2912 天前
10.16.02026/10/1921 天前
10.15.02026/10/081 个月前

其他发布通道:alpha → 5.0.0-alpha,rc → 10.0.0-rc.10。

关于 @cognite/sdk 的常见问题

@cognite/sdk 是什么?

The package @cognite/sdk provides convenient access to the stable Cognite API from applications written in client- or server-side javascript.

如何安装 @cognite/sdk?

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

@cognite/sdk 支持 TypeScript 吗?

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

@cognite/sdk 支持 ESM 还是 CommonJS?

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

@cognite/sdk 可以商用吗?

@cognite/sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cognite/sdk 的下载量有多少?

根据 npm 官方下载统计,@cognite/sdk 在 2026/10/11 – 2026/11/09 这 30 天内被下载 46,403 次,日均约 1,547 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cognite/sdk 还在维护吗?

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