> ## 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 API client (devin.api)

> The typed API client the Devin SDK exposes as devin.api: every REST resource as a method, documented from its TypeScript source one page per class and type.

Sessions cover live interaction. Everything else the platform offers — session history and
structured output, pull requests, playbooks, secrets, repositories, schedules, usage and
enterprise administration — is reached through the [Devin REST API](https://docs.devin.ai/api-reference/overview.md).
The SDK ships a typed TypeScript client for all of it, the **API client**, and a `CloudDevin`
hands you one as `api`, already authenticated with the same key and pointed at the same base URL
as the session connection:

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

await using devin = await createDevin(); // CloudDevin; apiKey from DEVIN_API_KEY
const org_id = "org_…";

// A session you drove over ACP, seen through the REST API.
const session = await devin.createSession();
await session.run("Add a CHANGELOG entry for the last release and open a PR.");
const snapshot = await devin.api.sessions.getSession({ org_id, devin_id: session.id });
console.log(snapshot.status_detail, snapshot.pull_requests);

// Platform resources have no session at all.
const playbooks = await devin.api.playbooks.listPlaybooks({ org_id });
const secrets = await devin.api.secrets.listSecrets({ org_id });
```

`api` is cloud-only: a `LocalDevin` runs the CLI on your machine and has no cloud session to ask
about. You can also construct the client on its own without opening a session connection:

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

const api = new DevinApiClient({ token: process.env.DEVIN_API_KEY });
await api.sessions.getSessions({ org_id: "org_…", qs: { first: 20 } });
```

## Shape of the client

`devin.api` is a `DevinApiClient`. Each REST resource is a property holding a resource client
(`devin.api.sessions` is a `SessionsClient`, `devin.api.enterprise.auditLogs` an
`EnterpriseAuditLogsClient`), and each REST operation is one method taking a single request
object: path parameters, query parameters and body fields flattened together, with the names the
API uses (`org_id`, `devin_id`).

```ts theme={null}
const created = await devin.api.sessions.createSession({
  org_id, // path parameter
  prompt: "Investigate the flaky checkout test", // body
  repos: ["acme/shop"],
});
```

Every method also takes an optional second argument, `RequestOptions`: `timeoutInSeconds`,
`maxRetries` (default 2), `abortSignal`, extra `headers`, `queryParams`. Failures throw a
`DevinApiError` with `statusCode`, the parsed `body`, and the `rawResponse`;
`DevinApiTimeoutError` when the request timed out.

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

try {
  await devin.api.sessions.getSession({ org_id, devin_id: "devin-nope" }, { maxRetries: 0 });
} catch (error) {
  if (error instanceof DevinApiError && error.statusCode === 404) console.log("no such session");
  else throw error;
}
```

Methods on paginated endpoints return a `Page`: `page.data` is the first page, and iterating the
page fetches the rest as needed.

```ts theme={null}
const messages = await devin.api.sessions.getSessionMessages({ org_id, devin_id: session.id });
for await (const message of messages) console.log(message.source, message.message);
```

Request and response types live in the `DevinApi` namespace (`DevinApi.SessionResponse`,
`DevinApi.CreateSessionRequest`), also exported from the package. Raw HTTP details are available
per call through `.withRawResponse()`.

## Where this reference comes from

The pages in this section are generated from the client's TypeScript source, not written by
hand. The client itself is generated by [Fern](https://buildwithfern.com) from the OpenAPI
spec of the [Devin REST API (v3)](https://docs.devin.ai/api-reference/v3/overview.md); a generation step first turns each
operation's dotted `operationId` (`sessions.createSession`) into the resource client and method
name you call, and adds pagination annotations. TypeDoc then reads the generated code, so what you see here is what
ships in the package, including Fern's JSDoc and the examples it derives from the spec.

Because the resource clients are only reachable through `devin.api.*`, not as top-level exports,
the reference exports them under their own names, and nested resources under a path-qualified
name where Fern reuses a class name: `devin.api.enterprise.sessions` is documented as
`EnterpriseSessionsClient`, distinct from the top-level `SessionsClient`.

> [!NOTE]
>
> Fern writes its examples against a bare client variable: `client.sessions.createSession(…)`. Read
> `client` as `devin.api`.

This section documents the client, not the HTTP endpoints. For request and response fields with
their REST semantics, status codes and a playground, see the
[Devin API reference](https://docs.devin.ai/api-reference/overview.md).


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