クイックスタート
最初の型付き意思決定
以下の例はリクエスト形式を示すものです。これらのテンプレートを使うには、認可されたAPIキーが必要です。メールのリンクまたはGoogleでサインインし、ダッシュボードでキーを作成して、招待コードを利用するか、1ユーロからチャージしてください。
DECISIONMODELS_API_KEY に、ダッシュボードで作成したキーを設定してください。実際のAPIキーを、ソース管理やブラウザ向けバンドルに含めないでください。
まずシェルでキーを設定してください。以下のcurlの例は、いずれもこの値を読み込みます。
export DECISIONMODELS_API_KEY="paste-your-key-here"テキストのバンドル
1つのstateに対して最大3つの質問をする
s1-pro と reax-1 は、同じ questions マップ内に名前付きのテキスト質問を最大3件まで指定できます。共通のテキストは1回分だけ課金され、質問を追加するとそのぶんプロンプトのトークンが加算されます。課金される合計はモデルのトークナイザーで決まり、モデルの入力上限が上限になります(stateを含め、各質問につきモデルに応じて8,000〜8,192トークン、上限の表を参照)。各質問は個別に評価され、バンドルすることで高速化が約束されるわけではありません。
s1-fast、s1-vision、quyet-1-large は質問を1件まで受け付けます。容量が混雑していると、バンドルが再試行可能な 503 model_unavailable または capacity_limit を返すことがあります。EUのリクエストが優先されます。冪等性キー(Idempotency-Key)を再利用すると、追加の課金なしで元の利用レシートが返ります。元の回答は保持されません。
01 / リクエストとレスポンス
サンプルの判断を試してみる
各サンプルには、型付きの質問が1つ含まれています。s1-proとreax-1は最大3件、s1-fast、s1-vision、quyet-1-largeは1件まで対応します。サンプルを選ぶと、リクエストボディとレスポンスの形が表示されます。
{
"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 / 自分のスタックから呼び出す
コピーして使える7言語の例
どのサンプルも同じリクエストを送ります。EUティアの s1-fast に対する choice 質問が1件です。キーは環境変数に保管してください。
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());
}
}クレジットがまだありませんか? APIは 402 insufficient_credit を返し、1ユーロからのチャージへのリンクを案内します。
レスポンスはAPI仕様(リクエストとレスポンスの形式)の例示であり、モデルの実測出力ではありません。利用レシートには実際の入力トークン数が記載され、課金が有効な場合は、整数ナノ単位の正確な請求額も記載されます。
03 / 画像の判断
s1-visionで画像1枚について判断する
モデル s1-vision、state、質問1件とともに、PNG、JPEG、WebPの画像を1枚だけ、base64のデータURLまたは公開HTTPS URLで送ります(デコード後で最大4 MiB、2,000,000ピクセル)。画像は、モデルが実際に読み取る入力トークンとして数えられます(通常は約300〜450)。画像を含むリクエストは、すべての入力トークン(テキストと画像位置)がs1-visionの画像料金で課金されます。テキストのみのs1-visionリクエストには、s1-visionのテキスト料金が適用されます。HTTPS URLはゲートウェイが1回だけ取得し、保存しません。
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 も引き続き使えます。