RATIO MACHINA STARTER logo

MERCURY

Conversation Design RPC API

The Conversation Design RPC API provides advanced operations that go beyond simple CRUD, including resource upserts, AI-powered message generation, and skill execution. These endpoints are optimized for complex workflows and external system integrations.

Base URL & Authentication

Base URL: https://your-api-name.mercury.ratiomachina.com
Authentication: x-mercury-api-key: YOUR_API_KEY

Create Conversation (Resource Upsert)

šŸš€ Primary Integration Endpoint: This is Mercury's most powerful endpoint, designed for external platform integrations. It automatically handles persona, contact, and conversation creation/updates, then generates AI responses in a single call.

POST /conversations

Key Features

  • Resource Upserts: Creates or updates personas, contacts, and conversations automatically
  • External ID Support: Uses external IDs for seamless integration with CRM systems
  • AI Response Generation: Automatically generates contextual AI responses
  • Conversation Threading: Intelligently continues existing conversations
  • Single API Call: Handles complete workflow in one request

Use Cases

  • CRM webhook integrations (GoHighLevel, Kartra)
  • Marketing automation workflows (Zapier, n8n, Make)
  • Website form submissions
  • Live chat system integrations
  • Multi-channel conversation management

Request Flow

  1. 1. Upsert Persona (create or update by externalId)
  2. 2. Upsert Contact (create or update by externalId)
  3. 3. Upsert Conversation (create or find existing)
  4. 4. Create incoming message from contact
  5. 5. Generate AI response using persona configuration
  6. 6. Return complete conversation context

Complete Request Example

Request Body

{
  "persona": {
    "externalId": "sales-alex-v1",
    "name": "Sales Assistant Alex",
    "data": {
      "role": "sales",
      "tone": "professional_friendly",
      "business_description": "We provide AI-powered conversation solutions for businesses looking to automate customer interactions while maintaining quality and personalization.",
      "channel": "sms",
      "identity": {
        "name": "Alex",
        "role": "Sales Representative"
      },
      "offers": [
        {
          "title": "Free Consultation",
          "description": "30-minute strategy session",
          "value_proposition": "Personalized insights"
        },
        {
          "title": "Product Demo",
          "description": "Live platform demonstration",
          "value_proposition": "See our solution in action"
        }
      ],
      "objections": [
        {
          "objection": "too expensive",
          "response": "I understand budget is important. Let's explore flexible pricing options that provide strong ROI."
        },
        {
          "objection": "need to think about it",
          "response": "Absolutely! What specific aspects would help with your decision? I can provide additional information."
        }
      ]
    }
  },
  "contact": {
    "externalId": "crm_lead_12345",
    "name": "Sarah Johnson",
    "data": {
      "email": "sarah@techcorp.com",
      "phone": "+1234567890",
      "company": "TechCorp Inc",
      "title": "Marketing Director",
      "lead_source": "website_form",
      "lead_score": 85,
      "interests": ["automation", "customer_service"]
    }
  },
  "conversation": {
    "externalId": "conv_techcorp_sarah_website",
    "channel": "sms",
    "data": {
      "campaign": "q1_2024_website_leads",
      "priority": "high"
    }
  },
  "message": {
    "content": "Hi! I saw your AI conversation platform and I'm interested in learning how it could help us automate our customer support. Can you tell me more about implementation timelines?",
    "sender": "contact",
    "data": {
      "source": "website_form",
      "form_data": {
        "interest": "customer_support_automation",
        "company_size": "50-100_employees",
        "current_solution": "zendesk"
      }
    }
  }
}

Response Example

{
  "conversation": {
    "id": "uuid-conv-123",
    "externalId": "conv_techcorp_sarah_website",
    "personaId": "uuid-persona-456",
    "contactId": "uuid-contact-789",
    "channel": "sms",
    "messageCount": 2,
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-15T10:30:15Z"
  },
  "persona": {
    "id": "uuid-persona-456",
    "externalId": "sales-alex-v1",
    "name": "Sales Assistant Alex",
    "data": {
      "role": "sales",
      "tone": "professional_friendly"
    },
    "wasCreated": false,
    "wasUpdated": true
  },
  "contact": {
    "id": "uuid-contact-789",
    "externalId": "crm_lead_12345",
    "name": "Sarah Johnson",
    "data": {
      "email": "sarah@techcorp.com",
      "company": "TechCorp Inc"
    },
    "wasCreated": true,
    "wasUpdated": false
  },
  "messages": [
    {
      "id": "uuid-msg-001",
      "conversationId": "uuid-conv-123",
      "content": "Hi! I saw your AI conversation platform and I'm interested in learning how it could help us automate our customer support. Can you tell me more about implementation timelines?",
      "sender": "contact",
      "data": {
        "source": "website_form"
      },
      "createdAt": "2024-01-15T10:30:00Z"
    },
    {
      "id": "uuid-msg-002",
      "conversationId": "uuid-conv-123",
      "content": "Hello Sarah! Thanks for your interest in our AI conversation platform. I'd be happy to help you understand how we can streamline your customer support automation.\n\nFor a company like TechCorp with 50-100 employees transitioning from Zendesk, our typical implementation timeline is 2-3 weeks, including:\n\n• Initial setup and configuration (3-5 days)\n• Integration with your existing systems (5-7 days)\n• Team training and testing (3-5 days)\n• Go-live support\n\nGiven your focus on customer support automation, I'd love to show you our live demo that demonstrates how we've helped similar companies reduce response times by 60% while maintaining quality.\n\nWould you be interested in a 30-minute consultation this week to discuss your specific requirements and see the platform in action?",
      "sender": "persona",
      "data": {
        "generated": true,
        "confidence": 0.92,
        "contextUsed": [
          "contact_company_info",
          "current_solution",
          "implementation_timeline_inquiry"
        ]
      },
      "createdAt": "2024-01-15T10:30:15Z"
    }
  ]
}

Minimal Request Example

For simpler integrations, you can provide minimal information. Mercury will use sensible defaults and existing data where available.

Minimal Request

{
  "persona": {
    "externalId": "support-bot-v1"
  },
  "contact": {
    "externalId": "customer_456",
    "name": "John Smith"
  },
  "conversation": {
    "externalId": "conv_support_john_456",
    "channel": "email"
  },
  "message": {
    "content": "My order #12345 hasn't arrived yet. Can you help?",
    "sender": "contact"
  }
}

Response

{
  "conversation": { ... },
  "persona": {
    "id": "uuid-persona-789",
    "externalId": "support-bot-v1",
    "name": "Customer Support Bot",
    "wasCreated": false,
    "wasUpdated": false
  },
  "contact": {
    "id": "uuid-contact-012",
    "externalId": "customer_456", 
    "name": "John Smith",
    "wasCreated": true,
    "wasUpdated": false
  },
  "messages": [
    {
      "content": "My order #12345 hasn't arrived yet. Can you help?",
      "sender": "contact"
    },
    {
      "content": "I'd be happy to help you track your order #12345, John. Let me look that up for you right away and provide you with the current status and expected delivery information.",
      "sender": "persona",
      "data": {
        "generated": true,
        "confidence": 0.88
      }
    }
  ]
}

Error Handling

Validation Errors

{
  "error": "Validation failed",
  "code": "VALIDATION_ERROR",
  "details": {
    "field": "persona.externalId",
    "message": "External ID is required for persona upsert"
  }
}

Generation Errors

{
  "error": "AI response generation failed",
  "code": "GENERATION_ERROR", 
  "details": {
    "reason": "Token limit exceeded",
    "conversationId": "uuid-conv-123"
  },
  "conversation": { ... },
  "messages": [
    {
      "content": "User message",
      "sender": "contact"
    }
  ]
}

Generate Next Message

POST /generate-next-message

Generates AI-powered responses for existing conversations without modifying the conversation history. This endpoint is useful for generating draft responses, A/B testing different responses, or providing response suggestions.

Request Body

{
  "conversationExternalId": "conv_support_sarah_123",
  "personaExternalId": "support-specialist-v1",
  "context": {
    "urgency": "high",
    "customerTier": "premium",
    "previousIssues": [
      {
        "issueId": "ISSUE-001",
        "type": "billing_question",
        "resolved": true
      }
    ]
  },
  "constraints": {
    "maxLength": 300,
    "tone": "empathetic_urgent",
    "includeNextSteps": true
  }
}

Response Example

{
  "generatedMessage": {
    "content": "I understand this is urgent, Sarah, and I apologize for the inconvenience. Since you're one of our premium customers and I see you had a billing question resolved recently, I want to make sure we address this quickly and thoroughly.\n\nNext steps:\n1. I'm escalating this to our senior technical team\n2. You'll receive an update within 2 hours\n3. I'll personally follow up to ensure resolution\n\nIs there anything else I can clarify in the meantime?",
    "confidence": 0.94,
    "generationTime": 1.2,
    "contextUsed": [
      "conversation_history",
      "persona_configuration", 
      "contact_tier_info",
      "previous_issue_history"
    ]
  },
  "conversation": {
    "id": "uuid-conv-456",
    "externalId": "conv_support_sarah_123",
    "messageCount": 8,
    "lastMessageAt": "2024-01-15T14:22:00Z"
  },
  "persona": {
    "id": "uuid-persona-789",
    "externalId": "support-specialist-v1",
    "name": "Support Specialist Bot"
  }
}

šŸ’” Note: This endpoint generates responses but doesn't add them to the conversation. Use the REST API or the main /conversations RPC endpoint to actually send the generated message.

Execute Skill

POST /execute-skill

Executes a specific skill within the context of a conversation, enabling integration with external APIs, data processing, and specialized functionality during conversations.

Request Body

{
  "skillExternalId": "sentiment_analyzer_v1",
  "conversationExternalId": "conv_support_john_456",
  "input": {
    "text": "I'm really frustrated with this service. This is the third time I've had to call about the same issue and nobody seems to be able to help me!",
    "includeHistory": true,
    "analysisDepth": "detailed"
  },
  "context": {
    "contactId": "customer_789",
    "conversationStage": "escalation_review",
    "channelType": "phone_call"
  }
}

Response Example

{
  "execution": {
    "id": "exec-uuid-123",
    "skillId": "skill-uuid-456",
    "conversationId": "conv-uuid-789",
    "input": {
      "text": "I'm really frustrated...",
      "includeHistory": true,
      "analysisDepth": "detailed"
    },
    "output": {
      "sentiment": "negative",
      "confidence": 0.87,
      "emotions": [
        {
          "emotion": "frustration",
          "intensity": 0.92
        },
        {
          "emotion": "disappointment", 
          "intensity": 0.76
        }
      ],
      "escalationRecommended": true,
      "priority": "high",
      "suggestedActions": [
        "immediate_supervisor_escalation",
        "customer_retention_alert",
        "priority_queue_placement"
      ]
    },
    "status": "success",
    "executionTime": 0.8,
    "createdAt": "2024-01-15T10:30:00Z"
  },
  "skill": {
    "id": "skill-uuid-456",
    "externalId": "sentiment_analyzer_v1",
    "name": "Advanced Sentiment Analyzer",
    "data": {
      "role": "sentiment_analysis",
      "version": "2.1"
    }
  },
  "conversation": {
    "id": "conv-uuid-789",
    "externalId": "conv_support_john_456"
  }
}

Common Skill Types & Examples

Sentiment Analysis

{
  "skillExternalId": "sentiment_v1",
  "conversationExternalId": "conv_123",
  "input": {
    "text": "Thanks so much! This solved my problem perfectly.",
    "analyzeIntensity": true
  }
}

Knowledge Base Lookup

{
  "skillExternalId": "kb_lookup_v1", 
  "conversationExternalId": "conv_456",
  "input": {
    "query": "password reset procedure",
    "categories": ["account_management"],
    "maxResults": 5
  }
}

JSON Parser

{
  "skillExternalId": "json_parser_v1",
  "conversationExternalId": "conv_789", 
  "input": {
    "jsonData": "{\"order\": {...}}",
    "extractFields": ["orderId", "status", "total"],
    "validateSchema": true
  }
}

Custom API Integration

{
  "skillExternalId": "crm_lookup_v1",
  "conversationExternalId": "conv_012",
  "input": {
    "customerId": "CUST-12345",
    "fields": ["account_status", "recent_orders"],
    "includeNotes": true
  }
}

Legacy Operations

āš ļø Legacy Endpoints: These endpoints are maintained for backward compatibility. New integrations should use the modern /conversations RPC endpoint for better functionality and performance.

POST /update-conversation

Legacy endpoint for updating conversation metadata and triggering AI responses.

Request Body

{
  "conversationId": "conv-uuid-123",
  "updates": {
    "priority": "high",
    "tags": ["escalated", "billing"]
  },
  "generateResponse": true
}

Response Example

{
  "conversation": {
    "id": "conv-uuid-123",
    "priority": "high",
    "tags": ["escalated", "billing"],
    "updatedAt": "2024-01-15T10:30:00Z"
  },
  "generatedMessage": {
    "content": "I understand this is a priority...",
    "createdAt": "2024-01-15T10:30:15Z"
  }
}

POST /message

Legacy endpoint for creating individual messages.

Request Body

{
  "conversationId": "conv-uuid-123",
  "content": "Thank you for the help!",
  "sender": "contact",
  "generateResponse": true
}

Response Example

{
  "message": {
    "id": "msg-uuid-456",
    "content": "Thank you for the help!",
    "sender": "contact",
    "createdAt": "2024-01-15T10:30:00Z"
  },
  "response": {
    "id": "msg-uuid-789", 
    "content": "You're very welcome! Is there anything else I can help you with today?",
    "sender": "persona",
    "createdAt": "2024-01-15T10:30:05Z"
  }
}

Best Practices for RPC API Usage

Performance Optimization

  • Use external IDs consistently for efficient resource lookups
  • Batch related operations using the /conversations endpoint
  • Implement proper error handling and retry logic
  • Cache persona and contact data on your side when possible

Integration Guidelines

  • Always include external IDs for CRM/platform integration
  • Use meaningful external ID patterns (e.g., crm_lead_12345)
  • Implement webhook endpoints to receive Mercury responses
  • Monitor conversation quality using the evaluation APIs
Transcend the hype with MERCURY by Ratio Machina