Endpoint
Retrieves the authenticated user’s debate history, including complete debate transcripts, synthesis reports, and metadata. Results are sorted by creation date (most recent first).
Authentication
Requires valid NextAuth session. Returns 401 Unauthorized if not authenticated.
Request
No query parameters or request body required. The endpoint automatically filters debates by the authenticated user’s ID.
Example Request
curl -X GET https://your-domain.com/api/debate/history \
-H "Cookie: next-auth.session-token=<token>"
Response
Returns a JSON array of debate objects, limited to the 20 most recent debates .
Response Fields
Array of debate objects Show Debate object structure
Unique debate identifier (format: debate_<timestamp>_<random>)
The debate topic or question
User’s profile information at the time of the debate Show userProfile properties
URL to user’s avatar image
User biography or description
Opponent’s profile information Show opponentProfile properties
Opponent’s title or description
Complete debate transcript as an array of messages Show Message object structure
Speaker role: "user" (user’s AI agent) or "opponent"
Unix timestamp in milliseconds when the message was created
AI-generated debate analysis (null if debate incomplete) Show synthesis properties
Array of points where both parties agreed
Array of core disagreement points
Debate outcome: "user", "opponent", or "tie"
Explanation for winner determination
Overall conclusion about the debate topic
synthesis.recommendations
Array of recommendations for readers
Debate status: "pending", "in_progress", or "completed"
ID of the user who created the debate
ISO 8601 timestamp when the debate was created
ISO 8601 timestamp when the debate was last updated
Example Response
[
{
"id" : "debate_1709510400000_abc123" ,
"topic" : "远程工作是否应该成为主流?" ,
"userProfile" : {
"id" : "user_123" ,
"name" : "张三" ,
"avatar" : "https://example.com/avatar.jpg" ,
"bio" : "科技从业者,关注未来工作方式"
},
"opponentProfile" : {
"id" : "opponent_conservative" ,
"name" : "李明" ,
"avatar" : "https://example.com/opponent-avatar.jpg" ,
"bio" : "传统管理专家"
},
"messages" : [
{
"role" : "user" ,
"name" : "张三" ,
"content" : "我认为远程工作能够提高效率,减少通勤时间,让员工有更好的工作生活平衡。" ,
"timestamp" : 1709510400000
},
{
"role" : "opponent" ,
"name" : "李明" ,
"content" : "但是远程工作会降低团队凝聚力,沟通效率也会受到影响。" ,
"timestamp" : 1709510410000
}
],
"synthesis" : {
"consensus" : [
"远程工作确实存在沟通挑战" ,
"不同行业适用性不同"
],
"disagreements" : [
"效率提升是否显著" ,
"团队文化能否维持"
],
"winner" : "user" ,
"winnerReason" : "提供了更多数据支持和实际案例,论证更充分" ,
"conclusion" : "远程工作的成功取决于组织文化、工具支持和管理方式的配合" ,
"recommendations" : [
"建议企业采用混合办公模式" ,
"重视远程协作工具的投资"
]
},
"status" : "completed" ,
"userId" : "user_123" ,
"createdAt" : "2026-03-03T10:00:00.000Z" ,
"updatedAt" : "2026-03-03T10:05:30.000Z"
},
{
"id" : "debate_1709424000000_xyz789" ,
"topic" : "人工智能是否会取代人类工作?" ,
"userProfile" : { /* ... */ },
"opponentProfile" : { /* ... */ },
"messages" : [ /* ... */ ],
"synthesis" : { /* ... */ },
"status" : "completed" ,
"userId" : "user_123" ,
"createdAt" : "2026-03-02T10:00:00.000Z" ,
"updatedAt" : "2026-03-02T10:06:15.000Z"
}
]
Response Characteristics
Sorting : Debates are sorted by createdAt in descending order (newest first)Limit : Maximum of 20 debates returnedFiltering : Only debates belonging to the authenticated user are returnedCleanup : MongoDB internal fields (_id, __v) are removed from the response
Error Responses
401 Unauthorized
Returned when the request lacks valid authentication.
{
"error" : "Unauthorized"
}
500 Internal Server Error
Returned when database connection or query fails.
{
"error" : "Failed to load history"
}
Use Cases
Display User’s Debate History
Retrieve all debates to show in a user dashboard or profile page.
fetch ( '/api/debate/history' )
. then ( res => res . json ())
. then ( debates => {
debates . forEach ( debate => {
console . log ( ` ${ debate . topic } - Winner: ${ debate . synthesis ?. winner } ` );
});
});
Filter Completed Debates
Filter for debates that have synthesis data.
fetch ( '/api/debate/history' )
. then ( res => res . json ())
. then ( debates => {
const completed = debates . filter ( d => d . status === 'completed' && d . synthesis );
console . log ( ` ${ completed . length } completed debates` );
});
Calculate win rate from debate history.
fetch ( '/api/debate/history' )
. then ( res => res . json ())
. then ( debates => {
const wins = debates . filter ( d => d . synthesis ?. winner === 'user' ). length ;
const total = debates . filter ( d => d . synthesis ). length ;
const winRate = ( wins / total * 100 ). toFixed ( 1 );
console . log ( `Win rate: ${ winRate } %` );
});
Database Schema Reference
The response structure matches the MongoDB Debate model defined in /src/models/Debate.ts:62-102.
The history endpoint returns debates in their stored format. Incomplete debates (status: "in_progress") may have empty messages arrays or null synthesis objects.
Start New Debate Create a new debate session to add to your history