# Getting Started

The official Go SDK for Stream covers Chat, Video, Moderation, and Feeds. This page takes you from installing the SDK to your first API call.

## Start here

- [Backend quickstart](https://getstream.io/chat/docs/go-golang/backend/): Generate tokens, sync users and manage channels from your server.
- [Authentication and tokens](https://getstream.io/docs/platform/authentication/): Token signing, expiry and revocation in detail.
- [Client-side overview](https://getstream.io/chat/docs/go-golang/client-side/): 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.

```mermaid
flowchart LR
  app[Your app] <-->|WebSocket| api[Stream API]
  backend[Your backend] -->|REST| api
  backend -. user token .-> app
```

## Stream CLI and Agent Skills

Manage Stream from your terminal with the [Stream CLI](https://getstream.io/cli/docs/), including scripting and AI-agent workflows. Install the CLI and the default [Agent Skills](https://getstream.io/agent-skills/docs/):

```bash
curl -fsSL https://getstream.io/cli.sh | bash
getstream skills
```

Then ask your agent in plain English, for example:

```text
/stream List recent channels in my app.
```

See the [CLI docs](https://getstream.io/cli/docs/) and [Agent Skills docs](https://getstream.io/agent-skills/docs/) for more.

## Setup

|             |                                                                                                            |
| ----------- | ---------------------------------------------------------------------------------------------------------- |
| GitHub      | [github.com/GetStream/getstream-go](https://github.com/GetStream/getstream-go)                             |
| Go Packages | [pkg.go.dev/github.com/GetStream/getstream-go/v8](https://pkg.go.dev/github.com/GetStream/getstream-go/v8) |

Install the SDK:

```go
go get github.com/GetStream/getstream-go/v8
```

Upgrading from v7: see the [v7 to v8 migration guide](https://github.com/GetStream/getstream-go/blob/main/MIGRATION_v7_to_v8.md).

Initialize the client with your API key and secret (available on the [Dashboard](https://getstream.io/signin/?product=chat)):

```go
import "github.com/GetStream/getstream-go/v8"

client, err := getstream.NewClient("your-api-key", "your-api-secret")
if err != nil {
    panic(err)
}
```

You can also load credentials from environment variables (`STREAM_API_KEY`, `STREAM_API_SECRET`):

```go
client, err := getstream.NewClientFromEnvVars()
```

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

```go
token, err := client.CreateToken("user-id")
if err != nil {
    panic(err)
}
// return the token to the client app
```

Tokens with an expiry:

```go
token, err := client.CreateToken("user-id",
    getstream.WithExpiration(24 * time.Hour))
```

For token expiry and revocation details, see [Authentication and tokens](https://getstream.io/docs/platform/authentication/).

## Making your first API call

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

```go
// Upsert a user
client.UpdateUsers(ctx, &getstream.UpdateUsersRequest{
    Users: map[string]getstream.UserRequest{
        "john": {ID: "john", Name: getstream.PtrTo("John")},
    },
})

// Create or join a channel
channel := client.Chat().Channel("messaging", "hello-world")
channel.GetOrCreate(ctx, &getstream.GetOrCreateChannelRequest{
    Data: &getstream.ChannelInput{
        CreatedByID: getstream.PtrTo("john"),
    },
})

// Send a message
channel.SendMessage(ctx, &getstream.SendMessageRequest{
    Message: getstream.MessageRequest{
        Text:   getstream.PtrTo("Hello, Stream!"),
        UserID: getstream.PtrTo("john"),
    },
})
```

## What's next

Once your first message is through, these are good places to go deeper:

- [Creating channels](https://getstream.io/chat/docs/go-golang/creating-channels/): Channel types, custom data and everything else about setting up conversations.
- [Sending messages](https://getstream.io/chat/docs/go-golang/send-message/): Attachments, custom fields and the rest of the message API.
- [Webhooks](https://getstream.io/docs/platform/webhooks/): React to chat events from your own backend.

## FAQ

**Which webhook events does chat send?**

The [event catalogue](https://getstream.io/chat/docs/go-golang/webhook-events/) lists every webhook event and most payloads.

**Can I check messages before they're delivered?**

Yes, with the [before message send webhook](https://getstream.io/chat/docs/go-golang/before-message-send-webhook/).

**Does this SDK cover other Stream products?**

Yes. Each [backend SDK](https://getstream.io/docs/platform/backend-sdks/) covers every product; build one client and reuse it.

**Are server-sent messages moderated?**

Not by default. Set `ForceModeration` to `true` when sending. See [chat moderation](https://getstream.io/moderation/docs/go-golang/integrations/stream-chat/#server-side-integration).

---

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