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

# Quick Start

Qoder Agent SDK lets you call Qoder AI capabilities from TypeScript — read/write files, search code, execute commands, and more — embedding an AI Agent into your application or script with just a few lines of code.

<div id="prerequisites" />

## Prerequisites

* Node.js 18+

<div id="install" />

## Install

```bash theme={null}
npm install @qoder-ai/qoder-agent-sdk
```

<div id="authentication" />

## Authentication

The SDK authenticates via a Personal Access Token (PAT), ideal for scripts, CI pipelines, and third-party integration scenarios.

Generate a PAT at [qoder.com/account/integrations](https://qoder.com/account/integrations) (copy it immediately — the value cannot be retrieved again after the page is closed). For full steps, custom environment variables, and reusing local `qodercli` credentials, see [SDK Authentication](/en/cli/sdk/authentication).

Once you have a PAT, set the environment variable first:

```bash theme={null}
export QODER_PERSONAL_ACCESS_TOKEN="<your-qoder-personal-access-token>"
node agent.mjs
```

Then configure authentication using `accessTokenFromEnv()`:

```js theme={null}
import { accessTokenFromEnv, query } from '@qoder-ai/qoder-agent-sdk';

const stream = query({
  prompt: 'Hello',
  options: {
    auth: accessTokenFromEnv(),
  },
});
```

The SDK reads this environment variable before starting qodercli and writes the parsed access token into a one-time auth payload. You typically don't need to pass the PAT via the `env` option; if `options.env` is explicitly provided, the SDK reads the same-named variable from it first.

> **Security Note**: Do not hard-code PATs in your code repository. Inject them via environment variables or a secrets management service.

<div id="example" />

## Example

Create `agent.mjs`:

```js theme={null}
import { accessTokenFromEnv, query } from '@qoder-ai/qoder-agent-sdk';

for await (const message of query({
  prompt: 'Analyze the codebase, find functions without test coverage, and write unit tests for them.',
  options: {
    auth: accessTokenFromEnv(),
    allowedTools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash'],
    permissionMode: 'acceptEdits',  // Auto-approve file edits
  },
})) {
  if (message.type === 'assistant') {
    for (const block of message.message.content) {
      if (block.type === 'text') {
        console.log(block.text);              // AI text response
      } else if (block.type === 'tool_use') {
        console.log(`Tool: ${block.name}`);   // Tool being called
      }
    }
  } else if (message.type === 'result') {
    console.log(`Done: ${message.subtype}`);  // Final result
  }
}
```

```bash theme={null}
node agent.mjs
```

The Agent will autonomously browse the project, find functions lacking test coverage, generate test files, and run them for verification.

<div id="next-steps" />

## Next Steps

* [SDK Authentication](/en/cli/sdk/authentication) — PAT, environment variables, and auth error handling
* [Multi-turn Conversation](/en/cli/sdk/multi-turn-conversation) — Multi-message session, managing the session lifecycle
* [Streaming Output](/en/cli/sdk/streaming-output) — Receive incremental content in real time, typewriter effect
* [SDK References](/en/cli/sdk/references) — Complete SDK reference
