Idempotency
- `Idempotency-Key` is supported only for non-streaming requests.
- Reusing the same key with a different request body returns `409 idempotency_conflict`.
Streaming
- When `stream: true`, the response content type becomes `text/event-stream`.
- The first event is `public_api_conversation`, followed by sanitized token, citation, source, and completion events, and then `public_api_complete`.
- Streaming metadata contains only `tokens_used`.
curl -X POST "https://api.mortgageguidelines.com/v1/messages" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer mgapi_live_your_key_here" \
-H "Idempotency-Key: first-turn-user-123-001" \
-d '{
"message": "What are FHA gift fund rules?",
"user": {
"external_user_id": "user_123",
"email": "user@example.com",
"name": "Test User"
},
"conversation": {
"title": "FHA gift funds",
"metadata": {
"external_ticket_id": "ticket_789"
}
},
"metadata": {
"channel": "crm"
}
}'
const response = await fetch("https://api.mortgageguidelines.com/v1/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer mgapi_live_your_key_here",
"Idempotency-Key": "first-turn-user-123-001",
},
body: JSON.stringify({
"message": "What are FHA gift fund rules?",
"user": {
"external_user_id": "user_123",
"email": "user@example.com",
"name": "Test User"
},
"conversation": {
"title": "FHA gift funds",
"metadata": {
"external_ticket_id": "ticket_789"
}
},
"metadata": {
"channel": "crm"
}
}),
});
const data = await response.json();
{
"request_id": "req_9b8f0b5fcb5b4eaa",
"conversation_id": "conv_3c2fd2bcf41f4f12",
"conversation_created": true,
"message_id": "msg_1fecc99b7f334e6c",
"response": "Gift funds are generally allowed with documentation.",
"citations": [
{
"documentTitle": "Fannie Mae Selling Guide",
"section": "B3-4.3-04",
"url": "https://selling-guide.fanniemae.com/",
"pageNumber": 12
}
],
"sources": [
{
"url": "https://selling-guide.fanniemae.com/",
"title": "Fannie Mae Selling Guide",
"description": "Document from selling-guide.fanniemae.com",
"citationCount": 1
}
],
"metadata": {
"tokens_used": 123
}
}
data: {"type":"public_api_conversation","request_id":"req_9b8f0b5fcb5b4eaa","conversation_id":"conv_3c2fd2bcf41f4f12","conversation_created":true}
data: {"type":"content","content":"Gift funds are generally allowed with "}
data: {"type":"content_postprocessed","content":"Gift funds are generally allowed with documentation."}
data: {"type":"complete","metadata":{"tokens_used":123}}
data: {"type":"public_api_complete","request_id":"req_9b8f0b5fcb5b4eaa","conversation_id":"conv_3c2fd2bcf41f4f12","message_id":"msg_1fecc99b7f334e6c"}