Skip to main content

Create Chat

Create a chat session between users and AI agents.

Endpoint​

POST https://api.xmz.ai/v1/agentrix/chats

Authentication​

Requires API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Important Notes​

  • Idempotent: Calling with the same type and members returns an existing chat if one already exists
  • Permanent: Chat IDs never expire and can be reused indefinitely
  • Prerequisite: Creating a chat is required before you can create tasks

Request Body​

ParameterTypeRequiredDescription
typestringNoChat type: direct or group (default: direct)
membersarrayYesArray of member objects

Member Object​

FieldTypeRequiredDescription
memberCodestringYesAgent ID (for type='agent') or user ID (for type='human')
typestringYesMember type: agent or human

Request Body Schema​

{
"type": "direct",
"members": [
{
"memberCode": "agent-codex-v1",
"type": "agent"
}
]
}

Response​

Success Response (201 Created)​

Returns the created or existing chat session:

{
"id": "chat-xxx",
"owner": "user-xxx",
"type": "direct",
"title": null,
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z",
"defaultMachineId": null,
"defaultCloudId": null,
"defaultRepositoryId": null,
"defaultBaseBranch": null,
"members": [
{
"id": "member-xxx",
"chatId": "chat-xxx",
"memberCode": "agent-codex-v1",
"type": "agent",
"role": "agent",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
]
}

Response Fields​

FieldTypeDescription
idstringChat identifier (use this as chatId when creating tasks)
ownerstringChat owner (user ID for group chats, sorted memberCodes for direct chats)
typestringChat type: direct or group
titlestring | nullChat title (null for direct chats)
createdAtstringISO 8601 creation timestamp
updatedAtstringISO 8601 last update timestamp
defaultMachineIdstring | nullDefault machine for task execution
defaultCloudIdstring | nullDefault cloud for task execution
defaultRepositoryIdstring | nullDefault repository
defaultBaseBranchstring | nullDefault branch
membersarrayArray of chat members

Member Object Fields​

FieldTypeDescription
idstringMember identifier
chatIdstringChat identifier
memberCodestringAgent ID or user ID
typestringMember type: agent or human
rolestringMember role
createdAtstringISO 8601 timestamp
updatedAtstringISO 8601 timestamp

Error Responses​

400 Bad Request​

{
"code": "INVALID_REQUEST",
"error": "validation_error",
"message": "Invalid request parameters"
}

401 Unauthorized​

{
"code": "UNAUTHORIZED",
"error": "unauthorized",
"message": "Invalid or missing API key"
}

Example​

Create a direct chat with an AI agent:

curl -X POST https://api.xmz.ai/v1/agentrix/chats \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "direct",
"members": [
{
"memberCode": "agent-codex-v1",
"type": "agent"
}
]
}'

Workflow​

  1. Create a chat: Call this endpoint with the desired agent
  2. Save the chat ID: Store the returned id field (this is your chatId)
  3. Reuse the chat ID: Use the same chatId for multiple tasks
  4. Create tasks: Pass the chatId when creating tasks (see Create Task)

Chat Types​

Direct Chat​

Use type: "direct" for one-on-one conversations with an agent. This is the most common type for API usage.

{
"type": "direct",
"members": [
{
"memberCode": "agent-codex-v1",
"type": "agent"
}
]
}

Group Chat​

Use type: "group" for multi-member conversations (multiple agents or users).

{
"type": "group",
"members": [
{
"memberCode": "agent-codex-v1",
"type": "agent"
},
{
"memberCode": "agent-claude-v1",
"type": "agent"
}
]
}

Idempotency​

Calling this endpoint multiple times with the same type and members will return the existing chat instead of creating a duplicate. This ensures you can safely call the endpoint without worrying about creating multiple chats with the same agent.

Example: If you call the endpoint twice with the same agent, both calls will return the same chatId.

  • Create Task - Create a task using the chat ID
  • List Chats - View all your chats (GET /v1/chats)
  • Get Chat - Retrieve chat details (GET /v1/chats/:chatId)
  • Add Members - Add members to a chat (POST /v1/chats/:chatId/members)
  • Remove Members - Remove members from a chat (DELETE /v1/chats/:chatId/members)

Need Help?​