快速入门
你的第一个类型化决策
以下示例展示请求与响应的约定格式。这些模板需要已获授权的 API 密钥:请通过邮件链接或 Google 登录,在控制台创建密钥,然后兑换邀请码,或从 1 欧元起充值。
请将 DECISIONMODELS_API_KEY 设置为你在控制台创建的密钥。切勿把真实的 API 密钥放进版本控制或浏览器端的打包文件中。
请先在 shell 中设置密钥;下面的每个 curl 示例都会读取它:
export DECISIONMODELS_API_KEY="paste-your-key-here"文本打包
针对同一个 state 最多提出三个问题
s1-pro 和 reax-1 支持在同一个 questions 映射中放入最多三个带名称的文本问题。共用的文本只计费一次;每增加一个问题,就会增加相应的提示词 token。计费总量由模型的分词器决定,并以模型的输入上限为封顶(每个问题连同其 state,视模型而定为 8,000 到 8,192 个 token,详见限制表)。每个问题单独评估;打包并不保证更快。
s1-fast、s1-vision 和 quyet-1-large 只接受一个问题。容量繁忙时,打包请求可能返回可重试的 503 model_unavailable 或 capacity_limit。EU 请求享有优先权。重复使用同一个幂等键会返回最初的用量回执,且不会再次扣费;原始回答不会保留。
01 / 请求与响应
点选示例决策
每个示例都包含一个类型化问题。s1-pro 和 reax-1 最多支持三个问题;s1-fast、s1-vision 和 quyet-1-large 支持一个。选择一个示例,即可查看它的请求体和响应的结构。
{
"model": "s1-fast",
"state": "Mia owns a red bicycle.",
"questions": {
"color": {
"type": "choice",
"instructions": "Which color is the bicycle?",
"criteria": {"red": null, "blue": null}
}
}
}{
"id": "dec_example",
"model": "s1-fast",
"answers": {
"color": { "type": "choice", "choice": "red", "confidence": 0.91,
"probabilities": { "red": 0.91, "blue": 0.09 } }
},
"usage": { "input_tokens": 328, "output_tokens": 0, "decisions": 1 },
"tier": "eu"
}{"model":"s1-fast","state":{"message":"I need to update my invoice address.","account_type":"business"},"questions":{"route":{"type":"choice","instructions":"Choose the support queue that best fits the request.","criteria":{"billing":null,"technical":null,"account":null}}}}{"id":"dec_route","model":"s1-fast","answers":{"route":{"type":"choice","choice":"billing","confidence":0.87,"probabilities":{"billing":0.87,"technical":0.09,"account":0.04}}},"usage":{"input_tokens":351,"output_tokens":0,"decisions":1},"tier":"eu"}{"model":"s1-fast","state":{"action":"delete_workspace","actor_role":"viewer"},"questions":{"allowed":{"type":"noul","instructions":"Is this action allowed under the stated role policy?"}}}{"id":"dec_guard","model":"s1-fast","answers":{"allowed":{"type":"noul","noul":0.04}},"usage":{"input_tokens":298,"output_tokens":0,"decisions":1},"tier":"eu"}{"model":"s1-pro","state":{"draft":"Short release note draft","rubric":"Clarity and factual support"},"questions":{"quality":{"type":"score","instructions":"Rate the draft against the rubric.","criteria":["low","medium","high"]}}}{"id":"dec_score","model":"s1-pro","answers":{"quality":{"type":"score","score":1.57,"confidence":0.71,"legend":{"0":"low","1":"medium","2":"high"},"probabilities":{"0":0.05,"1":0.33,"2":0.62}}},"usage":{"input_tokens":512,"output_tokens":0,"decisions":1},"tier":"eu"}02 / 在你的技术栈中调用
七种语言的可复制示例
每个示例发送的都是同一个请求:在 EU 层级上,向 s1-fast 发出一个 choice 问题。请把密钥保存在环境变量中。
curl https://api.decisionmodels.io/v1/systemone \
-H "Authorization: Bearer $DECISIONMODELS_API_KEY" \
-H "Content-Type: application/json" \
-H "S1-Region: eu" \
-d '{ "model": "s1-fast", "state": "Mia owns a red bicycle.", "questions": { "color": { "type": "choice", "instructions": "Which color is the bicycle?", "criteria": {"red": null, "blue": null} } }}'import os
import requests
response = requests.post(
"https://api.decisionmodels.io/v1/systemone",
headers={
"Authorization": f"Bearer {os.environ['DECISIONMODELS_API_KEY']}",
"Content-Type": "application/json",
"S1-Region": "eu",
},
json={
"model": "s1-fast",
"state": "Mia owns a red bicycle.",
"questions": {
"color": {
"type": "choice",
"instructions": "Which color is the bicycle?",
"criteria": {"red": None, "blue": None},
}
},
},
timeout=30,
)
print(response.json())const response = await fetch("https://api.decisionmodels.io/v1/systemone", {
method: "POST",
headers: {
Authorization: "Bearer " + process.env.DECISIONMODELS_API_KEY,
"Content-Type": "application/json",
"S1-Region": "eu",
},
body: JSON.stringify({
model: "s1-fast",
state: "Mia owns a red bicycle.",
questions: {
color: { type: "choice", instructions: "Which color is the bicycle?",
criteria: { red: null, blue: null } },
},
}),
});
if (!response.ok) throw new Error("HTTP " + response.status);
const result = await response.json();
console.log(result.answers.color);type DecisionAnswer = {
type: "noul" | "choice" | "score";
choice?: string;
noul?: number;
score?: number;
confidence?: number;
legend?: Record<string, string>;
probabilities?: Record<string, number>;
};
type DecisionResponse = {
id: string;
model: string;
answers: Record<string, DecisionAnswer>;
usage: { input_tokens: number; output_tokens: number; decisions: number };
tier: "eu" | "global";
};
const response = await fetch("https://api.decisionmodels.io/v1/systemone", {
method: "POST",
headers: {
Authorization: "Bearer " + process.env.DECISIONMODELS_API_KEY,
"Content-Type": "application/json",
"S1-Region": "eu",
},
body: JSON.stringify({
model: "s1-fast",
state: "Mia owns a red bicycle.",
questions: {
color: { type: "choice", instructions: "Which color is the bicycle?",
criteria: { red: null, blue: null } },
},
}),
});
if (!response.ok) throw new Error("HTTP " + response.status);
const result = (await response.json()) as DecisionResponse;
console.log(result.answers.color);// cargo add reqwest --features json
// cargo add tokio --features full
// cargo add serde_json
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let client = reqwest::Client::new();
let body = serde_json::json!({
"model": "s1-fast",
"state": "Mia owns a red bicycle.",
"questions": {
"color": { "type": "choice",
"instructions": "Which color is the bicycle?",
"criteria": { "red": null, "blue": null } }
}
});
let response = client
.post("https://api.decisionmodels.io/v1/systemone")
.bearer_auth(std::env::var("DECISIONMODELS_API_KEY").expect("DECISIONMODELS_API_KEY"))
.header("S1-Region", "eu")
.json(&body)
.send().await?;
println!("{}", response.text().await?);
Ok(())
}using System.Net.Http.Json;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization",
"Bearer " + Environment.GetEnvironmentVariable("DECISIONMODELS_API_KEY"));
client.DefaultRequestHeaders.Add("S1-Region", "eu");
var body = new {
model = "s1-fast",
state = "Mia owns a red bicycle.",
questions = new {
color = new { type = "choice",
instructions = "Which color is the bicycle?",
criteria = new { red = (string?)null, blue = (string?)null } }
}
};
var response = await client.PostAsJsonAsync(
"https://api.decisionmodels.io/v1/systemone", body);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class DecisionModelsQuickstart {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
String body = """
{"model":"s1-fast","state":"Mia owns a red bicycle.",
"questions":{"color":{"type":"choice",
"instructions":"Which color is the bicycle?",
"criteria":{"red":null,"blue":null}}}}""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.decisionmodels.io/v1/systemone"))
.header("Authorization", "Bearer " + System.getenv("DECISIONMODELS_API_KEY"))
.header("Content-Type", "application/json")
.header("S1-Region", "eu")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
System.out.println(client.send(request,
HttpResponse.BodyHandlers.ofString()).body());
}
}还没有余额?接口会返回 402 insufficient_credit,并附上从 1 欧元起充值的链接。
这里的响应只是说明约定格式的示例,并非实测的模型输出。用量回执包含实际的输入 token 数;启用计费后,还包含精确的整数 nanos 扣费金额。
03 / 图像决策
用 s1-vision 对一张图像做决策
使用模型 s1-vision,并附上一个 state 和一个问题,发送且仅发送一张 PNG、JPEG 或 WebP 图像,可以是 base64 data URL,也可以是公开的 HTTPS URL(解码后最大 4 MiB,2,000,000 像素)。图像按模型实际读取的输入 token 计算(通常约 300–450)。包含图像的请求,其全部输入 token(文本与图像部分)都按 s1-vision 的图像费率计费;纯文本的 s1-vision 请求则按 s1-vision 的文本费率计费。HTTPS URL 由网关抓取一次,不会存储。
IMG=$(base64 -w0 photo.jpg)
curl https://api.decisionmodels.io/v1/multimodal \
-H "Authorization: Bearer $DECISIONMODELS_API_KEY" \
-H "Content-Type: application/json" \
-H "S1-Region: eu" \
-d '{
"model": "s1-vision",
"state": "Customer return request: item arrived damaged.",
"questions": {
"damage": {
"type": "choice",
"instructions": "What does the photo show?",
"criteria": {"visible_damage": null, "no_damage": null, "not_the_product": null}
}
},
"images": ["data:image/jpeg;base64,'"$IMG"'"]
}'import base64, os, requests
with open("photo.jpg", "rb") as f:
image = "data:image/jpeg;base64," + base64.b64encode(f.read()).decode()
response = requests.post(
"https://api.decisionmodels.io/v1/multimodal",
headers={
"Authorization": f"Bearer {os.environ['DECISIONMODELS_API_KEY']}",
"S1-Region": "eu",
},
json={
"model": "s1-vision",
"state": "Customer return request: item arrived damaged.",
"questions": {
"damage": {
"type": "choice",
"instructions": "What does the photo show?",
"criteria": {"visible_damage": None, "no_damage": None, "not_the_product": None},
}
},
"images": [image],
},
timeout=10,
)
response.raise_for_status()
print(response.json()["answers"]["damage"])import { readFile } from "node:fs/promises";
const image = "data:image/jpeg;base64," + (await readFile("photo.jpg")).toString("base64");
const response = await fetch("https://api.decisionmodels.io/v1/multimodal", {
method: "POST",
headers: {
Authorization: "Bearer " + process.env.DECISIONMODELS_API_KEY,
"Content-Type": "application/json",
"S1-Region": "eu",
},
body: JSON.stringify({
model: "s1-vision",
state: "Customer return request: item arrived damaged.",
questions: {
damage: {
type: "choice",
instructions: "What does the photo show?",
criteria: { visible_damage: null, no_damage: null, not_the_product: null },
},
},
images: [image],
}),
});
if (!response.ok) throw new Error("HTTP " + response.status);
console.log((await response.json()).answers.damage);https://api.system1models.ai 仍可继续使用。