AT URI と bsky.app のリンクのしくみ
開発者向けの at:// URI の文法:オーソリティ、コレクションの NSID、レコードキー、bsky.app のリンクとの対応、コードでの変換方法を解説します。
AT URI が指すもの
AT URI は、アカウントや、そのリポジトリの 1 つのレコードを指します。人が bsky.app のリンクを使う場面で、アプリや API が使うアドレスです。AT URI の仕様による文法は次のとおりです。
at://AUTHORITY/COLLECTION/RKEY- オーソリティ:アカウント。DID(
did:plc:…、did:web:…)かハンドルで書きます。レコードは DID で保存されるので、保存する URI には必ず DID を使いましょう。ハンドルは持ち主が変わることがあります。 - コレクション:レコードの種類。
app.bsky.feed.postのような NSID です。 - レコードキー(
rkey):コレクション内でのレコードの名前。多くは3l6oveex3ii2lのようなタイムスタンプ ID(TID)で、プロフィールは常にselfです。
at://did:plc:z72i7hdynmk6r22z27h6tvur はアカウント、at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post はその投稿すべてを指し、3 つめの部分で 1 つの投稿を指します。コンバーターが読むレコードには、クエリもフラグメントもありません。
bsky.app から at:// へ、そして逆へ
Bluesky アプリは 5 種類のレコードにページを用意しています。コンバーターはそれらを双方向に対応づけます。
| bsky.app のリンク | AT URI |
|---|---|
/profile/{actor} | at://{did} |
/profile/{actor}/post/{rkey} | at://{did}/app.bsky.feed.post/{rkey} |
/profile/{actor}/feed/{rkey} | at://{did}/app.bsky.feed.generator/{rkey} |
/profile/{actor}/lists/{rkey} | at://{did}/app.bsky.graph.list/{rkey} |
/starter-pack/{actor}/{rkey} | at://{did}/app.bsky.graph.starterpack/{rkey} |
{actor} はハンドルでも DID でもかまいません。bsky.app はどちらも受け付けます。DID を使ったリンクは、アカウントがハンドルを変えても切れません。ほかのコレクションのレコード(いいね、フォロー、別のアプリのレコード)には bsky.app のページがないため、コンバーターは AT URI とその各部分だけを表示します。
ハンドルを DID に変えるときは、Bluesky の AppView(com.atproto.identity.resolveHandle)に問い合わせます。ハンドルを使ったリンクを表示するときは DID ドキュメントを読み、そのハンドルが同じ DID に解決される場合だけ使います。
コードで変換する
TypeScript では、@atproto/syntax の AtUri で URI を解析・生成できます。投稿のリンクは次のように URI に変換できます。
import { AtUri } from "@atproto/syntax";
const COLLECTIONS: Record<string, string> = {
post: "app.bsky.feed.post",
feed: "app.bsky.feed.generator",
lists: "app.bsky.graph.list",
};
export function postLinkToAtUri(link: string, did: string): string {
const [, , kind, rkey] = new URL(link).pathname.split("/").filter(Boolean);
const collection = COLLECTIONS[kind];
if (!collection || !rkey) throw new Error("Not a post, feed or list link");
return AtUri.make(did, collection, rkey).toString();
}
const uri = new AtUri("at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/3l6oveex3ii2l");
uri.host; // the DID
uri.collection; // "app.bsky.feed.post"
uri.rkey; // "3l6oveex3ii2l"Python なら、AT URI は手で分割できるほど単純です。
def parse_at_uri(uri: str) -> dict:
if not uri.startswith("at://"):
raise ValueError("not an AT URI")
parts = uri[len("at://"):].split("/")
return {
"authority": parts[0],
"collection": parts[1] if len(parts) > 1 else None,
"rkey": parts[2] if len(parts) > 2 else None,
}保存する URI が使えなくならないよう、先にハンドルを DID に解決しておきましょう(resolveHandle、または DID 検索)。
API や AI エージェントから
コンバーターは GET /api/v1/tools/at-uri-converter?uri=… と MCP ツール convert_at_uri としても使えます。ツール API と MCP サーバーを参照してください。レコードキーが TID の場合は、TID デコーダーがその時刻を読み取ります。