Header menu logo FSharp.ATProto

AtpAgent Module

Functions for creating and authenticating AtpAgent instances.

Functions and values

Function or value Description

configureLabelers labelers agent

Full Usage: configureLabelers labelers agent

Parameters:
    labelers : (string * bool) list - A list of labeler DIDs and optional redact flags. Each entry is a tuple of (labeler DID string, redact flag). When redact=true, the labeler's labels can cause content to be entirely removed from responses.
    agent : AtpAgent - The agent to copy with labeler configuration.

Returns: AtpAgent A new AtpAgent with the atproto-accept-labelers header.

Returns a copy of the agent configured with the atproto-accept-labelers header. This tells the server which labeler services to include labels from in responses.

The header format follows IETF RFC-8941 Structured Field Values: did:plc:abc123;redact, did:plc:def456

labelers : (string * bool) list

A list of labeler DIDs and optional redact flags. Each entry is a tuple of (labeler DID string, redact flag). When redact=true, the labeler's labels can cause content to be entirely removed from responses.

agent : AtpAgent

The agent to copy with labeler configuration.

Returns: AtpAgent

A new AtpAgent with the atproto-accept-labelers header.

create baseUrl

Full Usage: create baseUrl

Parameters:
    baseUrl : string - The PDS base URL (e.g. "https://bsky.social"). A trailing slash is appended if not present.

Returns: AtpAgent An unauthenticated AtpAgent ready for login.

Creates a new unauthenticated agent pointing at the given PDS base URL. A new HttpClient is allocated internally.

baseUrl : string

The PDS base URL (e.g. "https://bsky.social"). A trailing slash is appended if not present.

Returns: AtpAgent

An unauthenticated AtpAgent ready for login.

Example

 let agent = AtpAgent.create "https://bsky.social"
val agent: obj

createWithClient httpClient baseUrl

Full Usage: createWithClient httpClient baseUrl

Parameters:
    httpClient : HttpClient - The HTTP client to use for all requests.
    baseUrl : string - The PDS base URL (e.g. "https://bsky.social"). A trailing slash is appended if not present.

Returns: AtpAgent An unauthenticated AtpAgent using the provided HTTP client.

Creates a new unauthenticated agent with a caller-supplied HttpClient. Useful for testing with mock HTTP handlers or custom client configuration.

httpClient : HttpClient

The HTTP client to use for all requests.

baseUrl : string

The PDS base URL (e.g. "https://bsky.social"). A trailing slash is appended if not present.

Returns: AtpAgent

An unauthenticated AtpAgent using the provided HTTP client.

Example

 let handler = new MockHttpMessageHandler()
 let client = new HttpClient(handler)
 let agent = AtpAgent.createWithClient client "https://bsky.social"
val handler: obj
val client: obj
val agent: obj

login identifier password agent

Full Usage: login identifier password agent

Parameters:
    identifier : string - A handle (e.g. "my-handle.bsky.social") or DID (e.g. "did:plc:xyz123").
    password : string - An app password (not the account password).
    agent : AtpAgent - The agent to authenticate.

Returns: Task<Result<AtpSession, XrpcError>> A Task resolving to Ok with the AtpSession on success, or Error with an XrpcError on failure.

Logs in to a PDS with an identifier and app password. On success, stores the session on the agent for subsequent authenticated requests.

Calls the com.atproto.server.createSession XRPC procedure. The session is stored mutably on the agent's Session field. All subsequent XRPC calls through this agent will include the access token automatically.

identifier : string

A handle (e.g. "my-handle.bsky.social") or DID (e.g. "did:plc:xyz123").

password : string

An app password (not the account password).

agent : AtpAgent

The agent to authenticate.

Returns: Task<Result<AtpSession, XrpcError>>

A Task resolving to Ok with the AtpSession on success, or Error with an XrpcError on failure.

Example

 let agent = AtpAgent.create "https://bsky.social"
 let! result = AtpAgent.login "my-handle.bsky.social" "app-password" agent
 match result with
 | Ok session -> printfn "Logged in as %s" session.Handle
 | Error e -> printfn "Login failed: %A" e.Message
val agent: obj
union case Result.Ok: ResultValue: 'T -> Result<'T,'TError>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
union case Result.Error: ErrorValue: 'TError -> Result<'T,'TError>

withChatProxy agent

Full Usage: withChatProxy agent

Parameters:
    agent : AtpAgent - The agent to copy with chat proxy configuration.

Returns: AtpAgent A new AtpAgent with the chat proxy header prepended to ExtraHeaders.

Returns a copy of the agent configured to proxy requests through the Bluesky Chat service. Adds the atproto-proxy: did:web:api.bsky.chat#bsky_chat header.

The returned agent shares the same HttpClient as the original but has an independent Session field (it is a record copy). If you need chat functionality, prefer using the Chat module functions directly — they handle the proxy header automatically and always use the current session from the original agent.

agent : AtpAgent

The agent to copy with chat proxy configuration.

Returns: AtpAgent

A new AtpAgent with the chat proxy header prepended to ExtraHeaders.

Type something to start searching.