<dependency>
<groupId>io.getstream</groupId>
<artifactId>stream-sdk-java</artifactId>
<version>$streamVersion</version>
</dependency>Getting Started
Setup
The official Java SDK for Stream covers Chat, Video, Moderation, and Feeds.
Add the dependency:
Maven:
Gradle:
implementation 'io.getstream:stream-sdk-java:$streamVersion'Initialize the client with your API key and secret (available on the Dashboard):
import io.getstream.services.framework.StreamSDKClient;
var client = new StreamSDKClient("your-api-key", "your-api-secret");You can also load credentials from environment variables (STREAM_API_KEY, STREAM_API_SECRET):
var client = new StreamSDKClient();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.
var token = client.tokenBuilder().createToken("user-id");
// return the token to the client appTokens with an expiry (in seconds):
var token = client.tokenBuilder().createToken("user-id", 3600);Making Your First API Call
Create a user, open a channel, and send a message:
import io.getstream.models.*;
import io.getstream.services.Chat;
import java.util.Map;
// Upsert a user
client.updateUsers(UpdateUsersRequest.builder()
.users(Map.of("john", UserRequest.builder().id("john").name("John").build()))
.build()).execute();
// Create or join a channel
Chat chat = client.chat();
chat.channel("messaging", "hello-world")
.getOrCreate(GetOrCreateChannelRequest.builder()
.data(ChannelInput.builder()
.createdByID("john")
.build())
.build());
// Send a message
chat.channel("messaging", "hello-world")
.sendMessage(SendMessageRequest.builder()
.message(MessageRequest.builder()
.text("Hello, Stream!")
.userID("john")
.build())
.build());