# Getting Started

## Setup

The official Ruby SDK for Stream covers Chat, Video, Moderation, and Feeds.

|          |                                                                                    |
| -------- | ---------------------------------------------------------------------------------- |
| GitHub   | [github.com/GetStream/getstream-ruby](https://github.com/GetStream/getstream-ruby) |
| RubyGems | [rubygems.org/gems/getstream-ruby](https://rubygems.org/gems/getstream-ruby)       |

Install the SDK:

```bash
gem install getstream-ruby
```

Or add to your Gemfile:

```ruby
gem 'getstream-ruby'
```

Initialize the client with your API key and secret (available on the [Dashboard](https://dashboard.getstream.io/)):

```ruby
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:

```ruby
client = GetStreamRuby.env
```

## Server-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.

```ruby
require 'jwt'

token = JWT.encode({ user_id: 'user-id', iat: Time.now.to_i }, 'your-api-secret', 'HS256')
# return the token to the client app
```

Tokens with an expiry:

```ruby
token = JWT.encode(
  { user_id: 'user-id', iat: Time.now.to_i, exp: (Time.now + 3600).to_i },
  'your-api-secret',
  'HS256'
)
```

## Making Your First API Call

Create a user, open a channel, and send a message:

```ruby
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')
  )
)
```


---

This page was last updated at 2026-03-13T13:17:06.290Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/ruby/](https://getstream.io/chat/docs/ruby/).