diff --git a/changelog.mdx b/changelog.mdx
index 5358870da..567745d90 100644
--- a/changelog.mdx
+++ b/changelog.mdx
@@ -8,14 +8,14 @@ keywords: ["changelog", "API updates", "release notes", "what's new", "API chang
To subscribe to updates, please [**“Turn on notifications”**](https://help.x.com/en/managing-your-account/notifications-on-mobile-devices#:~:text=In%20the%20top%20menu,%20you,you%20would%20like%20to%20receive) for [**@API**](https://x.com/api). You can also follow this changelog in your feed reader via the [**RSS feed**](https://docs.x.com/changelog/rss.xml).
- ### Ruby bindings for Chat XDK (`chat_xdk`)
+ ### Official Ruby XDK (`xdk`) and Ruby Chat XDK (`chat_xdk`)
- Official **Ruby** bindings for the X Chat encryption SDK are now available as the [`chat_xdk`](https://rubygems.org/gems/chat_xdk) gem (Ruby 3.0+):
+ Both official **Ruby** libraries (Ruby 3.0+) are now live on RubyGems:
- - **Prebuilt native libraries:** Platform gems bundle `libchat_xdk_ffi` for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`) with no Rust toolchain required.
- - **Full API parity:** Key generation, Juicebox PIN-backed storage (`setup` / `unlock`), raw key export/import (`export_keys` / `import_keys`), batch and single-event decryption (`decrypt_events` / `decrypt_event`), automatic public-key resolution (`set_resolve_public_keys`), message and file encryption, and signed group/conversation actions.
+ - **Ruby XDK ([`xdk`](https://rubygems.org/gems/xdk) `0.1.0`):** Official X API v2 client with zero runtime dependencies (stdlib `net/http`), full v2 resource coverage (including `/2/chat/*`), Bearer Token / OAuth 2.0 PKCE / OAuth 1.0a authentication, lazy `Enumerator` pagination, and real-time streaming with keep-alive callbacks and idle-timeout recovery. See [Ruby XDK](/xdks/ruby/overview) and [xdevplatform/xdk-ruby](https://github.com/xdevplatform/xdk-ruby).
+ - **Ruby Chat XDK ([`chat_xdk`](https://rubygems.org/gems/chat_xdk) `0.7.10`):** End-to-end encryption SDK for X Chat DMs bundling `libchat_xdk_ffi` for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`). See [Chat XDK](/xchat/xchat-xdk) and [`chat-xdk/examples/ruby`](https://github.com/xdevplatform/chat-xdk/tree/main/examples/ruby).
- Install with `gem install chat_xdk` and see [Chat XDK](/xchat/xchat-xdk) and [`chat-xdk/examples/ruby`](https://github.com/xdevplatform/chat-xdk/tree/main/examples/ruby).
+ Install both with `gem install xdk chat_xdk`.
diff --git a/docs.json b/docs.json
index f9cc6b0c8..79e74af23 100644
--- a/docs.json
+++ b/docs.json
@@ -1292,6 +1292,24 @@
]
}
]
+ },
+ {
+ "dropdown": "Ruby",
+ "description": "xdk gem",
+ "icon": "gem",
+ "groups": [
+ {
+ "group": "Guides",
+ "pages": [
+ "xdks/ruby/overview",
+ "xdks/ruby/install",
+ "xdks/ruby/quickstart",
+ "xdks/ruby/authentication",
+ "xdks/ruby/pagination",
+ "xdks/ruby/streaming"
+ ]
+ }
+ ]
}
]
},
diff --git a/xchat/getting-started.mdx b/xchat/getting-started.mdx
index 069c03f0f..3959a1029 100644
--- a/xchat/getting-started.mdx
+++ b/xchat/getting-started.mdx
@@ -12,7 +12,7 @@ X Chat apps use two pieces together:
| Component | Role |
|:----------|:-----|
| **[Chat XDK](/xchat/xchat-xdk)** | Encryption, decryption, signing, and private key storage (secure key backup or a key blob) |
-| **X API** | Public keys, conversation keys, messages, and events: via the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), or [C#](/xdks/csharp/overview) XDK, or HTTPS with a user access token |
+| **X API** | Public keys, conversation keys, messages, and events: via the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview), or [Ruby](/xdks/ruby/overview) XDK, or HTTPS with a user access token |
**Prerequisites**
@@ -84,10 +84,10 @@ X Chat apps use two pieces together:
```bash
- gem install chat_xdk
+ gem install chat_xdk xdk
```
- Available on RubyGems. Published platform gems bundle the native library for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`). Import with `require "chat_xdk"`. Requires Ruby 3.0+.
+ Available on RubyGems. `chat_xdk` platform gems bundle the native library for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`), and `xdk` has zero runtime dependencies. Requires Ruby 3.0+.
diff --git a/xchat/introduction.mdx b/xchat/introduction.mdx
index 9a4c378bc..3bcd1f549 100644
--- a/xchat/introduction.mdx
+++ b/xchat/introduction.mdx
@@ -14,7 +14,7 @@ The **X Chat API** lets you send and receive **encrypted** direct messages on X.
| Piece | Responsibility |
|:------|:---------------|
| **[Chat XDK](/xchat/xchat-xdk)** | Generate keys, encrypt/decrypt, sign/verify, optional passcode-protected secure key backup (Python, JS, Rust, Go, C#, Java, Ruby) |
-| **X API access** | Public keys, conversation keys, messages, events, media: via **[XDK](/xdks/overview)** ([Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview)) or HTTPS |
+| **X API access** | Public keys, conversation keys, messages, events, media: via **[XDK](/xdks/overview)** ([Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview), [Ruby](/xdks/ruby/overview)) or HTTPS |
| **Delivery** | [Webhooks or activity stream](/xchat/real-time-events) for live events; events API for history |
Follow **[Getting Started](/xchat/getting-started)** for a full implementation. For concepts only, see the **[Cryptography primer](/xchat/cryptography-primer)**.
diff --git a/xchat/xchat-xdk.mdx b/xchat/xchat-xdk.mdx
index 56f4c30c8..4dec4aa83 100644
--- a/xchat/xchat-xdk.mdx
+++ b/xchat/xchat-xdk.mdx
@@ -5,7 +5,7 @@ description: "Meet the Chat XDK, the library that handles keys, encryption, decr
keywords: ["Chat XDK", "chat-xdk", "encryption SDK", "key management", "signing", "SDK reference"]
---
-The **Chat XDK** handles key management, encryption, decryption, and signing for X Chat. It does **not** call the X HTTP API: pair it with the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), or [C#](/xdks/csharp/overview) **XDK**, or with HTTPS and a user access token.
+The **Chat XDK** handles key management, encryption, decryption, and signing for X Chat. It does **not** call the X HTTP API: pair it with the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview), or [Ruby](/xdks/ruby/overview) **XDK**, or with HTTPS and a user access token.
App walkthrough: [Getting Started](/xchat/getting-started). Sample bots: [chat-xdk/examples](https://github.com/xdevplatform/chat-xdk/tree/main/examples).
diff --git a/xdks/overview.mdx b/xdks/overview.mdx
index 41752cc2b..7abe48aee 100644
--- a/xdks/overview.mdx
+++ b/xdks/overview.mdx
@@ -1,8 +1,8 @@
---
title: XDKs
sidebarTitle: All SDKs
-description: Official client libraries for the X API v2 in Python, TypeScript, Java, and C#.
-keywords: ["XDK", "X SDK", "Python SDK", "TypeScript SDK", "Java SDK", "C# SDK", ".NET SDK", "X API v2", "client libraries"]
+description: Official client libraries for the X API v2 in Python, TypeScript, Java, C#, and Ruby.
+keywords: ["XDK", "X SDK", "Python SDK", "TypeScript SDK", "Java SDK", "C# SDK", ".NET SDK", "Ruby SDK", "X API v2", "client libraries"]
---
The X Developer Kits (XDKs) are X's client libraries for the X API v2, generated from the [X API OpenAPI spec](https://api.x.com/2/openapi.json).
@@ -20,6 +20,9 @@ The X Developer Kits (XDKs) are X's client libraries for the X API v2, generated
`dotnet add package XDevPlatform.Xdk` · .NET 8+
+
+ `gem install xdk` · Ruby 3.0+
+
---
@@ -32,6 +35,7 @@ The X Developer Kits (XDKs) are X's client libraries for the X API v2, generated
| **TypeScript / JS** | `@xdevplatform/xdk` | Node.js 18+ | [npm](https://www.npmjs.com/package/@xdevplatform/xdk) | [xdk-typescript](https://github.com/xdevplatform/xdk-typescript) |
| **Java** | `com.x:xdk:0.4.0` | Java 8+ | [Maven Central](https://central.sonatype.com/artifact/com.x/xdk) | [xdk-java](https://github.com/xdevplatform/xdk-java) |
| **C# / .NET** | `XDevPlatform.Xdk` | .NET 8.0+ | [NuGet](https://www.nuget.org/packages/XDevPlatform.Xdk) | [xdk-csharp](https://github.com/xdevplatform/xdk-csharp) |
+| **Ruby** | `xdk` | Ruby 3.0+ | [RubyGems](https://rubygems.org/gems/xdk) | [xdk-ruby](https://github.com/xdevplatform/xdk-ruby) |
---
@@ -121,6 +125,22 @@ var response = await client.Users.GetByUsernameAsync(
UserFields = new List { "created_at", "public_metrics" },
});
Console.WriteLine(response.Data);
+```
+
+
+```bash
+gem install xdk
+```
+
+```ruby
+require "xdk"
+
+client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))
+response = client.users.get_by_username(
+ username: "XDevelopers",
+ user_fields: %w[created_at public_metrics]
+)
+puts response["data"]
```
@@ -131,9 +151,9 @@ Console.WriteLine(response.Data);
- **Typed clients** — One sub-client per X API v2 resource (`posts`, `users`, `stream`, `direct_messages`, `spaces`, `lists`, `media`, `webhooks`, `chat`, and more).
- **Authentication** — Bearer Token, OAuth 2.0 with PKCE and token refresh, and OAuth 1.0a.
-- **Pagination** — Cursor handling via Python generators, TypeScript `Paginator`, Java `Paginator`, and C# `IAsyncEnumerable`.
+- **Pagination** — Cursor handling via Python generators, TypeScript `Paginator`, Java `Paginator`, C# `IAsyncEnumerable`, and Ruby `Enumerator`.
- **Streaming** — Live event streams for Filtered Stream, Sample Streams, Firehose, Compliance, and Activity.
-For encrypted X Chat messages, see the [Chat XDK](/xchat/xchat-xdk) (Python, TypeScript, Java, C#, Go, and Rust).
+For encrypted X Chat messages, see the [Chat XDK](/xchat/xchat-xdk) (Python, TypeScript, Java, C#, Ruby, Go, and Rust).
diff --git a/xdks/ruby/authentication.mdx b/xdks/ruby/authentication.mdx
new file mode 100644
index 000000000..7a4b29b02
--- /dev/null
+++ b/xdks/ruby/authentication.mdx
@@ -0,0 +1,70 @@
+---
+title: Authentication in Ruby XDK
+sidebarTitle: Authentication
+description: Configure Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a authentication with the Ruby XDK.
+keywords: ["Ruby XDK auth", "OAuth 2.0 PKCE Ruby", "OAuth 1.0a Ruby", "Bearer Token Ruby"]
+---
+
+`Xdk::Client` supports all three X API authentication schemes and automatically chooses the appropriate header for each endpoint (preferring user context on write endpoints and Bearer Token on read endpoints when multiple credentials are supplied).
+
+## Bearer Token (App-Only)
+
+```ruby
+client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))
+```
+
+## OAuth 2.0 User Context (PKCE)
+
+### With an existing user access token
+
+```ruby
+client = Xdk::Client.new(access_token: ENV.fetch("X_ACCESS_TOKEN"))
+```
+
+### Full PKCE authorization & refresh flow
+
+```ruby
+client = Xdk::Client.new(
+ client_id: ENV.fetch("X_CLIENT_ID"),
+ client_secret: ENV["X_CLIENT_SECRET"], # omit for public clients
+ redirect_uri: "http://localhost:8080/callback",
+ scope: %w[tweet.read tweet.write users.read dm.read dm.write offline.access]
+)
+
+# 1. Redirect user to the authorization URL
+auth_url = client.get_authorization_url(state: "csrf-state")
+
+# 2. Exchange the authorization code returned to your callback
+token = client.exchange_code(params[:code])
+
+# 3. Refresh when expired (the client also refreshes automatically before requests)
+token = client.refresh_token if client.token_expired?
+```
+
+## OAuth 1.0a (HMAC-SHA1)
+
+```ruby
+oauth1 = Xdk::OAuth1.new(
+ api_key: ENV.fetch("X_API_KEY"),
+ api_secret: ENV.fetch("X_API_SECRET"),
+ access_token: ENV.fetch("X_ACCESS_TOKEN"),
+ access_token_secret: ENV.fetch("X_ACCESS_TOKEN_SECRET")
+)
+
+client = Xdk::Client.new(auth: oauth1)
+```
+
+For 3-legged OAuth 1.0a login:
+
+```ruby
+oauth1 = Xdk::OAuth1.new(
+ api_key: ENV.fetch("X_API_KEY"),
+ api_secret: ENV.fetch("X_API_SECRET"),
+ callback: "http://localhost:8080/callback"
+)
+
+oauth1.get_request_token
+redirect_url = oauth1.get_authorization_url
+# After callback with oauth_verifier:
+oauth1.get_access_token(verifier)
+```
diff --git a/xdks/ruby/install.mdx b/xdks/ruby/install.mdx
new file mode 100644
index 000000000..60205e020
--- /dev/null
+++ b/xdks/ruby/install.mdx
@@ -0,0 +1,44 @@
+---
+title: Install Ruby XDK
+sidebarTitle: Install
+description: Install the official Ruby XDK (xdk) gem from RubyGems.
+keywords: ["xdk", "gem install xdk", "Ruby XDK install"]
+---
+
+## Requirements
+
+- **Ruby 3.0+**
+- No runtime gem dependencies (uses Ruby's built-in `net/http`, `openssl`, and `json` standard library)
+
+## RubyGems
+
+```bash
+gem install xdk
+```
+
+## Bundler (`Gemfile`)
+
+```ruby
+gem "xdk"
+```
+
+Then run:
+
+```bash
+bundle install
+```
+
+## Encrypted X Chat DMs (optional)
+
+If your app uses the encrypted [X Chat API](/xchat/introduction), install the companion `chat_xdk` encryption gem as well:
+
+```bash
+gem install xdk chat_xdk
+```
+
+## Verify installation
+
+```ruby
+require "xdk"
+puts Xdk::VERSION
+```
diff --git a/xdks/ruby/overview.mdx b/xdks/ruby/overview.mdx
new file mode 100644
index 000000000..9bbce1563
--- /dev/null
+++ b/xdks/ruby/overview.mdx
@@ -0,0 +1,31 @@
+---
+title: Ruby XDK
+sidebarTitle: Overview
+description: Official Ruby SDK for the X API v2 — zero runtime dependencies, Ruby 3.0+, Bearer/OAuth 2.0 PKCE/OAuth 1.0a auth, pagination, and streaming.
+keywords: ["XDK", "Ruby SDK", "X API Ruby", "xdk gem", "Ruby X API v2"]
+---
+
+The **Ruby XDK** (`xdk`) is the official Ruby client library for the X API v2, generated from the [X API OpenAPI specification](https://api.x.com/2/openapi.json).
+
+- **Package:** [`xdk`](https://rubygems.org/gems/xdk) on RubyGems (`0.1.0`)
+- **Repository:** [xdevplatform/xdk-ruby](https://github.com/xdevplatform/xdk-ruby)
+- **Runtime:** Ruby 3.0+ with **zero runtime gem dependencies** (pure stdlib `net/http`, `openssl`, `json`)
+
+
+
+ Add `xdk` via RubyGems or Bundler
+
+
+ Make your first X API v2 call in Ruby
+
+
+ Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a
+
+
+ Lazy Enumerators and resilient real-time streams
+
+
+
+## Encrypted X Chat DMs
+
+Pair `xdk` with the official Ruby **[Chat XDK](/xchat/xchat-xdk)** (`gem install chat_xdk`) to handle X Chat end-to-end encryption, decryption, and signing alongside `/2/chat/*` REST calls.
diff --git a/xdks/ruby/pagination.mdx b/xdks/ruby/pagination.mdx
new file mode 100644
index 000000000..9e8ac09d5
--- /dev/null
+++ b/xdks/ruby/pagination.mdx
@@ -0,0 +1,38 @@
+---
+title: Pagination in Ruby XDK
+sidebarTitle: Pagination
+description: Paginate through X API v2 results lazily using Ruby Enumerators.
+keywords: ["Ruby XDK pagination", "X API next_token Ruby", "Enumerator"]
+---
+
+Endpoints that accept `pagination_token` or `next_token` return a lazy Ruby `Enumerator` that fetches each page on demand until `meta.next_token` is absent.
+
+## Iterating with an `Enumerator`
+
+```ruby
+require "xdk"
+
+client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))
+
+# Fetch at most 3 pages lazily
+client.posts.search_recent(query: "ruby lang:en", max_results: 25).take(3).each do |page|
+ (page["data"] || []).each do |post|
+ puts "#{post['id']}: #{post['text']}"
+ end
+end
+```
+
+## Fetching just the first page
+
+```ruby
+first_page = client.posts.search_recent(query: "ruby lang:en", max_results: 10).first
+```
+
+## Passing a block directly
+
+```ruby
+client.posts.search_recent(query: "ruby lang:en", max_results: 25) do |page|
+ puts "Got #{(page['data'] || []).length} posts"
+ break if page.dig("meta", "result_count").to_i < 25
+end
+```
diff --git a/xdks/ruby/quickstart.mdx b/xdks/ruby/quickstart.mdx
new file mode 100644
index 000000000..6d6afff41
--- /dev/null
+++ b/xdks/ruby/quickstart.mdx
@@ -0,0 +1,51 @@
+---
+title: Ruby XDK Quickstart
+sidebarTitle: Quickstart
+description: Make your first X API v2 requests in Ruby with the official xdk gem.
+keywords: ["Ruby XDK quickstart", "X API Ruby example", "xdk gem"]
+---
+
+## Look up a user (Bearer Token)
+
+```ruby
+require "xdk"
+
+client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))
+
+response = client.users.get_by_username(
+ username: "XDevelopers",
+ user_fields: %w[created_at description public_metrics]
+)
+
+puts response["data"]
+```
+
+## Create a Post (OAuth 2.0 User Context)
+
+```ruby
+require "xdk"
+
+client = Xdk::Client.new(access_token: ENV.fetch("X_ACCESS_TOKEN"))
+
+created = client.posts.create(body: { text: "Hello from the Ruby XDK!" })
+puts "Created Post ID: #{created.dig('data', 'id')}"
+```
+
+## Error handling & automatic retries
+
+Configure transient retries for `429` / `5xx` responses (honoring `Retry-After`) and rescue `Xdk::ApiError`:
+
+```ruby
+client = Xdk::Client.new(
+ bearer_token: ENV.fetch("X_BEARER_TOKEN"),
+ timeout: 15,
+ max_retries: 3,
+ retry_backoff: 0.5
+)
+
+begin
+ user = client.users.get_by_username(username: "XDevelopers")
+rescue Xdk::ApiError => e
+ warn "HTTP #{e.status} (request_id=#{e.request_id}, retry_after=#{e.retry_after}): #{e.message}"
+end
+```
diff --git a/xdks/ruby/streaming.mdx b/xdks/ruby/streaming.mdx
new file mode 100644
index 000000000..3da1c4d10
--- /dev/null
+++ b/xdks/ruby/streaming.mdx
@@ -0,0 +1,37 @@
+---
+title: Streaming in Ruby XDK
+sidebarTitle: Streaming
+description: Consume X API v2 real-time streams in Ruby with keep-alive callbacks, idle-timeout recovery, and automatic reconnection.
+keywords: ["Ruby XDK streaming", "filtered stream Ruby", "StreamConfig"]
+---
+
+Streaming endpoints yield parsed JSON events as they arrive (or return a lazy `Enumerator` when called without a block), with automatic exponential backoff reconnection, keep-alive heartbeat callbacks, and optional idle-timeout stall detection.
+
+## Consuming a stream
+
+```ruby
+require "xdk"
+
+client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))
+
+config = Xdk::StreamConfig.new(
+ max_retries: -1, # -1 for infinite retries
+ initial_backoff: 1.0,
+ max_backoff: 64.0,
+ idle_timeout: 60.0, # reconnect if no data or 20s heartbeat arrives for 60s
+ reconnect_on_close: true,
+ on_connect: -> { puts "Stream connected" },
+ on_keep_alive: -> { puts "Heartbeat received" },
+ on_reconnect: ->(attempt, delay) { warn "Reconnecting ##{attempt} in #{delay.round(2)}s" },
+ on_error: ->(err) { warn "Stream error (#{err.error_type}): #{err.message}" }
+)
+
+client.stream.posts(stream_config: config) do |event|
+ puts event.dig("data", "text")
+end
+```
+
+## Error classification
+
+- **Retryable (`err.retryable? == true`):** connection resets, timeouts (`Xdk::StreamIdleTimeoutError`), `429` rate limits, and `5xx` server errors — retried automatically with exponential backoff and jitter, resetting the backoff counter whenever an event or keep-alive heartbeat arrives.
+- **Non-retryable (`err.retryable? == false`):** `401` / `403` authentication errors and other `4xx` client errors raise `Xdk::StreamError` immediately.