开发者快速入门

5 分钟集成 MBE API

前置条件

  • 有效的 MBE 账号
  • API Key(在开发者控制台获取)

步骤 1: 获取 API Key

  1. 访问 MBE 开发者门户
  2. 登录您的账号
  3. 进入「控制台」→「API 密钥」
  4. 点击「创建密钥」
  5. 复制您的 API Key

步骤 2: 发送第一个请求

使用 cURL

curl -X POST https://mbe.hi-maker.com/api/expert/ask \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "什么是合同违约的法律后果?"
  }'

使用 Python

import requests

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://mbe.hi-maker.com"

response = requests.post(
    f"{BASE_URL}/api/expert/ask",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    },
    json={
        "query": "什么是合同违约的法律后果?"
    }
)

data = response.json()
print(data["answer"])

使用 JavaScript

const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://mbe.hi-maker.com';

const response = await fetch(`${BASE_URL}/api/expert/ask`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    query: '什么是合同违约的法律后果?',
  }),
});

const data = await response.json();
console.log(data.answer);

步骤 3: 理解响应

{
  "answer": "合同违约的法律后果主要包括:\n1. 继续履行\n2. 支付违约金\n3. 赔偿损失\n4. 解除合同...",
  "confidence": 0.92,
  "expert_id": "civil_lawyer",
  "expert_name": "中国民事律师",
  "sources": [
    {
      "title": "《中华人民共和国合同法》",
      "relevance": 0.95
    }
  ],
  "response_time_ms": 1250
}
字段 说明
answer AI 专家的回答
confidence 置信度 (0-1)
expert_id 响应的专家 ID
expert_name 专家名称
sources 引用来源
response_time_ms 响应时间

步骤 4: 指定专家

# 获取专家列表
experts = requests.get(
    f"{BASE_URL}/api/expert/list",
    headers={"Authorization": f"Bearer {API_KEY}"}
).json()

for expert in experts:
    print(f"{expert['id']}: {expert['name']}")

# 指定专家提问
response = requests.post(
    f"{BASE_URL}/api/expert/ask",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    },
    json={
        "query": "劳动合同纠纷如何处理?",
        "expert_id": "civil_lawyer"  # 指定民事律师专家
    }
)

步骤 5: 错误处理

response = requests.post(...)

if response.status_code == 200:
    data = response.json()
    print(data["answer"])
elif response.status_code == 401:
    print("API Key 无效")
elif response.status_code == 429:
    print("超出速率限制,请稍后重试")
else:
    error = response.json().get("error", {})
    print(f"错误: {error.get('message')}")

下一步

常见问题

Q: API Key 在哪里获取?

A: 登录开发者门户 → 控制台 → API 密钥 → 创建密钥

Q: 有请求限制吗?

A: 免费版 100次/天,付费版本更高限制

Q: 支持哪些专家?

A: 25+ 领域专家,包括法律、烹饪、健身、技术等


开发者快速入门 | MBE v3.0.0 | 2026-02-01