LLM
Normalize chat history API
Normalizes a chat history for replay: merges consecutive same-role messages, drops empty messages, and validates roles — fixing the 'messages must alternate' / 'consecutive roles not allowed' errors many chat APIs throw. Answers 'how do I fix consecutive same-role messages?', 'how do I clean a chat history before resending it?'.
Price$0.02per request
MethodPOST
Route/v1/llm/normalize-messages
StatusLive
MIME typeapplication/json
Rate limit120/minute
Cache0s public
llmmessagesnormalizechat-historymergealternatededupagent
API URL
Integration docshttps://x402.hexl.dev/v1/llm/normalize-messagesExample request
{
"messages": [
{
"role": "system",
"content": "sys"
},
{
"role": "user",
"content": "a"
},
{
"role": "user",
"content": "b"
},
{
"role": "assistant",
"content": "c"
}
]
}Example response
{
"messages": [
{
"role": "system",
"content": "sys"
},
{
"role": "user",
"content": "a\n\nb"
},
{
"role": "assistant",
"content": "c"
}
],
"originalCount": 4,
"mergedCount": 3,
"collapsed": 1
}Input schema
{
"type": "object",
"required": [
"messages"
],
"properties": {
"messages": {
"type": "array",
"items": {
"type": "object"
}
},
"joiner": {
"type": "string",
"default": "\n\n"
}
}
}Output schema
{
"type": "object",
"additionalProperties": true
}