This document provides a complete reference for the Codebuff WebSocket protocol implemented by the LLM Interactive Proxy.
The Codebuff protocol uses JSON messages over WebSocket connections. All communication follows a request-response pattern with acknowledgments.
All messages are JSON objects with a type field that determines the message structure and handling.
Most messages include a txid (transaction ID) field for request-response correlation. The server echoes the txid in acknowledgment messages.
Establishes the client session ID.
Format:
{
"type": "identify",
"txid": <integer>,
"clientSessionId": <string>
}Fields:
type: Must be"identify"txid: Transaction ID for correlationclientSessionId: Unique identifier for this client session
Response: ack message with success: true
Example:
{
"type": "identify",
"txid": 1,
"clientSessionId": "session-abc123"
}Heartbeat message to keep connection alive.
Format:
{
"type": "ping",
"txid": <integer>
}Fields:
type: Must be"ping"txid: Transaction ID for correlation
Response: ack message with success: true
Example:
{
"type": "ping",
"txid": 42
}Notes:
- Clients must send ping messages regularly (recommended: every 30 seconds)
- Connections timeout after
heartbeat_timeout_secondswithout ping - Default timeout: 60 seconds
Subscribe to one or more topics.
Format:
{
"type": "subscribe",
"txid": <integer>,
"topics": [<string>, ...]
}Fields:
type: Must be"subscribe"txid: Transaction ID for correlationtopics: Array of topic names to subscribe to
Response: ack message with success: true
Example:
{
"type": "subscribe",
"txid": 5,
"topics": ["updates", "notifications", "errors"]
}Unsubscribe from one or more topics.
Format:
{
"type": "unsubscribe",
"txid": <integer>,
"topics": [<string>, ...]
}Fields:
type: Must be"unsubscribe"txid: Transaction ID for correlationtopics: Array of topic names to unsubscribe from
Response: ack message with success: true
Example:
{
"type": "unsubscribe",
"txid": 6,
"topics": ["updates"]
}Container for action-specific messages (prompt, init, etc.).
Format:
{
"type": "action",
"txid": <integer>,
"data": <action-object>
}Fields:
type: Must be"action"txid: Transaction ID for correlationdata: Action-specific object (see Action Types below)
Response: ack message followed by action-specific responses
Request LLM completion.
Format:
{
"type": "prompt",
"promptId": <string>,
"prompt": <string | null>,
"content": <array | null>,
"promptParams": <object | null>,
"fingerprintId": <string>,
"authToken": <string | null>,
"costMode": <string>,
"sessionState": <object>,
"toolResults": <array>,
"model": <string | null>,
"repoUrl": <string | null>,
"agentId": <string | null>
}Fields:
type: Must be"prompt"promptId: Unique identifier for this prompt requestprompt: Simple text prompt (alternative tocontent)content: Structured message content (alternative toprompt)promptParams: Optional parameters for the promptfingerprintId: Client fingerprint for usage attributionauthToken: Optional authentication tokencostMode: Cost mode (default:"normal")sessionState: Current session state/conversation historytoolResults: Results from previous tool callsmodel: Requested model name (e.g.,"gpt-4","claude-3-opus")repoUrl: Optional repository URL for contextagentId: Optional agent identifier
Response Sequence:
ackmessage withsuccess: true- Multiple
response-chunkactions (streaming) - Final
prompt-responseaction (completion) - Or
prompt-erroraction (on error)
Example:
{
"type": "action",
"txid": 10,
"data": {
"type": "prompt",
"promptId": "prompt-xyz789",
"prompt": "Write a Python function to calculate fibonacci numbers",
"fingerprintId": "client-abc",
"model": "gpt-4",
"sessionState": {},
"toolResults": [],
"costMode": "normal"
}
}Initialize session with file context.
Format:
{
"type": "init",
"fingerprintId": <string>,
"authToken": <string | null>,
"fileContext": <object>,
"repoUrl": <string | null>
}Fields:
type: Must be"init"fingerprintId: Client fingerprint for usage attributionauthToken: Optional authentication tokenfileContext: File context object containing project filesrepoUrl: Optional repository URL
File Context Structure:
{
"files": [
{
"path": "relative/path/to/file.py",
"content": "file contents..."
}
]
}Response: init-response action
Example:
{
"type": "action",
"txid": 15,
"data": {
"type": "init",
"fingerprintId": "client-abc",
"fileContext": {
"files": [
{
"path": "main.py",
"content": "def main():\n print('Hello')\n"
},
{
"path": "utils.py",
"content": "def helper():\n pass\n"
}
]
},
"repoUrl": "https://github.com/user/repo"
}
}Acknowledges receipt and validation of client message.
Format:
{
"type": "ack",
"txid": <integer | null>,
"success": <boolean>,
"error": <string | null>
}Fields:
type: Always"ack"txid: Transaction ID from client message (null if not applicable)success:trueif message was valid and accepted,falseotherwiseerror: Error message ifsuccessisfalse, null otherwise
Examples:
Success:
{
"type": "ack",
"txid": 1,
"success": true,
"error": null
}Failure:
{
"type": "ack",
"txid": 2,
"success": false,
"error": "Invalid JSON: Unexpected token at position 42"
}Container for server-initiated actions.
Format:
{
"type": "action",
"data": <action-object>
}Fields:
type: Always"action"data: Action-specific object (see Server Action Types below)
Streaming chunk of LLM response.
Format:
{
"type": "response-chunk",
"userInputId": <string>,
"chunk": <string>
}Fields:
type: Must be"response-chunk"userInputId: Prompt ID from the original requestchunk: Text chunk from the LLM response
Example:
{
"type": "action",
"data": {
"type": "response-chunk",
"userInputId": "prompt-xyz789",
"chunk": "def fibonacci(n):\n"
}
}Notes:
- Multiple chunks are sent for a single prompt
- Chunks should be concatenated in order to build the complete response
- Final
prompt-responseaction signals completion
Final response after streaming completes.
Format:
{
"type": "prompt-response",
"promptId": <string>,
"sessionState": <object>,
"toolCalls": <array | null>,
"toolResults": <array | null>,
"output": <object | null>
}Fields:
type: Must be"prompt-response"promptId: Prompt ID from the original requestsessionState: Updated session state after this interactiontoolCalls: Tool calls requested by the LLM (null in MVP)toolResults: Results from tool execution (null in MVP)output: Additional output data (null in MVP)
Example:
{
"type": "action",
"data": {
"type": "prompt-response",
"promptId": "prompt-xyz789",
"sessionState": {
"messages": [
{"role": "user", "content": "Write a fibonacci function"},
{"role": "assistant", "content": "def fibonacci(n):..."}
]
},
"toolCalls": null,
"toolResults": null,
"output": null
}
}Error during prompt processing.
Format:
{
"type": "prompt-error",
"userInputId": <string>,
"message": <string>,
"error": <string | null>,
"remainingBalance": <number | null>
}Fields:
type: Must be"prompt-error"userInputId: Prompt ID from the original requestmessage: User-friendly error messageerror: Detailed error information (optional)remainingBalance: Remaining usage balance (null in MVP)
Example:
{
"type": "action",
"data": {
"type": "prompt-error",
"userInputId": "prompt-xyz789",
"message": "Backend unavailable",
"error": "Connection timeout after 30 seconds",
"remainingBalance": null
}
}Response to init action.
Format:
{
"type": "init-response",
"message": <string | null>,
"agentNames": <object | null>,
"usage": <number>,
"remainingBalance": <number>,
"next_quota_reset": <string | null>
}Fields:
type: Must be"init-response"message: Optional status messageagentNames: Optional agent name mappingsusage: Usage credits consumed (0 in MVP)remainingBalance: Remaining balance (unlimited in MVP)next_quota_reset: Next quota reset time (null in MVP)
Example:
{
"type": "action",
"data": {
"type": "init-response",
"message": "Session initialized successfully",
"agentNames": null,
"usage": 0.0,
"remainingBalance": 999999.0,
"next_quota_reset": null
}
}Errors in message parsing or validation return an ack message with success: false:
{
"type": "ack",
"txid": 5,
"success": false,
"error": "Schema validation failed: 'type' is required"
}Errors during action processing return action-specific error messages:
Prompt Errors:
{
"type": "action",
"data": {
"type": "prompt-error",
"userInputId": "prompt-123",
"message": "Model not supported",
"error": "Model 'gpt-5' is not available",
"remainingBalance": null
}
}Action Errors (generic):
{
"type": "action",
"data": {
"type": "action-error",
"message": "Authentication failed",
"error": "Invalid auth token",
"remainingBalance": null
}
}Client Server
| |
|--- WebSocket Connect -------->|
|<-- WebSocket Accept ----------|
| |
Client Server
| |
|--- identify message --------->|
|<-- ack (success: true) -------|
| |
Client Server
| |
|--- ping message ------------->|
|<-- ack (success: true) -------|
| |
| (30 seconds later) |
|--- ping message ------------->|
|<-- ack (success: true) -------|
| |
Client Server
| |
|--- init action -------------->|
|<-- ack (success: true) -------|
|<-- init-response action ------|
| |
Client Server
| |
|--- prompt action ------------>|
|<-- ack (success: true) -------|
|<-- response-chunk action -----|
|<-- response-chunk action -----|
|<-- response-chunk action -----|
|<-- prompt-response action ----|
| |
Client Server
| |
|--- WebSocket Close ---------->|
|<-- WebSocket Close -----------|
| |
| (Session cleaned up) |
- Send Regular Pings: Send ping messages every 30 seconds to prevent timeout
- Handle Reconnection: Implement reconnection logic with exponential backoff
- Clean Disconnect: Close WebSocket properly to allow server cleanup
- Validate Before Sending: Validate messages against schema before sending
- Handle Errors Gracefully: Check
ackmessages for errors and handle appropriately - Correlate Responses: Use
txidandpromptIdto correlate requests and responses
- Buffer Chunks: Accumulate response chunks in order
- Handle Completion: Wait for
prompt-responsebefore considering request complete - Handle Errors: Check for
prompt-errorand handle appropriately
- Initialize Once: Send init action once per session
- Maintain State: Track session state across requests
- Clean Up: Close connection when done to free server resources
The current implementation has these limitations:
- No Tool Calls: Tool call request/response flow not implemented
- No File Access: Read-files request/response flow not implemented
- No Authentication: Auth tokens accepted but not validated
- Dummy Usage: Usage and balance values are placeholders
- No Persistence: Sessions not persisted across server restarts
These features are planned for future releases.
IMPORTANT LEGAL NOTICE - READ CAREFULLY BEFORE USING THE CODEBUFF-COMPATIBLE BACKEND
-
Non-Affiliation: This project is an independent open-source initiative. It is not affiliated with, endorsed by, authorized by, or in any way officially connected to Codebuff or any of their subsidiaries or affiliates. All product and company names are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
-
No Liability: The authors, contributors, and maintainers of this project hold no responsibility or liability for any consequences arising from the use of this backend in violation of these rules, or for any violations of third-party Terms of Service resulting from such use.
-
User Responsibility: You accept full responsibility for ensuring your use of this tool complies with all applicable laws and third-party agreements.
-
Compliance with Provider Terms: Users of the Codebuff-compatible backend connector are strictly required to respect all related Terms of Service (ToS) and other agreements with Codebuff and any backend providers. You are solely responsible for verifying that your use of this software is compatible with those agreements.
-
Indemnification: You agree to indemnify, defend, and hold harmless the authors and contributors of this project from and against any and all claims, liabilities, damages, losses, or expenses, including legal fees and costs, arising out of or in any way connected with your access to or use of the Codebuff-compatible backend.
If you do not agree to these terms, do not use the Codebuff-compatible backend interface.
- Codebuff Backend Feature Guide - Configuration and usage
- Configuration Reference - Complete configuration options
- Wire Capture - Debugging WebSocket traffic