如何用 OpenAI SDK 兩行呼叫 Saanora 的 Mark 1x-27B
Call Mark 1x-27B with the OpenAI SDK in two lines
文章示範如何用 OpenAI SDK 呼叫 Saanora 的 Mark 1x-27B,只需更改 base URL 和模型名稱。該模型支援 OpenAI Chat Completions API,提供工具呼叫、圖片輸入、可調推理力度及 262K-token 上下文窗口,GPQA Diamond 得分為 84.7。
Mark 1x-27B is Saanora's most capable model: 84.7 on GPQA Diamond, a 262K-token context window, tool calling, image input and adjustable reasoning effort. It speaks the OpenAI Chat Completions API, so if your code already uses the OpenAI SDK, switching is two lines: the base URL and the model name.
1. Get a key
Sign up at api.saanora.com. Once your email is verified you get $0.20 of free credit, enough to try everything below. Open API keys, create a key and export it:
export SAANORA_API_KEY="sk_sa_..."
2. Python
# mark.py: pip install openai, then python mark.py
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.saanora.com/v1", api_key=os.environ["SAANORA_API_KEY"])
r = client.chat.completions.create(
model="mark-1x-27b",
messages=[{"role": "user", "content": "How many prime numbers are there below 100?"}],
)
print(r.choices[0].message.content)
3. JavaScript
// mark.mjs: npm install openai, then node mark.mjs (Node.js 18 or later)
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.saanora.com/v1", apiKey: process.env.SAANORA_API_KEY });
const r = await client.chat.completions.create({
model: "mark-1x-27b",
messages: [{ role: "user", content: "How many prime numbers are there below 100?" }],
});
console.log(r.choices[0].message.content);
4. cURL
curl https://api.saanora.com/v1/chat/completions \
-H "Authorization: Bearer $SAANORA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "mark-1x-27b", "messages": [{"role": "user", "content": "How many prime numbers are there below 100?"}]}'
5. Reasoning and reasoning effort
Mark thinks before it answers. The answer is in choices[0].message.content; the thinking comes back separately in choices[0].message.reasoning (billed as output tokens). Set how hard it thinks with reasoning_effort: low, medium or high.
r = client.chat.completions.create(
model="mark-1x-27b",
messages=[{"role": "user", "content": "Is 1,000,003 prime?"}],
reasoning_effort="low",
)
print(r.choices[0].message.content)
6. Streaming
stream = client.chat.completions.create(
model="mark-1x-27b",
messages=[{"role": "user", "content": "Explain compound interest with an example."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
7. Pricing
$0.10 per 1M input tokens and $0.60 per 1M output tokens, paid from prepaid credit. Top-ups start at $5. One key and one balance work for every model on the API.
One note: when Mark has been quiet for a while, the first request can come back as 503 model_warming_up with a Retry-After header while it starts. Retry after that time; those requests aren't charged.
Docs: api.saanora.com. I'd love to hear what you build with it.
來源:DEV Community · dev.to
