Get Started
Make your first post to the Bluesky app via the API in under 5 minutes.
Install the SDK
Choose the SDK you want to work with. Below, we use TypeScript and Python. You can follow the instructions for the community-maintained atproto.dart package here.
- Typescript
- CURL
- Python
Install @atproto/api using your preferred package manager.
yarn add @atproto/api
Install CURL if you need to. It comes pre-installed on most operation systems.
Install atproto using your preferred package manager.
pip install atproto
Create a session
Create an authentication session with your username and password.
- Typescript
- CURL
- Python
import { BskyAgent } from '@atproto/api'
const agent = new BskyAgent({
service: 'https://bsky.social'
})
await agent.login({
identifier: 'handle.example.com',
password: 'hunter2'
})
Replace $BLUESKY_HANDLE
and $BLUESKY_PASSWORD
with your credentials, and $PDSHOST
with your PDS host (including https://
).
curl -X POST $PDSHOST/xrpc/com.atproto.server.createSession \
-H "Content-Type: application/json" \
-d '{"identifier": "'"$BLUESKY_HANDLE"'", "password": "'"$BLUESKY_PASSWORD"'"}'
from atproto import Client
client = Client()
client.login('handle.example.com', 'hunter2')
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 minutesrefreshJwt
: a refresh token which lasts longer and is used only to update the session with a new access token
The agent object stores this session information for you, and will include it in the headers of its requests.
The client instance stores and manages this session information for you, and 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.
- Typescript
- CURL
- Python
await agent.post({
text: 'Hello world! I posted this via the API.',
createdAt: new Date().toISOString()
})
Replace $BLUESKY_HANDLE
with your handle, $PDSHOST
with your PDS host (including https://
), and and $ACCESS_JWT
with the JWT in the response from createSession.
curl -X POST $PDSHOST/xrpc/com.atproto.repo.createRecord \
-H "Authorization: Bearer $ACCESS_JWT" \
-H "Content-Type: application/json" \
-d "{\"repo\": \"$BLUESKY_HANDLE\", \"collection\": \"app.bsky.feed.post\", \"record\": {\"text\": \"Hello world! I posted this via the API.\", \"createdAt\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}}"
post = client.send_post('Hello world! I posted this via the Python SDK.')
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..."
}
{
"uri": "at://did:plc:abc123..../app.bsky.feed.post/xyz...",
"cid": "abc..."
}
post.uri # at://did:plc:abc123..../app.bsky.feed.post/xyz...
post.cid # abc...
Check out your profile to see the post you just created!
Next Steps
- Jump to one of the Starter Templates:
- Continue reading Tutorials to learn more.