Overview
The Chat API provides conversational AI capabilities with integrated literature search, hypothesis generation, and data analysis. It supports both synchronous and asynchronous execution modes.
Authentication
All chat endpoints require authentication via JWT token or API key.
Bearer token for JWT authentication
Alternative API key authentication
Execution Modes
The API operates in two modes based on the USE_JOB_QUEUE environment variable:
In-Process Mode (USE_JOB_QUEUE=false): Executes synchronously and returns results directly
Queue Mode (USE_JOB_QUEUE=true): Enqueues job to BullMQ and returns job ID for polling
POST /api/chat
Send a message to the AI agent for processing.
Request Body
The user’s question or message to process
Optional conversation ID for multi-turn conversations. Auto-generated if not provided.
Optional array of files to upload and analyze (supports CSV, PDF, images)
Response (In-Process Mode)
Returns 200 OK with the AI’s response.
The AI-generated response text
User ID for tracking (included for x402 payment users)
Response (Queue Mode)
Returns 202 Accepted with job information.
BullMQ job ID for status polling
Database message ID for tracking
Conversation ID for multi-turn context
User ID for ownership verification
Example: Basic Chat
curl -X POST https://api.bioagents.xyz/api/chat \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "What are the key pathways involved in autophagy?"
}'
Example Response (In-Process)
{
"text" : "Autophagy involves several key pathways: \n\n 1. **mTOR Pathway**: The master regulator that inhibits autophagy when nutrients are abundant... \n\n 2. **ULK1 Complex**: Initiates autophagosome formation..." ,
"userId" : "usr_abc123"
}
Example: Multi-Turn Conversation
curl -X POST https://api.bioagents.xyz/api/chat \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "What about the role of AMPK in this process?",
"conversationId": "conv_xyz789"
}'
Example: Chat with File Upload
curl -X POST https://api.bioagents.xyz/api/chat \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-F "message=Analyze this gene expression dataset" \
-F "files=@expression_data.csv"
GET /api/chat/status/:jobId
Check the status of a queued chat job (only available when USE_JOB_QUEUE=true).
Path Parameters
The job ID returned from POST /api/chat
Response Fields
Job status: queued, active, completed, failed, or not_found
Chat result (only present when status is completed) The AI-generated response
Progress information (present during active execution) Completion percentage (0-100)
Error message (only present when status is failed)
Number of retry attempts made
Example: Check Job Status
curl https://api.bioagents.xyz/api/chat/status/msg_abc123
Example Response: Completed
{
"status" : "completed" ,
"result" : {
"text" : "Based on the literature search, autophagy is regulated by..." ,
"userId" : "usr_abc123"
}
}
Example Response: Processing
{
"status" : "active" ,
"progress" : {
"stage" : "literature_search" ,
"percent" : 45
},
"attemptsMade" : 0
}
POST /api/chat/retry/:jobId
Manually retry a failed chat job.
Authentication Required
Must be the owner of the job being retried.
Path Parameters
Response Fields
Whether retry was successful
Human-readable status message
Number of previous retry attempts
Example: Retry Failed Job
curl -X POST https://api.bioagents.xyz/api/chat/retry/msg_abc123 \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Example Response
{
"ok" : true ,
"jobId" : "msg_abc123" ,
"status" : "retrying" ,
"message" : "Job has been queued for retry" ,
"previousAttempts" : 1
}
Error Codes
Missing required field (message) or invalid request format
Missing or invalid authentication credentials
Attempting to access another user’s job
Job not found or queue mode not enabled
Too many requests - rate limit exceeded
Server error during processing
Features
The Chat API automatically:
Literature Search : Queries OpenScholar, BioLit, and knowledge bases
Hypothesis Generation : Creates testable hypotheses when appropriate
File Processing : Extracts data from CSV, PDF, and image files
Context Retention : Maintains conversation history across messages
Token Usage Tracking : Monitors LLM token consumption per message
Rate Limits
Rate limits are configurable per authentication method:
JWT Users : Default 60 requests/minute
API Key Users : Custom limits based on tier
Anonymous Users : 10 requests/minute (if enabled)