API Usage
Megabyte Island provides a secure chat proxy so you can send messages to your AI agent from your own product β without ever exposing your master API token.
Chat Endpoint
POST /api/agents/:agentId/chat Authentication: Include your session cookie (set automatically after login) or pass Authorization: Bearer <jwt>.
Request body
{
"message": "What are your opening hours?",
"conversationId": "optional-uuid-for-history"
} | Field | Type | Required | Notes |
|---|---|---|---|
message | string | Yes | The userβs message |
conversationId | string | No | Pass the same ID across turns to maintain context |
Response
The endpoint streams a Server-Sent Events (SSE) response. Each chunk is a partial token from the model.
data: {"token": "Our"}
data: {"token": " opening"}
data: {"token": " hours"}
data: {"token": " are 9amβ6pm."}
data: [DONE] Example β JavaScript (fetch + SSE)
const response = await fetch(`https://agents.megabyteisland.com/api/agents/${AGENT_ID}/chat`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include', // sends session cookie
body: JSON.stringify({ message: userMessage, conversationId: sessionId }),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value, { stream: true });
// Append chunk to your chat UI
appendToChat(chunk);
} Error Responses
| Code | Meaning |
|---|---|
400 | Missing or empty message |
401 | Not authenticated β check your session or JWT |
404 | Agent not found or does not belong to your account |
409 | Agent status is not active yet |
502 | Upstream AI error β retry after a moment |
Rate Limits
Rate limits are governed by your Gradient AI plan. Megabyte Island does not impose additional limits beyond those inherited from the platform.