Overview
Osmium Chat Protocol uses a bidirectional message-based communication model with Protocol Buffers. All communication flows through two main message types:ClientMessage (client → server) and ServerMessage (server → client).
ClientMessage Structure
Every message sent from the client to the server follows this structure:Key Fields
Unique identifier for this request. Used to match server responses to client requests. Each request must have a unique ID within the session.
The actual RPC method being invoked. Only one field can be set at a time, representing the specific operation to perform.
Available RPC Methods
The protocol supports over 80 different RPC methods organized by domain:Authentication & Authorization
Authentication & Authorization
Messaging
Messaging
messages_send_message- Send a new messagemessages_get_history- Retrieve message historymessages_delete_message- Delete a messagemessages_edit_message- Edit an existing messagemessages_search- Search messagesmessages_forward_message- Forward a message
Communities & Channels
Communities & Channels
communities_create_community- Create a new communitycommunities_get_communities- List communitiescommunities_create_channel- Create a channelcommunities_get_channels- List channelscommunities_get_channel_members- List channel memberscommunities_edit_channel- Edit channel settings
Chats & Groups
Chats & Groups
chats_get_chats- List all chatschats_get_chat- Get specific chat detailschats_create_chat- Create a group chatchats_mark_chat_read- Mark messages as readchats_set_typing- Send typing indicator
Friends & Relationships
Friends & Relationships
friends_get_relationships- List all relationshipsfriends_sync_friends- Sync friend listfriends_change_relationship- Modify relationship status
ServerMessage Structure
Every message sent from the server to the client follows this structure:Message Types
Sequential message ID assigned by the server. Used for ordering and tracking.
Real-time update notification (e.g., new message, user status change). These are pushed to the client without a corresponding request.
Response to a client RPC request. Contains either successful result data or an error.
RPC Result System
RPCResult Message
When the server responds to a client request, it uses theRPCResult message:
References the
id field from the original ClientMessage. This allows clients to match responses to their requests.Either an error or a success result. The specific success type depends on which RPC method was called.
RPCError Structure
When an RPC call fails, the server returns an error:Numeric error code identifying the type of error. Clients can use this for programmatic error handling.
Human-readable error description. Useful for debugging and user-facing error messages.
How RPCs Work
The RPC flow follows this sequence:Client sends request
Client creates a
ClientMessage with a unique id and sets one of the RPC method fields.Server processes request
Server receives the message, validates it, performs the requested operation, and prepares a response.
Server sends response
Server sends back a
ServerMessage containing an RPCResult with req_id matching the original request’s id.Example RPC Flows
Sending a Message
Fetching Message History
The separation of RPC results and real-time updates allows clients to maintain a clear distinction between responses to their actions and asynchronous events from other users.
Best Practices
Use Unique Request IDs
Always increment or randomize request IDs to avoid collisions. Many clients use a simple counter starting from 1.
Handle Both Success and Error
Every RPC call can fail. Always implement error handling for graceful degradation.
Match Responses Correctly
Use
req_id to associate responses with pending requests, especially important for async implementations.Set Reasonable Timeouts
Implement request timeouts to detect network issues or server problems.
Related Topics
Message Flow
Learn about the complete request/response lifecycle
Real-time Updates
Understand how server-pushed updates work
Snowflake IDs
Learn about the ID system used throughout the protocol