Skip to main content
// Bluesky API

Build on Bluesky

Make your first post to the Bluesky app via the API in under 5 minutes — then keep going with the guides below.

Install a library

The examples below use TypeScript, Python, Go, and curl. These are a few of the libraries available for atproto; for other languages and the full list of community-maintained SDKs, see atproto.com/sdks.

Install @bsky/sdk and the atproto client packages using your preferred package manager.

npm install @bsky/sdk @atproto/lex @atproto/lex-password-session

Create a session

Log in with your handle and an app password to create an authentication session. (Use an app password rather than your main account password.)

import { Client } from '@atproto/lex'
import { PasswordSession } from '@atproto/lex-password-session'

const session = await PasswordSession.login({
service: 'https://bsky.social',
identifier: 'handle.example.com',
password: 'hunter2'
})
const client = new Client(session)

The com.atproto.server.createSession API endpoint returns a session object containing two API tokens:

  • accessJwt: an access token which is used to authenticate requests but expires after a few minutes
  • refreshJwt: a refresh token which lasts longer and is used only to update the session with a new access token

The session object stores this information for you (and refreshes the access token automatically), and the client will include it in the headers of its requests.

Create a post

Now you can create a post by sending a POST request to the createRecord endpoint.

import { post } from '@bsky/sdk'

await client.call(post, {
text: 'Hello world! I posted this via the API.'
})

This will return an object containing the post's URI and a CID (a hash of the content).

{
"uri": "at://did:plc:abc123..../app.bsky.feed.post/xyz...",
"cid": "abc..."
}

Check out your profile to see the post you just created!

Next Steps