跳轉到主要內容

概覽

LemonData 支援使用單一 API 金鑰的 三種原生 API 格式。選擇最適合您使用情境的格式 — 無需變更任何設定。

OpenAI 格式

/v1/chat/completions 標準格式,最高相容性

Anthropic 格式

/v1/messages 延伸思考,Claude 原生功能

Gemini 格式

/v1beta/models/:model:generateContent 整合 Google 生態系

為何使用多格式?

優勢說明
無須切換 SDK使用您慣用的 SDK 操作任何模型
原生功能存取格式專屬的能力
輕鬆遷移只需變更 base URL 即可從官方 API 切換
單一計費一個帳戶、一組 API 金鑰,支援所有格式

格式比較

功能OpenAIAnthropicGemini
Endpoint/v1/chat/completions/v1/messages/v1beta/models/:model:generateContent
Auth HeaderAuthorization: Bearerx-api-keyAuthorization: Bearer
System PromptIn messages arraySeparate system fieldIn systemInstruction
Extended Thinking
Streaming✅ SSE✅ SSE✅ SSE
Tool Calling
Vision

OpenAI 格式

最廣泛相容的格式,也是大多數新整合的預設起點。可用於最廣泛的 LemonData 模型集合。
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-lemondata-key",
    base_url="https://api.lemondata.cc/v1"
)

# Works with ANY model
response = client.chat.completions.create(
    model="claude-sonnet-4-6",  # Claude via OpenAI format
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
)
適用情境:
  • 一般用途
  • 既有 OpenAI SDK 整合
  • 最高相容性

Anthropic 格式

Anthropic 原生 Messages API。若要使用 Claude 特有功能(例如延伸思考),需使用此格式。
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-your-lemondata-key",
    base_url="https://api.lemondata.cc"  # No /v1 suffix!
)

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="You are a helpful assistant.",  # Separate system field
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

延伸思考(Claude Opus 4.6)

僅在 Anthropic 格式中提供:
message = client.messages.create(
    model="claude-opus-4-6",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000
    },
    messages=[{"role": "user", "content": "Solve this complex problem..."}]
)

# Access thinking process
for block in message.content:
    if block.type == "thinking":
        print(f"Thinking: {block.thinking}")
    elif block.type == "text":
        print(f"Answer: {block.text}")
適用情境:
  • Claude 特有功能
  • 延伸思考模式
  • 使用原生 Anthropic SDK 的用戶

Gemini 格式

原生 Google Gemini API 格式,便於整合 Google 生態系。
curl "https://api.lemondata.cc/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "Authorization: Bearer sk-your-lemondata-key" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [{"text": "Hello!"}]
    }],
    "systemInstruction": {
      "parts": [{"text": "You are a helpful assistant."}]
    }
  }'

串流

curl "https://api.lemondata.cc/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" \
  -H "Authorization: Bearer sk-your-lemondata-key" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "Write a story"}]}]
  }'
適用情境:
  • Google Cloud 整合
  • 既有 Gemini SDK 程式碼
  • 原生 Gemini 功能

選擇合適的格式

遷移指南

從 OpenAI 官方 API 遷移

# Before (OpenAI)
client = OpenAI(api_key="sk-openai-key")

# After (LemonData)
client = OpenAI(
    api_key="sk-lemondata-key",
    base_url="https://api.lemondata.cc/v1"  # Add this line
)
# That's it! Same code works

從 Anthropic 官方 API 遷移

# Before (Anthropic)
client = Anthropic(api_key="sk-ant-key")

# After (LemonData)
client = Anthropic(
    api_key="sk-lemondata-key",
    base_url="https://api.lemondata.cc"  # Add this line (no /v1!)
)

從 Google AI Studio 遷移

# Before (Google)
import google.generativeai as genai
genai.configure(api_key="google-api-key")

# After (LemonData) - Use REST API
import requests

response = requests.post(
    "https://api.lemondata.cc/v1beta/models/gemini-2.5-flash:generateContent",
    headers={"Authorization": "Bearer sk-lemondata-key"},
    json={"contents": [{"parts": [{"text": "Hello"}]}]}
)

跨模型相容性

LemonData 的魔力:使用 任何 SDK 搭配 任何模型。網關會自動處理格式轉換。

任何 SDK → 任何模型

# Anthropic SDK with GPT-4o (auto-converts to OpenAI format)
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-lemondata-key",
    base_url="https://api.lemondata.cc"
)

response = client.messages.create(
    model="gpt-4o",  # ✅ Works! Auto-converted
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

# Same SDK, different models - no code changes
response = client.messages.create(model="gemini-2.5-flash", ...)  # ✅ Works!
response = client.messages.create(model="deepseek-r1", ...)       # ✅ Works!

OpenAI SDK → 支援所有模型

from openai import OpenAI

client = OpenAI(base_url="https://api.lemondata.cc/v1", api_key="sk-...")

# All these work with the same SDK:
response = client.chat.completions.create(model="gpt-4o", ...)
response = client.chat.completions.create(model="claude-sonnet-4-6", ...)
response = client.chat.completions.create(model="gemini-2.5-flash", ...)

產業比較

平台OpenAI 格式Anthropic 格式Gemini 格式Responses API
LemonData✅ 所有模型✅ 所有模型✅ 所有模型✅ 所有模型
OpenRouter✅ 所有模型
Together AI✅ 所有模型
Fireworks✅ 所有模型
雖然跨格式在大多數功能下可運作,但格式特定功能(例如 Anthropic 的延伸思考)仍需使用原生格式。