繁中 ▾
領取試用金鑰

Claude api code: quickstart guide

透過單一基礎 URL 的變更,將您的 Claude API 程式碼整合至任何 OpenAI 相容的用戶端。此無審查 LLM 代理伺服器會將您的請求路由至專門針對無限制程式碼生成和高用量場景優化的模型。

基礎 URL 與驗證

首先更新您的客戶端配置以指向我們的主機端點。使用 base_url HTTPS://api.claudeapicode.com/v1 並將您的金鑰傳遞至 Authorization 標頭。此代理程式與標準 OpenAI SDK 相容,無需自訂驅動程式。您可以在儀表板上透過 Google 或電子郵件即時產生金鑰,無需提供手機號碼。

curl https://api.claudeapicode.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [{"role": "user", "content": "Set up a PostgreSQL connection pool with ten connections"}]
  }'

聊天完成端點

向 /v1/chat/completions 使用模型 ID 的 endpoint uncensored. 此端點接受標準的聊天訊息並返回文字回應。它為您程式碼會話處理所有 token 處理,不受官方平台的限制。您可以透過呼叫 /v1/models 確認連接性。

from openai import OpenAI

client = OpenAI(base_url="https://api.claudeapicode.com/v1", api_key="YOUR_KEY")

resp = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)

Node.js

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.claudeapicode.com/v1", apiKey: process.env.API_KEY });

const resp = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);

串流

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Tell the story in second person."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

幾秒鐘內取得金鑰

註冊、複製金鑰,更新基礎網址。設定完成。