Developer Center

Open APIs & Webhooks to embed customer service into your systems

API overview: TianKey Cloud provides RESTful APIs and Webhook subscriptions. Base APIs come with Pro / Flagship plans; full access and higher quotas require Developer Membership. Apply for an API Key (X-API-Key) in your console under Settings → Open Platform.

1. Authentication

All API requests require your API Key and tenant ID:

X-API-Key: <your-api-key>
X-Company-Id: <tenant-id>
Content-Type: application/json

Create and revoke keys anytime in Console → Settings → Open Platform. All endpoints use HTTPS and return JSON.

2. Chat APIs

POST/api/v1/chat/message

Send a customer message and get the AI reply (synchronous). For custom chat entry points and in-app conversations.

{
  "session_id": "sess_xxxx",      // optional, auto-created if omitted
  "content": "Do you have a plan with WeChat Pay?",
  "source": "app",
  "user_id": "u_10001"            // optional business user ID
}
GET/api/v1/chat/messages?session_id=sess_xxxx&limit=20

Paginated message history with intent and handover metadata.

POST/api/v1/chat/session

Create a session with an optional bot (bot_id), channel and user tags.

3. Knowledge Base APIs

GET/api/v1/knowledge/questions

Paginated Q&A list with keyword and status filters.

POST/api/v1/knowledge/questions

Batch add Q&A (with similar phrasings) to auto-sync FAQs and product data.

{
  "questions": [
    { "question": "How do I request a refund?",
      "answer": "Go to your order and click 'Apply for refund'…",
      "category": "After-sales",
      "similar": ["How to refund", "Refund process"] }
  ]
}
DELETE/api/v1/knowledge/questions/{id}

Soft-delete a Q&A (restorable in console).

4. Users & Sessions

GET/api/v1/users/{user_id}

User profile and session history summary.

GET/api/v1/sessions?status=active&page=1&size=20

Paginated sessions, filterable by status, time, channel and bot.

5. Ticket APIs

POST/api/v1/tickets

Create a ticket (auto-assigned, SLA starts).

PUT/api/v1/tickets/{id}/status

Update ticket status with history.

6. Report APIs

GET/api/v1/analytics/overview

Operation KPIs: sessions, AI resolution, CSAT, etc.

GET/api/v1/analytics/bi?start=2026-08-01&end=2026-08-27

BI multi-dimension: trends, channels, bots, handover reasons, top misses, agent performance.

7. Webhook Events

Configure your callback URL and subscribe to events (delivered with signature verification):

EventDescription
session.createdNew session created
message.receivedCustomer message received
message.ai_repliedAI replied
transfer.createdHuman handover triggered (with reason)
ticket.created / updatedTicket created / updated
rating.submittedCSAT submitted
knowledge.missUnresolved question (drives KB optimization)

Signature: X-TianKey-Signature = HMAC-SHA256(Webhook Secret, raw body). Verify before processing.

8. Order Integration

POST/api/v1/orders/query

Query order status by order number / phone. AI answers logistics and after-sales directly. Supports Taobao, JD, Pinduoduo, Douyin.

{
  "platform": "douyin",
  "order_no": "DY202608270001",
  "query": "Has my order shipped?"
}

9. Quick Start

Python: chat API

import requests

API = "https://api.tiankeyun.com"

resp = requests.post(f"{API}/api/v1/chat/message",
    headers={"X-API-Key": "your-key", "X-Company-Id": "1001"},
    json={"session_id": "sess_1001", "content": "Do you support WeChat Pay?", "source": "app"})

print(resp.json()["reply"])   # AI reply
print(resp.json()["intent"])  # detected intent

JavaScript: webhook verification

const crypto = require("crypto");
const sig = crypto
  .createHmac("sha256", process.env.WEBHOOK_SECRET)
  .update(rawBody)
  .digest("hex");
if (req.headers["x-tiankey-signature"] !== sig) return res.status(401).end();
// handle event…
📖 Full Swagger/OpenAPI docs are available online in Console → Developer Center. Developer Membership adds sandbox, higher QPS and dedicated support. Apply →