Skip to content

openagents_sdk

Public OpenAgents HTTP client. Authentication is supplied explicitly; this client never adopts CLI credentials, launches a browser, or loads a host.

ItemWhat it does
Account structA signed-in account: its ID, display label, and optional email and avatar.
AccountView structThe account and its current workspaces, as [`Client::account`] returns them.
Client structA bounded client for one deployment that refuses redirects.
CredentialRecord structExplicit persistence payload.
CredentialStore traitCaller-owned persistence.
Deployment structThe two explicit addresses belonging to one deployment.
Error enumError diagnostics omit response bodies, credential values, request URLs, and the HTTP 402 headers available through the explicit accessor.
EventTemplate structAn unsigned NIP-01 event for the signer to complete with `id`, `pubkey`, and `sig`.
KeySignIn structA completed key sign-in.
LinkedKey structOne of the account's keys.
Login structA single login attempt.
NostrSigner traitSigns events with the caller's key.
PaymentRequired structAn untrusted `PAYMENT-REQUIRED` header from an HTTP 402 response.
PaymentRequiredHeaderError enumWhy an HTTP 402 did not supply one usable text header.
Poll enumThe result of one login poll: keep waiting, slow down, or signed in.
ScannedLogin structA website login the phone scanned.
ScannedLoginAbout structWhich browser a scanned login is for.
ScannedLoginApproved structAn approved website login.
Session structAn authenticated account, bound to its exact API/website pair.
SignerError structWhy a signer didn't sign.
StorageError enumWhy a credential store couldn't load, save, or clear a login.
Workspace structA workspace the account belongs to, with the account's role in it.
solve_pow fnSolve the sign-up proof of work over `challenge`: the first counter, in decimal, whose `SHA-256(challenge ":" counter)` starts with `bits` zero bits.
DELETE_ACCOUNT_CONFIRM constThe words `DELETE /v1/account` asks for, sent after the person confirms in the app.
HTTP_AUTH_KIND constThe NIP-98 HTTP authorization kind.
KEY_BODY_MAX constThe largest sign-in body the server takes (`oa_auth::nostr::BODY_MAX`).
MAX_PAYMENT_REQUIRED_HEADER_BYTES constThe same encoded-header limit used by the existing x402 HTTP codec.
POW_BITS constThe proof-of-work difficulty a new key's first sign-in needs by default (#11994): leading zero bits of `SHA-256(challenge ":" solution)`.

Account

pub struct Account {
    pub id: String,
    pub label: String,
    pub email: Option<String>,
    pub avatar_url: Option<String>,
}

A signed-in account: its ID, display label, and optional email and avatar.

AccountView

pub struct AccountView {
    pub account: Account,
    pub workspaces: Vec<Workspace>,
}

The account and its current workspaces, as [Client::account] returns them.

Client

pub struct Client {}

A bounded client for one deployment that refuses redirects. Auth and history send once; the Computers facade applies its own operation-specific retry policy.

Client::new

pub fn new(deployment: Deployment) -> Result<Self, Error>

Creates a client for deployment with a 20-second request timeout.

Client::with_timeout

pub fn with_timeout(deployment: Deployment, timeout: Duration) -> Result<Self, Error>

Creates a client with a request timeout of timeout. The connection timeout is the shorter of timeout and 10 seconds.

Client::with_timeouts

pub fn with_timeouts(
    deployment: Deployment,
    connect_timeout: Duration,
    timeout: Duration,
) -> Result<Self, Error>

Creates a client with separate connection and request timeouts. Refuses a timeout that is zero or over two minutes, or a connection timeout longer than the request timeout.

Client::with_test_run

pub fn with_test_run(
    deployment: Deployment,
    timeout: Duration,
    test_run: bool,
) -> Result<Self, Error>

Mark requests made by an explicitly identified test run. This option reads no environment variables and does not change the credential.

Client::deployment

pub fn deployment(&self) -> &Deployment

The deployment this client talks to.

CredentialRecord

pub struct CredentialRecord {}

Explicit persistence payload. Serialize only into the application's credential store.

CredentialRecord::deployment

pub fn deployment(&self) -> &Deployment

The deployment this record belongs to.

CredentialRecord::account

pub fn account(&self) -> &Account

The account this record signs in.

CredentialRecord::expires_at

pub fn expires_at(&self) -> Option<u64>

When the credential expires, in Unix seconds, or None when it has no set expiry.

CredentialRecord::expired

pub fn expired(&self, now: u64) -> bool

Whether the credential has expired at now, in Unix seconds.

CredentialStore

pub trait CredentialStore {
    fn load(
        &self,
        deployment: &Deployment,
    ) -> Result<Option<CredentialRecord>, StorageError>;
    fn save(&self, record: &CredentialRecord) -> Result<(), StorageError>;
    fn clear(&self, deployment: &Deployment) -> Result<(), StorageError>;
}

Caller-owned persistence. Implement with Keychain, another OS store, or memory.

CredentialStore::load

fn load(
    &self,
    deployment: &Deployment,
) -> Result<Option<CredentialRecord>, StorageError>

Loads the login saved for deployment, if there is one.

CredentialStore::save

fn save(&self, record: &CredentialRecord) -> Result<(), StorageError>

Saves record, replacing any login saved for its deployment.

CredentialStore::clear

fn clear(&self, deployment: &Deployment) -> Result<(), StorageError>

Removes the login saved for deployment.

Deployment

pub struct Deployment {}

The two explicit addresses belonging to one deployment.

Deployment::new

pub fn new(api_base: &str, website: &str) -> Result<Self, Error>

Creates a deployment from its API base, such as https://api.openagents.com/v1, and its website address. Refuses an address that isn't HTTPS, except HTTP to this computer.

Deployment::production

pub fn production() -> Self

The OpenAgents production deployment.

Deployment::api_base

pub fn api_base(&self) -> &Url

The API base address, ending in /v1/.

Deployment::website

pub fn website(&self) -> &Url

The website address.

Error

pub enum Error {
    InvalidDeployment,
    InvalidTimeout,
    InvalidCredential,
    WrongDeployment,
    WrongAccount,
    ExpiredSession,
    Unauthorized,
    Forbidden,
    Denied,
    KeyDenied,
    ExpiredLogin,
    FinishedLogin,
    Cancelled,
    UncertainLogin(Box<Error>),
    Network { timeout: bool },
    InvalidResponse,
    NotFound,
    Changed,
    InvalidCursor,
    InvalidReference,
    TooLarge,
    Redirect,
    PaymentRequired(crate::PaymentRequired),
    RateLimited { retry_after: Option<Duration> },
    Unavailable { retry_after: Option<Duration> },
    Refused { status: u16, code: Option<&'static str> },
}

Error diagnostics omit response bodies, credential values, request URLs, and the HTTP 402 headers available through the explicit accessor.

Error::payment_required

pub fn payment_required(&self) -> Option<&crate::PaymentRequired>

The HTTP 402 challenge, when this error is a payment request.

EventTemplate

pub struct EventTemplate {
    pub created_at: u64,
    pub kind: u16,
    pub tags: Vec<Vec<String>>,
    pub content: String,
}

An unsigned NIP-01 event for the signer to complete with id, pubkey, and sig.

KeySignIn

pub struct KeySignIn {
    pub session: Session,
    pub created: bool,
    pub pubkey: String,
}

A completed key sign-in.

LinkedKey

pub struct LinkedKey {
    pub pubkey: String,
    pub npub: String,
}

One of the account's keys.

Login

pub struct Login {}

A single login attempt. Drop or cancel it to stop waiting; no credential is saved.

Login::user_code

pub fn user_code(&self) -> &str

The code the person confirms on the website.

Login::verification_url

pub fn verification_url(&self) -> &Url

A validated URL on this deployment's website, suitable for a system browser.

Login::expires_in

pub fn expires_in(&self) -> Duration

The time left before this login code expires.

Login::next_poll_in

pub fn next_poll_in(&self) -> Duration

The time to wait before the next poll.

Login::cancel

pub fn cancel(&mut self)

Stops this login. Later polls return Error::FinishedLogin.

NostrSigner

pub trait NostrSigner: Send + Sync {
    fn sign_event(&self, template: &EventTemplate) -> Result<String, SignerError>;
}

Signs events with the caller's key. The SDK only asks for signatures.

NostrSigner::sign_event

fn sign_event(&self, template: &EventTemplate) -> Result<String, SignerError>

Sign template, answering the complete event as NIP-01 JSON ({"id", "pubkey", "created_at", "kind", "tags", "content", "sig"}).

PaymentRequired

pub struct PaymentRequired {}

An untrusted PAYMENT-REQUIRED header from an HTTP 402 response.

The SDK preserves the header without parsing, paying, or following any URL it contains. An application must validate the offer, invoice, and actual request through its separately authorized payment integration before spending. Debug output omits the header, which can contain private request details.

PaymentRequired::header

pub fn header(&self) -> Result<&str, PaymentRequiredHeaderError>

The exact text header value, without decoding or offer validation. Missing, repeated, oversized, or non-text headers remain typed HTTP 402 errors, but their contents are not retained.

PaymentRequiredHeaderError

pub enum PaymentRequiredHeaderError {
    Missing,
    Repeated,
    TooLarge,
    InvalidText,
}

Why an HTTP 402 did not supply one usable text header.

Poll

pub enum Poll {
    Pending { retry_after: Duration },
    SlowDown { retry_after: Duration },
    SignedIn(Session),
}

The result of one login poll: keep waiting, slow down, or signed in.

ScannedLogin

pub struct ScannedLogin {
    pub origin: String,
}

A website login the phone scanned. The challenge is a one-time capability: never log it.

ScannedLogin::parse

pub fn parse(text: &str) -> Option<Self>

Read a scanned code, or None when it isn't a website login.

ScannedLoginAbout

pub struct ScannedLoginAbout {
    pub browser: String,
    pub expires_at: u64,
}

Which browser a scanned login is for.

ScannedLoginApproved

pub struct ScannedLoginApproved {
    pub browser: String,
    pub created: bool,
}

An approved website login.

Session

pub struct Session {}

An authenticated account, bound to its exact API/website pair.

Session::account

pub fn account(&self) -> &Account

The signed-in account.

Session::expires_at

pub fn expires_at(&self) -> Option<u64>

When the session expires, in Unix seconds, or None when it has no set expiry.

Session::deployment

pub fn deployment(&self) -> &Deployment

The deployment this session belongs to.

Session::record

pub fn record(&self) -> CredentialRecord

Export for explicit storage; the client never saves it by itself.

Session::bearer_token

pub fn bearer_token(&self) -> &str

Bearer for an explicitly configured OpenAgents service, such as Coder sync. Keep it out of logs and ordinary application files.

SignerError

pub struct SignerError;

Why a signer didn't sign.

StorageError

pub enum StorageError {
    Denied,
    Unavailable,
}

Why a credential store couldn't load, save, or clear a login.

Workspace

pub struct Workspace {
    pub id: String,
    pub name: String,
    pub role: String,
    pub kind: String,
    pub tenant: String,
}

A workspace the account belongs to, with the account's role in it.

solve_pow

pub fn solve_pow(challenge: &str, bits: u8) -> String

Solve the sign-up proof of work over challenge: the first counter, in decimal, whose SHA-256(challenge ":" counter) starts with bits zero bits. About a million hashes at 20 bits: run it off the UI thread.

DELETE_ACCOUNT_CONFIRM

pub const DELETE_ACCOUNT_CONFIRM: &str = "delete my account";

The words DELETE /v1/account asks for, sent after the person confirms in the app.

HTTP_AUTH_KIND

pub const HTTP_AUTH_KIND: u16 = 27_235;

The NIP-98 HTTP authorization kind.

KEY_BODY_MAX

pub const KEY_BODY_MAX: usize = 16 * 1024;

The largest sign-in body the server takes (oa_auth::nostr::BODY_MAX).

MAX_PAYMENT_REQUIRED_HEADER_BYTES

pub const MAX_PAYMENT_REQUIRED_HEADER_BYTES: usize = 64 * 1024;

The same encoded-header limit used by the existing x402 HTTP codec.

POW_BITS

pub const POW_BITS: u8 = 20;

The proof-of-work difficulty a new key's first sign-in needs by default (#11994): leading zero bits of SHA-256(challenge ":" solution).

Re-exported from other crates

  • CancellationToken from tokio_util::sync