Official Go SDK for Stream
Official Go API client for Stream Chat and Video, a service for building chat and video applications.
Explore the docs »
Report Bug
·
Request Feature
- Video call creation and management
- Chat session creation and management
- Token generation for user authentication
You can sign up for a Stream account at our Get Started page.
You can use this library to access chat API endpoints server-side.
For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries (docs).
go get github.com/GetStream/getstream-go
package main
import (
"context"
"fmt"
"os"
"time"
stream "github.com/GetStream/getstream-go"
)
func main() {
apiKey := os.Getenv("STREAM_API_KEY")
apiSecret := os.Getenv("STREAM_API_SECRET")
userID := "your-user-id" // Replace with your server user id
// Initialize client
client, err := stream.NewClient(apiKey, apiSecret)
if err != nil {
fmt.Printf("Error initializing client: %v\n", err)
return
}
// Or initialize using only environmental variables:
// (required) STREAM_API_KEY, (required) STREAM_API_SECRET
client, err = stream.NewClientFromEnvVars()
if err != nil {
fmt.Printf("Error initializing client from env vars: %v\n", err)
return
}
// Define a context
ctx := context.Background()
// Create a call
call := client.Video.Call("default", "unique-call-id")
// Create or get a call
response, err := call.GetOrCreate(ctx, &stream.CallRequest{
CreatedBy: stream.UserRequest{ID: userID},
})
if err != nil {
fmt.Printf("Error creating/getting call: %v\n", err)
return
}
fmt.Printf("Call created/retrieved: %s\n", response.Call.ID)
// Update call settings
_, err = call.Update(ctx, &stream.UpdateCallRequest{
SettingsOverride: &stream.CallSettingsRequest{
Audio: &stream.AudioSettings{
MicDefaultOn: stream.PtrTo(true),
},
},
})
if err != nil {
fmt.Printf("Error updating call settings: %v\n", err)
return
}
// Create a token for client-side use
token, err := client.CreateToken(userID, nil)
if err != nil {
fmt.Printf("Error creating token: %v\n", err)
return
}
fmt.Printf("Token for user %s: %s\n", userID, token)
// Query calls
callsResponse, err := client.Video.QueryCalls(ctx, &stream.QueryCallsRequest{
FilterConditions: map[string]interface{}{
"created_by_user_id": userID,
},
})
if err != nil {
fmt.Printf("Error querying calls: %v\n", err)
return
}
fmt.Printf("Found %d calls\n", len(callsResponse.Calls))
}
// Helper function to create a pointer to a value
func PtrTo[T any](v T) *T {
return &v
}
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.
Head over to CONTRIBUTING.md for some development tips.
To regenerate the Go source from OpenAPI, just run the ./generate.sh
script from this repo.
Note
Code generation currently relies on tooling that is not publicly available, only Stream devs can regenerate SDK source code from the OpenAPI spec.
We've recently closed a $38 million Series B funding round and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
Check out our current openings and apply via Stream's website.