快速開始

快速開始

只需幾行程式碼,即可完成第一個 Lawbot AI API 呼叫。 本指南提供 cURL、Python 與 Node.js 三種方式。

前置條件

  1. 1取得 API 金鑰(由 Lawbot 團隊提供)
  2. 2確認可透過 HTTPS 存取 API 伺服器
  3. 3選擇您慣用的 HTTP 客戶端或 OpenAI 相容 SDK

使用 cURL

最直接的方式,無需安裝任何套件,直接在終端機執行:

terminal
curl https://developer-api.lawbot.tw/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "lawbot-flash",
    "stream": true,
    "reasoning_effort": "medium",
    "temperature": 0.3,
    "messages": [
      {
        "role": "user",
        "content": "請問股東會決議瑕疵的法律效果為何?"
      }
    ]
  }'

使用 Python(OpenAI 相容)

安裝 OpenAI Python SDK,僅需修改 base_url 即可使用(reasoning_effort 透過 extra_body 傳入):

terminal
pip install openai
quickstart.py
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://developer-api.lawbot.tw/api/v1",
)

response = client.chat.completions.create(
    model="lawbot-flash",
    messages=[
        {
            "role": "user",
            "content": "請問股東會決議瑕疵的法律效果為何?",
        },
    ],
    temperature=0.3,
    extra_body={"reasoning_effort": "medium"},  # 可選:none/minimal/low/medium/high/xhigh
)

print(response.choices[0].message.content)
# x_lawbot_references 包含 AI 引用的法律文件清單
if response.x_lawbot_references:
    for ref in response.x_lawbot_references:
        print(f"引用:{ref['title']}")

使用 Node.js / TypeScript

安裝 OpenAI Node.js SDK,同樣只需修改 baseURL

terminal
npm install openai
quickstart.ts
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://developer-api.lawbot.tw/api/v1",
});

const response = await client.chat.completions.create({
  model: "lawbot-flash",
  stream: true,
  temperature: 0.3,
  messages: [
    {
      role: "user",
      content: "請問股東會決議瑕疵的法律效果為何?",
    },
  ],
  // @ts-expect-error Lawbot 擴充欄位
  reasoning_effort: "medium",
});

console.log(response.choices[0].message.content);
// x_lawbot_references 包含 AI 引用的法律文件清單

回應格式

API 回應格式與 OpenAI Chat Completions 相容,並包含 Lawbot 擴充欄位 x_lawbot_references(引用法律文件清單)。 注意:usage 欄位目前回傳 0 以保留相容性。

response.json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1740000000,
  "model": "lawbot-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "股東會決議瑕疵依民法及公司法規定,可分為無效與得撤銷兩種情形..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  },
  "x_lawbot_references": [
    {
          "doc_id": "law-corp-189",
      "title": "公司法第 189 條",
      "doc_type": "法規命令",
      "is_abandoned": false
    }
  ]
}