Header menu logo FSharp.ATProto

Xrpc Module

XRPC transport layer for AT Protocol API calls. Provides functions for executing queries (HTTP GET) and procedures (HTTP POST) against an authenticated AtpAgent.

All public functions in this module automatically handle:

  • Bearer token authentication from the agent's session.
  • Automatic session refresh on 401 ExpiredToken responses (retries once with a new access token).
  • Rate-limit retry on 429 responses (waits for the Retry-After duration, then retries once).
  • JSON serialization/deserialization using .
  • Extra headers from (e.g. proxy headers).

Functions and values

Function or value Description

paginate nsid initialParams getCursor setCursor agent

Full Usage: paginate nsid initialParams getCursor setCursor agent

Parameters:
    nsid : string - The NSID of the XRPC query method (e.g. "app.bsky.feed.getTimeline").
    initialParams : 'P - The initial query parameters (typically with cursor set to None).
    getCursor : 'O -> string option - A function that extracts the next-page cursor from a response. Return None to signal that there are no more pages.
    setCursor : string option -> 'P -> 'P - A function that produces updated parameters with the given cursor value set.
    agent : AtpAgent - The AtpAgent to send requests through.

Returns: IAsyncEnumerable<Result<'O, XrpcError>> An IAsyncEnumerable that yields one Result per page. Enumeration stops when getCursor returns None or when an error occurs. On error, the error result is yielded as the final element.

Paginates through a cursor-based XRPC query, returning an IAsyncEnumerable of pages.

Each page is fetched lazily as the caller iterates the async enumerable. The underlying query function handles rate limiting and token refresh automatically.

nsid : string

The NSID of the XRPC query method (e.g. "app.bsky.feed.getTimeline").

initialParams : 'P

The initial query parameters (typically with cursor set to None).

getCursor : 'O -> string option

A function that extracts the next-page cursor from a response. Return None to signal that there are no more pages.

setCursor : string option -> 'P -> 'P

A function that produces updated parameters with the given cursor value set.

agent : AtpAgent

The AtpAgent to send requests through.

Returns: IAsyncEnumerable<Result<'O, XrpcError>>

An IAsyncEnumerable that yields one Result per page. Enumeration stops when getCursor returns None or when an error occurs. On error, the error result is yielded as the final element.

Example

 let pages = Xrpc.paginate
     "app.bsky.feed.getTimeline"
     { Limit = Some 50; Cursor = None }
     (fun output -> output.Cursor)
     (fun cursor p -> { p with Cursor = cursor })
     agent
val pages: obj
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val output: 'a
val cursor: 'a
val p: 'a

procedure nsid input agent

Full Usage: procedure nsid input agent

Parameters:
    nsid : string - The NSID of the XRPC method (e.g. "com.atproto.repo.createRecord").
    input : 'I - The input value to serialize as the JSON request body.
    agent : AtpAgent - The AtpAgent to send the request through.

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

Executes an XRPC procedure (HTTP POST) with a JSON request body and a JSON response body.

The request body is serialized as application/json using options. Automatically retries once on 429 (rate limit) after waiting for the Retry-After duration. Automatically refreshes the session and retries once on 401 ExpiredToken.

nsid : string

The NSID of the XRPC method (e.g. "com.atproto.repo.createRecord").

input : 'I

The input value to serialize as the JSON request body.

agent : AtpAgent

The AtpAgent to send the request through.

Returns: Task<Result<'O, XrpcError>>

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

Example

 let input = {| repo = did; collection = "app.bsky.feed.post"; record = post |}
 let! result = Xrpc.procedure "com.atproto.repo.createRecord" input agent
val input: {| collection: string; record: obj; repo: obj |}

procedureVoid nsid input agent

Full Usage: procedureVoid nsid input agent

Parameters:
    nsid : string - The NSID of the XRPC method (e.g. "com.atproto.repo.deleteRecord").
    input : 'I - The input value to serialize as the JSON request body.
    agent : AtpAgent - The AtpAgent to send the request through.

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

Executes an XRPC procedure (HTTP POST) with a JSON request body that returns no response body.

Use this for XRPC procedures that return 200 with no body (e.g. delete operations). The request body is serialized as application/json using options. Automatically retries once on 429 (rate limit) after waiting for the Retry-After duration. Automatically refreshes the session and retries once on 401 ExpiredToken.

nsid : string

The NSID of the XRPC method (e.g. "com.atproto.repo.deleteRecord").

input : 'I

The input value to serialize as the JSON request body.

agent : AtpAgent

The AtpAgent to send the request through.

Returns: Task<Result<unit, XrpcError>>

A Task resolving to Ok () on success, or Error with an XrpcError on failure.

query nsid parameters agent

Full Usage: query nsid parameters agent

Parameters:
    nsid : string - The NSID of the XRPC method (e.g. "app.bsky.feed.getTimeline").
    parameters : 'P - An F# record whose fields are serialized to query-string parameters via toQueryString. Option fields that are None are omitted; list fields are emitted as repeated parameters.
    agent : AtpAgent - The AtpAgent to send the request through.

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

Executes an XRPC query (HTTP GET) with query-string parameters.

Automatically retries once on 429 (rate limit) after waiting for the Retry-After duration. Automatically refreshes the session and retries once on 401 ExpiredToken.

nsid : string

The NSID of the XRPC method (e.g. "app.bsky.feed.getTimeline").

parameters : 'P

An F# record whose fields are serialized to query-string parameters via toQueryString. Option fields that are None are omitted; list fields are emitted as repeated parameters.

agent : AtpAgent

The AtpAgent to send the request through.

Returns: Task<Result<'O, XrpcError>>

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

Example

 type GetProfileParams = { Actor: string }
 let! result = Xrpc.query "app.bsky.actor.getProfile" { Actor = "my-handle.bsky.social" } agent
type GetProfileParams = { Actor: string }
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String

queryBinary nsid parameters agent

Full Usage: queryBinary nsid parameters agent

Parameters:
    nsid : string - The NSID of the XRPC method (e.g. "com.atproto.sync.getBlob").
    parameters : 'P - An F# record whose fields are serialized to query-string parameters via toQueryString.
    agent : AtpAgent - The AtpAgent to send the request through.

Returns: Task<Result<byte[], XrpcError>> A Task resolving to Ok with the raw response bytes on success, or Error with an XrpcError on failure.

Executes an XRPC query (HTTP GET) with query-string parameters that returns raw bytes instead of JSON. Used for binary endpoints such as com.atproto.sync.*.

Automatically retries once on 429 (rate limit) after waiting for the Retry-After duration. Automatically refreshes the session and retries once on 401 ExpiredToken.

nsid : string

The NSID of the XRPC method (e.g. "com.atproto.sync.getBlob").

parameters : 'P

An F# record whose fields are serialized to query-string parameters via toQueryString.

agent : AtpAgent

The AtpAgent to send the request through.

Returns: Task<Result<byte[], XrpcError>>

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

queryNoParams nsid agent

Full Usage: queryNoParams nsid agent

Parameters:
    nsid : string - The NSID of the XRPC method (e.g. "app.bsky.actor.getProfile").
    agent : AtpAgent - The AtpAgent to send the request through.

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

Executes an XRPC query (HTTP GET) with no query-string parameters.

Automatically retries once on 429 (rate limit) after waiting for the Retry-After duration. Automatically refreshes the session and retries once on 401 ExpiredToken.

nsid : string

The NSID of the XRPC method (e.g. "app.bsky.actor.getProfile").

agent : AtpAgent

The AtpAgent to send the request through.

Returns: Task<Result<'O, XrpcError>>

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

Type something to start searching.