> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Devin SDK quickstart

> Install the beta Devin SDK from npm, create a Devin session from TypeScript, send a prompt, and read the typed events it emits.

## Prerequisites

* Node.js 22 or later.
* A Devin API key: a `cog_…` [personal access token](https://docs.devin.ai/api-reference/personal-access-tokens.md),
  created on the **PATs** tab of
  [app.devin.ai → Settings → Devin API](https://app.devin.ai/settings/devin-api?tab=pats).

## Install

```sh npm theme={null}
npm install @cognition-ai/sdk@beta
```

```sh bun theme={null}
bun add @cognition-ai/sdk@beta
```

```sh pnpm theme={null}
pnpm add @cognition-ai/sdk@beta
```

> [!NOTE]
>
> The `@cognition-ai` packages are in beta. Every release is a `0.0.1-beta.N` prerelease on the
> `beta` dist-tag (currently `0.0.1-beta.7`), so the `@beta` suffix is required: a bare
> `npm install @cognition-ai/sdk` fails on purpose. Pin the exact version in your lockfile, and keep
> every `@cognition-ai` package you use (`sdk`, `ai-sdk`, `cloudflare-agents`, `harness-devin`) on
> the same version; they release together. Each published version is stable, but the API can
> change between beta bumps; see the [changelog](https://docs.devin.ai/sdk/changelog.md) for what moved.

> [!TIP]
>
> Using a coding agent? Install the
> [`devin-sdk` skill](https://github.com/COG-GTM/devin-sdk-examples/tree/main/skills/devin-sdk)
> and it will know how to use this SDK:
>
> ```sh theme={null}
> npx skills add COG-GTM/devin-sdk-examples
> ```

## Run a session

`createDevin()` connects to the cloud. Pass `cwd` to run the bundled Devin CLI on your machine
instead. Both need an API key, from the `apiKey` option or `DEVIN_API_KEY`; nothing else in the
environment changes which one you get.

```ts theme={null}
import { createDevin } from "@cognition-ai/sdk";

await using devin = await createDevin(); // cloud, apiKey from DEVIN_API_KEY
const session = await devin.createSession();

const result = await session.run("Explain in one paragraph what a coding agent SDK is for.");
console.log(result.text);
```

Clients are async-disposable, so `await using` closes the connection (and the CLI process) at
scope exit. Call `.close()` yourself if you don't use it.

## Next steps

> [card] [Stream events](https://docs.devin.ai/sdk/guides/streaming-events.md)
>
> Print the reply as it arrives and react to each tool call.

> [card] [Structured output](https://docs.devin.ai/sdk/guides/launch-and-structured-output.md)
>
> Get a typed, validated value back instead of prose.

> [card] [How it works](https://docs.devin.ai/sdk/how-it-works.md)
>
> Run the same code in the Devin CLI on your machine with `createDevin({cwd})`.

> [card] [Using devin.api](https://docs.devin.ai/sdk/api/overview.md)
>
> Read the session's PRs and structured output, or manage playbooks and secrets.

> [card] [Examples](https://docs.devin.ai/sdk/examples/overview.md)
>
> Five runnable programs, including this quickstart with a `--local` flag.

> [card] [SDK reference](https://docs.devin.ai/sdk/reference/overview.md)
>
> Every exported class, function, and type, generated from the source.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.