Skip to main content

APIs

Secure Chat API

The Secure Chat API is an authenticated chat API for published agents. Requests must include a workspace API key and the key must match the workspace in the request.

Authentication

Secure chat requires a workspace API key:

  • keys are managed per workspace (see Workspace API Keys).
  • requests must authenticate using a Bearer token in the Authorization header.

Security

Keep API keys out of browsers and client-side code. Only invoke the Secure Chat API from trusted server environments.


Chat Endpoint

Send a message sequence to the published agent to generate a response, optionally streaming back the tokens.

HTTP Request

POST /api/secure/chat

Query Parameters

ParameterTypeRequiredDescription
workspaceIdstringYesUnique ID of the workspace.
agentIdstringYesUnique ID of the agent.
streamstringNoSet to "true" to receive a Server-Sent Events (SSE) streaming response.

Request Headers

  • Authorization: Bearer <workspaceApiKey>
  • Content-Type: application/json

Request Body Schema

{
"id": "optional-session-id",
"messages": [
{
"id": "optional-message-id",
"role": "user",
"parts": [
{
"type": "text",
"text": "Hello! What is your pricing?"
}
]
}
]
}

Response Formats

Non-Streaming Response (stream not set or not "true")

Returns a standard JSON object containing the generated message, session details, finish reason, and source chunk metadata.

{
"message": {
"id": "msg_98765",
"role": "assistant",
"parts": [
{
"type": "text",
"text": "Our pricing plans start at $29/month."
}
]
},
"session": {
"id": "sess_12345"
},
"finishReason": "stop",
"metadata": {
"retrievedChunks": [
{
"id": "chunk_abc",
"text": "Pricing Plans: Free ($0), Creator ($29/month)...",
"score": 0.89
}
]
}
}

Streaming Response (stream=true)

Returns a text/event-stream using the Vercel AI SDK format. Refer to the Streaming and Errors page for the full structure.


Code Examples

sending a request with curl

curl -X POST "https://api.kriyaos.com/api/secure/chat?workspaceId=ws_12345&agentId=agent_67890" \
-H "Authorization: Bearer kriya_sec_key_abc123" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "user",
"parts": [{ "type": "text", "text": "Hi Support!" }]
}
]
}'

sending a request with node/fetch

const query = new URLSearchParams({
workspaceId: "ws_12345",
agentId: "agent_67890"
});

const response = await fetch(`https://api.kriyaos.com/api/secure/chat?${query}`, {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KRIYAOS_WORKSPACE_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
messages: [
{
role: "user",
parts: [{ type: "text", text: "Are there any hidden fees?" }]
}
]
})
});

const data = await response.json();
console.log("Response:", data.message.parts[0].text);