Skip to main content
The Agent API is the primary interface for interacting with AT Protocol servers. It provides a comprehensive set of methods for creating posts, managing profiles, following users, and much more.

Understanding the Agent

The Agent class extends the XRPC client with AT Protocol-specific functionality and Bluesky syntactic sugar. It handles authentication, request signing, and provides convenient methods for common operations.
The agent requires a session manager, which can be:
  • A CredentialSession for app password authentication (deprecated)
  • An OAuthSession from the OAuth client (recommended)
  • A custom SessionManager implementation
App password authentication is deprecated. Use OAuth-based authentication for production applications. See the OAuth authentication guide.

Core Concepts

Session Management

Every agent is backed by a session manager that handles authentication state:

Labelers Configuration

Labelers provide moderation labels for content. Configure which labelers the agent uses:

Proxy Configuration

Route requests through a proxy service:

Working with Posts

Creating Posts

Create posts using the post() method:
The createdAt field is required and must be an ISO 8601 timestamp.

Posts with Rich Text

Use the RichText class to handle mentions, links, and other facets:
See the Rich Text guide for more details.

Posts with Media

Upload images and embed them in posts:

Deleting Posts

Delete a post using its URI:

Reading Feeds and Posts

Getting the Timeline

Retrieve the authenticated user’s timeline:

Getting an Author’s Feed

Retrieve posts from a specific user:

Getting Post Threads

Retrieve a post and its replies:

Getting Multiple Posts

Fetch multiple posts by URI:

Social Graph Operations

Following Users

Follow a user:

Unfollowing Users

Getting Followers

Getting Follows

Engagement Actions

Liking Posts

Unliking Posts

Reposting

Deleting Reposts

Profile Management

Getting Profiles

Get a single profile:
Get multiple profiles:

Updating Your Profile

Use upsertProfile to safely update your profile:
The upsertProfile method:
  • Fetches the current profile
  • Passes it to your callback function
  • Creates or updates the profile record
  • Handles CAS (Compare-And-Swap) conflicts automatically
upsertProfile automatically retries on conflicts, but will fail after too many attempts to prevent infinite loops.

Notifications

Listing Notifications

Counting Unread Notifications

Marking Notifications as Seen

Searching for Users

For autocomplete functionality:

Moderation

Muting Users

Unmuting Users

Blocking Users

Blocking is done by creating a block record:

Advanced Usage

Direct XRPC Calls

For methods not wrapped by convenience functions, use the namespaced API:

Custom Headers

Set custom headers for requests:

Cloning Agents

Create a copy of an agent with the same configuration:

Error Handling

Handle errors from API calls:

Best Practices

1

Use OAuth authentication

Always use OAuth-based sessions in production rather than app passwords for better security and token management.
2

Handle pagination

Use cursors properly when fetching large datasets to avoid missing items.
3

Validate input

Validate user input before creating records, especially for rich text.
4

Handle rate limits

Implement exponential backoff when hitting rate limits.

Common Pitfalls

Forgetting createdAt: All records require a createdAt timestamp. Always include it:
Not handling mentions properly: Always call detectFacets() to resolve mentions to DIDs:
Using handles instead of DIDs: For persistent references, always use DIDs, not handles (handles can change):

Next Steps

OAuth Authentication

Implement secure OAuth-based authentication

Rich Text

Work with mentions, links, and formatted text

Moderation

Implement content moderation in your app

API Reference

Explore the complete API reference