The Chat API provides endpoints to create and manage real-time chat conversations between users and AI agents. This API supports both REST endpoints for chat management and WebSocket connections for real-time messaging with streaming responses.
├── POST /api/v1/chats/ # Create chat ├── GET /api/v1/chats/user/{user_id} # List user chats├── GET /api/v1/chats/{chat_id} # Get specific chat├── GET /api/v1/chats/{chat_id}/messages # Get messages (paginated)└── DELETE /api/v1/chats/{chat_id} # Delete chat
The API implements reasonable rate limits to ensure service stability:
REST API: 100 requests per minute per tenant
WebSocket: 10 messages per second per connection
Concurrent Connections: 50 per tenant
Rate limit headers are included in REST API responses to help you track usage.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Lexicon Labs API","colors":{"primary":"#8D6553","light":"#07C983","dark":"#15803D"},"logo":{"light":"https://mintcdn.com/lexiconlabssro/aeH2Vgt_hMq_N5Yy/logo/light.svg?fit=max\u0026auto=format\u0026n=aeH2Vgt_hMq_N5Yy\u0026q=85\u0026s=c29e50beeefcdb0eba42fbb10ecf6c85","dark":"https://mintcdn.com/lexiconlabssro/aeH2Vgt_hMq_N5Yy/logo/dark.svg?fit=max\u0026auto=format\u0026n=aeH2Vgt_hMq_N5Yy\u0026q=85\u0026s=4e3f8a5f7eecbc651d8fbe13f25f2c4f"},"favicon":"/favicon.svg","navbar":{"links":[{"label":"Support","href":"mailto:hi@mintlify.com"}],"primary":{"type":"button","label":"Dashboard","href":"https://dashboard.mintlify.com"}},"footer":{"socials":{"x":"https://x.com/mintlify","github":"https://github.com/mintlify","linkedin":"https://linkedin.com/company/mintlify"}},"navigation":{"global":{"anchors":[{"anchor":"Documentation","icon":"book-open-cover","href":"https://docs.lexiconlabs.ai"},{"anchor":"Website","icon":"globe","href":"https://lexiconlabs.ai"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"lexiconlabssro","hasAudioNarration":false,"actualSubdomain":"lexiconlabssro","customDomains":["docs.lexiconlabs.ai"],"gitSource":{"type":"github","owner":"lexiconlabsai","repo":"ll-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"entitlements":{},"buildId":"6ae9280b38a52af76f41ce2c:success","clientVersion":"0.0.4102","searchFilterCounts":[{"language":"default","tag":"API Reference","count":10},{"language":"default","tag":"Chats","count":7},{"language":"default","tag":"Homeworks","count":3}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"api-reference/chats/introduction","slug":"/api-reference/chats/introduction","pageMetadata":{"title":"Chat API","description":"Endpoints for managing real-time chat conversations","href":"/api-reference/chats/introduction"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Endpoints for managing real-time chat conversations\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`chat-api-overview`,children:`Chat API Overview`}),`\n`,_jsx(_components.p,{children:`The Chat API provides endpoints to create and manage real-time chat conversations between users and AI agents. This API supports both REST endpoints for chat management and WebSocket connections for real-time messaging with streaming responses.`}),`\n`,_jsx(Heading,{level:`2`,id:`authentication`,children:`Authentication`}),`\n`,_jsx(_components.p,{children:`All API endpoints require an API key for authentication, which should be included in the request header.`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Header`}),`: `,_jsx(_components.code,{children:`X-API-Key`})]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Value`}),`: `,_jsx(_components.code,{children:`YOUR_API_KEY`})]}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`This API key is unique to your tenant and should be kept secure.`})}),`\n`,_jsx(Heading,{level:`2`,id:`key-concepts`,children:`Key Concepts`}),`\n`,_jsx(Heading,{level:`3`,id:`chat-sessions`,children:`Chat Sessions`}),`\n`,_jsx(_components.p,{children:`Chat sessions are created via the REST API and contain:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`User identification`}),`\n`,_jsx(_components.li,{children:`Chat metadata and configuration`}),`\n`,_jsx(_components.li,{children:`Message history`}),`\n`,_jsx(_components.li,{children:`Tenant isolation`}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`real-time-messaging`,children:`Real-Time Messaging`}),`\n`,_jsx(_components.p,{children:`Once a chat is created, users can connect via WebSocket to:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Send messages in real-time`}),`\n`,_jsx(_components.li,{children:`Receive streaming AI responses`}),`\n`,_jsx(_components.li,{children:`Get connection status updates`}),`\n`,_jsx(_components.li,{children:`Handle errors gracefully`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`authentication-flow`,children:`Authentication Flow`}),`\n`,_jsx(_components.p,{children:`The API uses a simple authentication flow:`}),`\n`,_jsx(CodeBlock,{numberOfLines:`2`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`API Key → Tenant → Access Control`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`API Key`}),`: Each tenant has a unique API key`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Tenant Resolution`}),`: The API key determines which tenant the request belongs to`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Access Control`}),`: All data is automatically scoped to the authenticated tenant`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`api-structure`,children:`API Structure`}),`\n`,_jsx(Heading,{level:`3`,id:`rest-api-chat-management`,children:`REST API (Chat Management)`}),`\n`,_jsx(CodeBlock,{numberOfLines:`6`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`6`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`├── POST /api/v1/chats/ # Create chat `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`├── GET /api/v1/chats/user/{user_id} # List user chats`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`├── GET /api/v1/chats/{chat_id} # Get specific chat`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`├── GET /api/v1/chats/{chat_id}/messages # Get messages (paginated)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`└── DELETE /api/v1/chats/{chat_id} # Delete chat`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`3`,id:`websocket-api-real-time-messaging`,children:`WebSocket API (Real-Time Messaging)`}),`\n`,_jsx(CodeBlock,{numberOfLines:`2`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`└── ws://localhost:8000/ws/chat # Real-time messaging`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`2`,id:`quick-start`,children:`Quick Start`}),`\n`,_jsx(Heading,{level:`3`,id:`1-create-a-chat`,children:`1. Create a Chat`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -X`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` POST`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"http://localhost:8000/api/v1/chats/\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"X-API-Key: your-tenant-api-key\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{\"user_id\": \"user123\"}'`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`2-connect-to-websocket`,children:`2. Connect to WebSocket`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` chatId`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"your-chat-id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`; `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// From step 1`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` ws`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` WebSocket`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`ws://localhost:8000/ws/chat?api_key=your-tenant-api-key\u0026user_id=user123\u0026chat_id=\"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chatId`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`3-send-messages`,children:`3. Send Messages`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ws`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Hello, I need help with my account\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}));`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`pagination`,children:`Pagination`}),`\n`,_jsxs(_components.p,{children:[`Endpoints that return collections (like chat messages) support pagination using `,_jsx(_components.code,{children:`offset`}),` and `,_jsx(_components.code,{children:`limit`}),` parameters:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`offset`}),`: The number of items to skip before starting to collect results (default 0)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`limit`}),`: The maximum number of results to return (default 50)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`order`}),`: Sort order for messages, either ‘asc’ or ‘desc’ (default ‘asc’)`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`The response includes pagination metadata to help with navigation:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`7`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`}),_jsx(_components.span,{style:{color:`#82071E`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#F44747`,\"--shiki-dark-font-style\":`inherit`},children:`...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"total\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`147`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"offset\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"limit\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`50`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"has_more\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`true`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`websocket-events`,children:`WebSocket Events`}),`\n`,_jsx(_components.p,{children:`The WebSocket connection provides several event types:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Connection Events`}),`: `,_jsx(_components.code,{children:`connection_established`}),`, `,_jsx(_components.code,{children:`user_created`})]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Message Events`}),`: `,_jsx(_components.code,{children:`message_received`}),`, `,_jsx(_components.code,{children:`message_stream_started`}),`, `,_jsx(_components.code,{children:`message_stream_token`}),`, `,_jsx(_components.code,{children:`message_stream_ended`})]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Error Events`}),`: `,_jsx(_components.code,{children:`error`}),` with specific error codes`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`error-handling`,children:`Error Handling`}),`\n`,_jsx(_components.p,{children:`The API provides clear error responses with:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Error Codes`}),`: Standardized error identifiers`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Error Messages`}),`: Human-readable descriptions`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Details`}),`: Additional context and suggested fixes`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`Common error scenarios:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Invalid API keys`}),`\n`,_jsx(_components.li,{children:`Chat not found`}),`\n`,_jsx(_components.li,{children:`Missing required parameters`}),`\n`,_jsx(_components.li,{children:`Connection timeouts`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`best-practices`,children:`Best Practices`}),`\n`,_jsx(Heading,{level:`3`,id:`chat-management`,children:`Chat Management`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Create chats via REST API before connecting to WebSocket`}),`\n`,_jsx(_components.li,{children:`Store chat IDs for future reference`}),`\n`,_jsx(_components.li,{children:`Use meaningful titles and metadata for organization`}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`websocket-connections`,children:`WebSocket Connections`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Handle connection errors gracefully`}),`\n`,_jsx(_components.li,{children:`Implement reconnection logic for network issues`}),`\n`,_jsx(_components.li,{children:`Process streaming tokens incrementally for better UX`}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`security`,children:`Security`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Keep API keys secure and never expose them in client-side code`}),`\n`,_jsx(_components.li,{children:`Validate user permissions before granting chat access`}),`\n`,_jsx(_components.li,{children:`Use HTTPS/WSS in production environments`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`rate-limits`,children:`Rate Limits`}),`\n`,_jsx(_components.p,{children:`The API implements reasonable rate limits to ensure service stability:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`REST API`}),`: 100 requests per minute per tenant`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`WebSocket`}),`: 10 messages per second per connection`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Concurrent Connections`}),`: 50 per tenant`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`Rate limit headers are included in REST API responses to help you track usage.`})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Chat API","description":"Endpoints for managing real-time chat conversations","href":"/api-reference/chats/introduction"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Chat API Overview","slug":"chat-api-overview","depth":2,"children":[]},{"title":"Authentication","slug":"authentication","depth":2,"children":[]},{"title":"Key Concepts","slug":"key-concepts","depth":2,"children":[{"title":"Chat Sessions","slug":"chat-sessions","depth":3,"children":[]},{"title":"Real-Time Messaging","slug":"real-time-messaging","depth":3,"children":[]}]},{"title":"Authentication Flow","slug":"authentication-flow","depth":2,"children":[]},{"title":"API Structure","slug":"api-structure","depth":2,"children":[{"title":"REST API (Chat Management)","slug":"rest-api-chat-management","depth":3,"children":[]},{"title":"WebSocket API (Real-Time Messaging)","slug":"websocket-api-real-time-messaging","depth":3,"children":[]}]},{"title":"Quick Start","slug":"quick-start","depth":2,"children":[{"title":"1. Create a Chat","slug":"1-create-a-chat","depth":3,"children":[]},{"title":"2. Connect to WebSocket","slug":"2-connect-to-websocket","depth":3,"children":[]},{"title":"3. Send Messages","slug":"3-send-messages","depth":3,"children":[]}]},{"title":"Pagination","slug":"pagination","depth":2,"children":[]},{"title":"WebSocket Events","slug":"websocket-events","depth":2,"children":[]},{"title":"Error Handling","slug":"error-handling","depth":2,"children":[]},{"title":"Best Practices","slug":"best-practices","depth":2,"children":[{"title":"Chat Management","slug":"chat-management","depth":3,"children":[]},{"title":"WebSocket Connections","slug":"websocket-connections","depth":3,"children":[]},{"title":"Security","slug":"security","depth":3,"children":[]}]},{"title":"Rate Limits","slug":"rate-limits","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"lexiconlabssro","siteName":"Lexicon Labs API","title":"Chat API - Lexicon Labs API","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-01-07T08:05:02.986Z","originalFileLocation":"api-reference/chats/introduction.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Endpoints for managing real-time chat conversations\">\u003cmeta data-mint-head name=\"application-name\" content=\"Lexicon Labs API\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Chat API - Lexicon Labs API\">\u003cmeta data-mint-head property=\"og:description\" content=\"Endpoints for managing real-time chat conversations\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Lexicon Labs API\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.lexiconlabs.ai/api-reference/chats/introduction\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://lexiconlabssro.mintlify.site/_mintlify/api/og/v2?division=Chats\u0026amp;title=Chat+API\u0026amp;description=Endpoints+for+managing+real-time+chat+conversations\u0026amp;theme=2c403c8378ccb8fb17b6aaf4\u0026amp;signature=d8ab620b6ef7466c186472455a1e28b94b4773149deeded5ab741351a5b4cac5\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Chat API - Lexicon Labs API\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Endpoints for managing real-time chat conversations\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://lexiconlabssro.mintlify.site/_mintlify/api/og/v2?division=Chats\u0026amp;title=Chat+API\u0026amp;description=Endpoints+for+managing+real-time+chat+conversations\u0026amp;theme=2c403c8378ccb8fb17b6aaf4\u0026amp;signature=d8ab620b6ef7466c186472455a1e28b94b4773149deeded5ab741351a5b4cac5\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/lexiconlabssro/yAchMQgn3TFPLUit/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Lexicon Labs API\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#8D6553\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.lexiconlabs.ai/api-reference/chats/introduction\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/api-reference/chats/introduction.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.lexiconlabs.ai/#organization\",\"name\":\"Lexicon Labs API\",\"url\":\"https://docs.lexiconlabs.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/lexiconlabssro/aeH2Vgt_hMq_N5Yy/logo/light.svg?fit=max\u0026auto=format\u0026n=aeH2Vgt_hMq_N5Yy\u0026q=85\u0026s=c29e50beeefcdb0eba42fbb10ecf6c85\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.lexiconlabs.ai#website\",\"name\":\"Lexicon Labs API\",\"url\":\"https://docs.lexiconlabs.ai\",\"publisher\":{\"@id\":\"https://docs.lexiconlabs.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.lexiconlabs.ai/api-reference/chats/introduction#webpage\",\"url\":\"https://docs.lexiconlabs.ai/api-reference/chats/introduction\",\"name\":\"Chat API\",\"description\":\"Endpoints for managing real-time chat conversations\",\"dateModified\":\"2026-01-07T08:05:02.986Z\",\"isPartOf\":{\"@id\":\"https://docs.lexiconlabs.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.lexiconlabs.ai/api-reference/chats/introduction#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.lexiconlabs.ai/api-reference/chats/introduction#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lexicon Labs API\",\"item\":\"https://docs.lexiconlabs.ai\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Chat API\",\"item\":\"https://docs.lexiconlabs.ai/api-reference/chats/introduction\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.lexiconlabs.ai/api-reference/chats/introduction#article\",\"headline\":\"Chat API\",\"name\":\"Chat API\",\"description\":\"Endpoints for managing real-time chat conversations\",\"url\":\"https://docs.lexiconlabs.ai/api-reference/chats/introduction\",\"mainEntityOfPage\":{\"@id\":\"https://docs.lexiconlabs.ai/api-reference/chats/introduction#webpage\"},\"dateModified\":\"2026-01-07T08:05:02.986Z\",\"publisher\":{\"@id\":\"https://docs.lexiconlabs.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.lexiconlabs.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Lexicon Labs API\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Lexicon Labs API\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/api-reference/chats/introduction.md","siteName":"Lexicon Labs API","nav":{"global":{"anchors":[{"anchor":"Documentation","icon":"book-open-cover","href":"https://docs.lexiconlabs.ai"},{"anchor":"Website","icon":"globe","href":"https://lexiconlabs.ai"}]},"tabs":[{"tab":"API Reference","groups":[{"group":"Chats","pages":[{"title":"Chat API","href":"/api-reference/chats/introduction"},{"title":"Create Chat","api":"POST /api/v1/chats/","description":null,"href":"/api-reference/chats/create"},{"title":"List User Chats","api":"GET /api/v1/chats/user/{user_id}","href":"/api-reference/chats/list-user-chats"},{"title":"Get Chat","api":"GET /api/v1/chats/{chat_id}","href":"/api-reference/chats/get-chat"},{"title":"Get Chat Messages","api":"GET /api/v1/chats/{chat_id}/messages","href":"/api-reference/chats/get-messages"},{"title":"Delete Chat","api":"DELETE /api/v1/chats/{chat_id}","href":"/api-reference/chats/delete-chat"},{"title":"WebSocket Integration","href":"/api-reference/chats/websocket"}]},{"group":"Homeworks","pages":[{"title":"Homeworks API","href":"/api-reference/homeworks/introduction"},{"title":"Get Homework Assignments","api":"GET /v1/homeworks","href":"/api-reference/homeworks/get"},{"title":"Create Homework Submission","api":"POST /v1/homeworks/:homeworkId/submissions","href":"/api-reference/homeworks/submissions/create"}]}]}]},"basePath":"","title":"Chat API - Lexicon Labs API","buildId":"dpl_596ePT575z4qnAFksq1biRW97aLY","deploymentId":"dpl_596ePT575z4qnAFksq1biRW97aLY","dynamics":[],"chunks":[]}