Getting Started
The official Ruby SDK for Stream covers Chat, Video, Moderation, and Feeds. This page takes you from installing the SDK to your first API call.
Start here
Generate tokens, sync users and manage channels from your server.
Token signing, expiry and revocation in detail.
Connecting users, presence and everything else that runs in your app.
How the pieces fit together
This SDK calls the Stream API from your backend, authenticated with your API secret. Your users connect from your app with a client SDK, using a token your backend signs. Anything that needs a connected user or a live WebSocket lives in the client: initialization, guest and anonymous sessions, typing indicators and presence.
flowchart LR
app[Your app] <-->|WebSocket| api[Stream API]
backend[Your backend] -->|REST| api
backend -. user token .-> appStream CLI and Agent Skills
Manage Stream from your terminal with the Stream CLI, including scripting and AI-agent workflows. Install the CLI and the default Agent Skills:
curl -fsSL https://getstream.io/cli.sh | bash
getstream skillsThen ask your agent in plain English, for example:
/stream List recent channels in my app.See the CLI docs and Agent Skills docs for more.
Setup
| GitHub | github.com/GetStream/getstream-ruby |
| RubyGems | rubygems.org/gems/getstream-ruby |
Install the SDK:
gem install getstream-rubyOr add to your Gemfile:
gem 'getstream-ruby'Initialize the client with your API key and secret (available on the Dashboard):
require 'getstream_ruby'
client = GetStreamRuby.manual(api_key: 'your-api-key', api_secret: 'your-api-secret')You can also load credentials from environment variables (STREAM_API_KEY, STREAM_API_SECRET) or a .env file:
client = GetStreamRuby.envServer-side token
Your backend generates a user token that the client SDKs use to authenticate. A typical place to issue this token is during login or registration.
require 'jwt'
token = JWT.encode({ user_id: 'user-id', iat: Time.now.to_i }, 'your-api-secret', 'HS256')
# return the token to the client appTokens with an expiry:
token = JWT.encode(
{ user_id: 'user-id', iat: Time.now.to_i, exp: (Time.now + 3600).to_i },
'your-api-secret',
'HS256'
)For token expiry and revocation details, see Authentication and tokens.
Making your first API call
Create a user, open a channel, and send a message:
Models = GetStream::Generated::Models
# Upsert a user
client.common.update_users(
Models::UpdateUsersRequest.new(
users: { 'john' => Models::UserRequest.new(id: 'john', name: 'John') }
)
)
# Create or join a channel
client.chat.get_or_create_channel('messaging', 'hello-world',
Models::ChannelGetOrCreateRequest.new(
data: Models::ChannelInput.new(created_by_id: 'john')
)
)
# Send a message
client.chat.send_message('messaging', 'hello-world',
Models::SendMessageRequest.new(
message: Models::MessageRequest.new(text: 'Hello, Stream!', user_id: 'john')
)
)What's next
Once your first message is through, these are good places to go deeper:
Channel types, custom data and everything else about setting up conversations.
Attachments, custom fields and the rest of the message API.
React to chat events from your own backend.
FAQ
Which webhook events does chat send?
The event catalogue lists every webhook event and most payloads.
Can I check messages before they're delivered?
Yes, with the before message send webhook.
Does this SDK cover other Stream products?
Yes. Each backend SDK covers every product; build one client and reuse it.
Are server-sent messages moderated?
Not by default. Set force_moderation to true when sending. See chat moderation.