@atproto/api session refactor: BskyAgent deprecated, some session hooks removed
What changed
On August 12, 2024 the Bluesky team merged an auth refactor of @atproto/api to prepare it for OAuth sessions. App password login keeps working. A new abstract Agent class sits above AtpAgent, BskyAgent is deprecated, the fetch property can no longer be set after construction, setSessionPersistHandler is gone, AtpBaseClient was removed and AtpServiceClient renamed to it, and fetch, Request and Headers must be available globally. The refactor also fixed a bug that could invalidate session data when agents were cloned.
What it means
Tools built on the TypeScript @atproto/api package keep working with app passwords for now, but code that customised fetch, used setSessionPersistHandler or extended BskyAgent breaks or is deprecated on upgrade.
Who is affected
Developers of Bluesky posting, scheduling and bot tools written in TypeScript or JavaScript with @atproto/api or @atproto/xrpc.
What to do by 12 Aug 2024
Type agents as Agent, create them with AtpAgent, pass persistSession and any custom fetch in the constructor, replace BskyAgent and default imports with named exports, and make sure fetch, Request and Headers exist globally.
What this means for you
Many Bluesky apps are built with a free code toolkit that Bluesky publishes. In August 2024 Bluesky changed how that toolkit keeps you logged in, to get ready for a safer login method. If you only use apps, you notice nothing. App makers who update the toolkit may have to change some code, or logins in their app can break.
The details
- Why: make
@atproto/apicompatible with OAuth session management. The post says you "can keep using the current app password authentication system" until OAuth launches; see AT Protocol publishes its OAuth specification. - New class layout:
XrpcClientis the base,AtpBaseClientextends it, the abstractAgentextends that,AtpAgentadds password sessions, andBskyAgentextendsAtpAgentwith nothing new. UseAgentas the type you accept andAtpAgentonly to create one. - Breaking: setting the
fetchproperty after creation now throws (it is read only asfetchHandler);fetch(),RequestandHeadersmust be global, so add a polyfill if needed;AtpBaseClientwas removed andAtpServiceClientrenamed toAtpBaseClient;setSessionPersistHandleris gone, use thepersistSessionconstructor option. - Deprecated: the default exports of
@atproto/apiand@atproto/xrpc, theClientandServiceClientclasses (useXrpcClient),BskyAgent(useAtpAgent), and thexrpcandapiproperties (use the instance itself). - Client-side rate limiting: instead of patching
agent.api.xrpc.call, wrap thefetchyou pass to theAtpAgentconstructor. - Fix: a bug that could make session data invalid when cloning agents, for example with
agent.withProxy(). - Source note: the post was on docs.bsky.app, which now redirects to bsky.network and no longer serves it. The text is in Bluesky's own
bluesky-social/bsky-docsrepository.
What to do next
- Business owners: Nothing.
- Marketers and agencies: Nothing, unless your Bluesky tool logs you out after an update; tell the vendor.
- Developers: Move to
AgentandAtpAgent, setpersistSessionandfetchin the constructor, drop default imports, and test session refresh after upgrading.
Primary sources
Get an email when a new API change is added
Follow new entries with the RSS feed. Each platform also has its own feed, for example X or Meta.