Skip to main content
This guide covers everything you need to install and configure the AT Protocol SDK in your development environment.

System requirements

Node.js

Version 18.7.0 or higherThe AT Protocol SDK requires Node.js 18.7.0+. Use nvm for easy version management.

Package manager

npm, yarn, or pnpmAny modern package manager works. The examples use npm, but commands are provided for all three.
The SDK is built with TypeScript and includes complete type definitions. While TypeScript is recommended, you can use the SDK with plain JavaScript.

Installing Node.js

If you don’t have Node.js installed, or need to upgrade:

Installing the SDK

1

Create or navigate to your project

If you’re starting a new project:
mkdir my-atproto-app
cd my-atproto-app
npm init -y
Or navigate to your existing project:
cd my-existing-project
2

Install @atproto/api

Install the main AT Protocol API client:
npm install @atproto/api
This installs the @atproto/api package, which includes:
  • Agent and AtpAgent classes for API calls
  • CredentialSession for authentication
  • RichText for text processing
  • All TypeScript type definitions
  • Content moderation utilities
3

Verify installation

Create a test file to verify everything is working:
test.ts
import { Agent } from '@atproto/api'

console.log('AT Protocol SDK installed successfully!')
console.log('Agent class:', typeof Agent)
Run it:
npx ts-node test.ts
You should see:
AT Protocol SDK installed successfully!
Agent class: function

Environment-specific setup

The AT Protocol SDK works in multiple JavaScript environments. Here’s how to set it up for each:

Node.js setup

Node.js (18.7.0+) has built-in support for everything the SDK needs:
import { Agent, CredentialSession } from '@atproto/api'

// Everything works out of the box in Node.js
const session = new CredentialSession(new URL('https://bsky.social'))
const agent = new Agent(session)
No polyfills or additional configuration needed!For TypeScript projects, add these to your tsconfig.json:
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "node",
    "lib": ["ES2022"],
    "types": ["node"]
  }
}

Additional packages

The AT Protocol SDK is split into multiple packages. Install additional packages as needed:
For production applications, use OAuth instead of app passwords:Browser applications:
npm install @atproto/oauth-client-browser
Node.js applications:
npm install @atproto/oauth-client-node
General/custom environments:
npm install @atproto/oauth-client
See the OAuth authentication guide for usage details.
For advanced identity operations:
npm install @atproto/identity
import { resolveHandle, resolveDid } from '@atproto/identity'

const did = await resolveHandle('alice.bsky.social')
const doc = await resolveDid(did)
For signing and key management:
npm install @atproto/crypto
import { Secp256k1Keypair } from '@atproto/crypto'

const keypair = await Secp256k1Keypair.create()
For advanced repository operations:
npm install @atproto/repo
import { Repo } from '@atproto/repo'

// Low-level repository operations
For working with Lexicon schemas:
npm install @atproto/lexicon
import { Lexicons } from '@atproto/lexicon'

const lexicons = new Lexicons(schemas)

TypeScript configuration

For the best TypeScript experience, configure your tsconfig.json:
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "node",
    "lib": ["ES2022", "DOM"],
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "types": ["node"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
The SDK provides complete TypeScript types out of the box. Enable strict mode to catch potential errors early.

Custom fetch implementation

If you need to provide a custom fetch implementation (for logging, proxying, etc.):
import { Agent, CredentialSession } from '@atproto/api'

const customFetch: typeof fetch = async (input, init) => {
  console.log('Request:', input)
  const response = await fetch(input, init)
  console.log('Response:', response.status)
  return response
}

const session = new CredentialSession(
  new URL('https://bsky.social'),
  customFetch  // Pass custom fetch here
)

const agent = new Agent(session)

Verification

After installation, verify everything is working:
verify.ts
import { Agent, CredentialSession, RichText } from '@atproto/api'

async function verify() {
  console.log('✓ Imports successful')

  // Test basic functionality
  const rt = new RichText({ text: 'Hello world!' })
  console.log('✓ RichText works:', rt.text)

  // Test session creation (doesn't require authentication)
  const session = new CredentialSession(new URL('https://bsky.social'))
  const agent = new Agent(session)
  console.log('✓ Agent created successfully')

  console.log('\n✅ All checks passed! SDK is ready to use.')
}

verify().catch(console.error)
Run with:
npx ts-node verify.ts

Troubleshooting

If you see “Cannot find module ‘@atproto/api’”:
  1. Make sure you ran npm install
  2. Check that @atproto/api is in your package.json dependencies
  3. Delete node_modules and reinstall:
    rm -rf node_modules package-lock.json
    npm install
    
  4. If using TypeScript, ensure moduleResolution is set to "node" in tsconfig.json
If you see errors about Node.js version:
  1. Check your current version: node --version
  2. Upgrade to Node.js 18.7.0 or higher
  3. Use nvm to manage versions: nvm install 22 && nvm use 22
  4. Add an .nvmrc file to your project:
    22
    
If you see “fetch is not defined” in older Node.js versions:
  • Upgrade to Node.js 18.7.0+ (has native fetch)
  • Or install a polyfill: npm install node-fetch
For environments without fetch, provide a custom fetch implementation:
import fetch from 'node-fetch'
import { CredentialSession } from '@atproto/api'

const session = new CredentialSession(
  new URL('https://bsky.social'),
  fetch as any
)
If you’re getting TypeScript errors:
  1. Make sure you have TypeScript installed: npm install -D typescript
  2. Check your tsconfig.json has correct settings (see above)
  3. Try setting "skipLibCheck": true in tsconfig.json
  4. Update your TypeScript version: npm install -D typescript@latest
If you have module system issues:For ESM (recommended):
  • Add "type": "module" to your package.json
  • Use .mjs extension or set "type": "module"
  • Use import statements
For CommonJS:
  • Use require() statements
  • You may need to use dynamic imports:
    const { Agent } = await import('@atproto/api')
    

Next steps

Now that you have the SDK installed:

Quickstart guide

Make your first API call and create a post

Authentication

Learn about authentication options and session management

API reference

Explore the complete API documentation

OAuth setup

Set up OAuth for production applications
Need help? Join the AT Protocol discussion forum or check the GitHub repository.

Build docs developers (and LLMs) love