توافق OpenAI و Anthropic
هل تستخدم بالفعل OpenAI أو Anthropic SDK؟ وجّهه إلى Nexevo بتغيير شيئين — الـ URL الأساسي ومفتاح API. يستمر كودك الحالي في العمل، ويحصل كل استدعاء على التوجيه الذكي والفوترة وBYOK من Nexevo.
المُنفّذات
POST/v1/chat/completions — OpenAI Chat Completions
POST/v1/messages — Anthropic Messages
كلاهما يتحدث بنفس تنسيق السلك الدقيق لمورّده (بث وغير بث)، لذا تعمل الـ SDKs الرسمية دون تعديل. هذا يجيب أيضًا عن "هل هناك SDK؟" — استخدم OpenAI أو Anthropic SDK الذي لديك بالفعل.
المصادقة
استخدم مفتاح API لمساحة العمل — نفس مفتاح الـ REST API. يربط الاستدعاء بمساحة عمل واحدة؛ تقرأه واجهة OpenAI من ترويسة Authorization: Bearer، وواجهة Anthropic من x-api-key. تضبطها الـ SDKs لك من خيار api_key الخاص بها.
اختيار النموذج
مرّر "nexevo-auto" كنموذج ليدع موجّه Nexevo يختار أفضل نموذج لكل طلب، أو مرّر معرّف نموذج Nexevo صريح لتثبيته. معرّف نموذج غير معروف يُرجع 404.
OpenAI — Python
from openai import OpenAI
client = OpenAI(
base_url="https://nexevo.ai/v1",
api_key="sk-ws-...", # your Nexevo workspace API key
)
resp = client.chat.completions.create(
model="nexevo-auto", # or an explicit Nexevo model id
messages=[{"role": "user", "content": "Summarize our Q2 results."}],
)
print(resp.choices[0].message.content)البث
stream = client.chat.completions.create(
model="nexevo-auto",
messages=[{"role": "user", "content": "Write a short product update."}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)OpenAI — JavaScript / TypeScript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://nexevo.ai/v1",
apiKey: process.env.NEXEVO_API_KEY, // your workspace API key
});
const resp = await client.chat.completions.create({
model: "nexevo-auto",
messages: [{ role: "user", content: "Summarize our Q2 results." }],
});
console.log(resp.choices[0].message.content);OpenAI — curl
curl https://nexevo.ai/v1/chat/completions \\
-H "Authorization: Bearer sk-ws-..." \\
-H "Content-Type: application/json" \\
-d '{
"model": "nexevo-auto",
"messages": [{"role": "user", "content": "Hello"}]
}'Anthropic — Python
تُلحق Anthropic SDK المسار /v1/messages بالـ URL الأساسي، لذا اضبطه على https://nexevo.ai.
from anthropic import Anthropic
client = Anthropic(
base_url="https://nexevo.ai",
api_key="sk-ws-...", # your Nexevo workspace API key
)
msg = client.messages.create(
model="nexevo-auto",
max_tokens=1024,
messages=[{"role": "user", "content": "Summarize our Q2 results."}],
)
print(msg.content[0].text)Anthropic — curl
curl https://nexevo.ai/v1/messages \\
-H "x-api-key: sk-ws-..." \\
-H "anthropic-version: 2023-06-01" \\
-H "Content-Type: application/json" \\
-d '{
"model": "nexevo-auto",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'تُفوترة الاستدعاءات تمامًا كمسار الدردشة الأصلي (موجّه ذكيًا، بطاقة سعر مسطحة)، ويُستخدم مفتاح BYOK لمساحة العمل — إن وُجد — تلقائيًا. الـ token usage في الاستجابة تقدير بأفضل جهد. لا تُنبعث إطارات التفكير واستدعاء الأدوات على هذه الواجهات؛ بل تُرجع نص المساعد فقط.