Sous docs
Wrap the client your app already uses. Sous learns from its calls, trains small open models, tests them on calls they never saw, and switches your app to the best one when it answers like your model for less. Then it keeps training.
Overview
Sous sits between your app and its model. At first your app’s calls go to the model it uses now, and Sous keeps each call and answer. Once there are enough, it trains small open models to give the same answers, tests each one on calls it held back, and switches your app to the best one if it answers like your model for less. Your model stays on as the backup, and Sous keeps training on newer calls.
- Model
- One job in your app, like routing tickets or redacting PII. It has an id, like f27d3be0, and the calls your app makes for that job train it.
- Frontier model
- The model your app calls today, or one Sous picks if it has none. Its answers are what the small models learn to give. The app calls it the teacher.
- Student
- A small open model Sous trains on those answers: c1, c2, and so on. Sous tries a few sizes and recipes and tests each one.
- Live student
- The student answering your app’s calls. The frontier model backs it up and answers any call it can’t.
- Round
- A later training on newer calls. It switches to a new student only if that student is clearly better than the live one.
Quickstart
Wrap an OpenAI client and keep using it. You need an API key and a model for Sous to train.
1. Make a model and an API key
In the app, create a model: name it and say which model your app calls today. Then make an API key under API keys and copy it; it’s shown once.
SOUS_API_KEY=...2. Wrap your client
Pass your client to Sous with the id of the model to train. Your calls keep naming your frontier model, and nothing else about them changes.
# pip install sousml
from openai import OpenAI
from sousml import Sous
client = Sous(OpenAI(), model="f27d3be0")
# The rest of your code stays as it is.
response = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": chat}],
)3. Use your app as usual
Calls go to your frontier model as before, and Sous keeps each one with its answer. Once it has at least 30 (50 or more conversations train better), start training from the model’s page, or turn on Train on its own and Sous starts when calls pause.
4. Let it switch
Training ends with a test on the calls Sous held back. If a student answers like your frontier model, Sous recommends it, and with Switch automatically your app’s calls go to it right away. Your frontier model answers any call the student can’t, and every reply says which one answered.
raw = client.chat.completions.with_raw_response.create(
model="f27d3be0",
messages=[{"role": "user", "content": chat}],
)
print(raw.headers.get("x-sous-answered-by"))
response = raw.parse()Ways to connect
Every way ends the same: Sous sees your app’s calls and answers, and once a student is live, it answers them. Pick by how your app calls its model today.
| Way | Use it when |
|---|---|
| Wrap your client | Your app already calls a model, with your key, and you can change one line. |
| No code changes | You’d rather not touch the code. For Python and Node apps. |
| Point at Sous | Your app has no model yet, or you’d like Sous to call the frontier model for you. |
| Send calls | Another language, or calls you can’t wrap. Your app calls its model and sends Sous each call afterwards. |
Wrap your client
Works with OpenAI, Azure OpenAI and Anthropic clients, in Python and TypeScript. Sous reads SOUS_API_KEY from the environment.
# pip install sousml
from openai import OpenAI
from sousml import Sous
client = Sous(OpenAI(), model="f27d3be0")
# The rest of your code stays as it is.
response = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": chat}],
)In TypeScript, pass an Anthropic or Azure client the same way: sous(new Anthropic(), { model }).
No code changes
Run your app under Sous, and every OpenAI, Azure OpenAI and Anthropic client it makes is wrapped for you.
pip install sousml
# Every OpenAI, Azure OpenAI and Anthropic client the app makes now trains f27d3be0.
SOUS_MODEL=f27d3be0 sous-run python app.py
SOUS_MODEL=f27d3be0 sous-run uvicorn app:appopenai package from Node, so the launcher can’t reach it. Wrap its client in code instead.Point at Sous
Use Sous as your OpenAI endpoint: change the base URL and call your Sous model by its id. Sous calls the frontier model for you until a student is live. If your app doesn’t use a model yet, start here, and Sous picks one.
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.sousml.com/v1", api_key=os.environ["SOUS_API_KEY"])
response = client.chat.completions.create(
model="f27d3be0",
messages=[{"role": "user", "content": chat}],
)Send calls
If you can’t wrap the client, send each call after it happens, with the answer your app got. Sous learns from them the same way. For Anthropic’s shape, add "api": "messages". To use the student once it’s live, call it through the OpenAI-compatible endpoint.
curl https://api.sousml.com/v1/models/f27d3be0/calls \
-H "Authorization: Bearer $SOUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request": {
"model": "gpt-5.5",
"messages": [{"role": "user", "content": "..."}]
},
"response": {
"choices": [
{"message": {"role": "assistant", "content": "..."}, "finish_reason": "stop"}
]
}
}'Coding agents
Sous has an MCP server, so a coding agent like Claude Code or Cursor can set up a model and connect your app for you. It takes the same API key.
claude mcp add --transport http sous https://api.sousml.com/mcp \
--header "Authorization: Bearer $SOUS_API_KEY"Calling your model
Your Sous model answers OpenAI’s API at https://api.sousml.com/v1. Send your API key as a bearer token and use the model’s id as the model; the SDK does both for you.
| Works | Notes |
|---|---|
| Chat Completions and Responses | Both OpenAI APIs, and Anthropic’s Messages API through the SDK. |
| Tools | Students learn which tools to call and with what arguments. |
| Structured outputs | JSON mode and JSON schemas. |
| Streaming | Server-sent events, as OpenAI sends them. |
| Images | Image parts in messages, as you send them to OpenAI. |
response = client.responses.create(model="f27d3be0", input=chat)
print(response.output_text)Who answered
Until a student is live, the frontier model answers every call. After that, if the student fails, or its reply comes back cut off or empty, the frontier model answers that call instead. Each reply’s x-sous-answered-by header says which one did.
Call one student
Add a student’s name to the id to call it directly, whichever one is live. Students still answer when called by name after you stop sending the model’s calls to them.
# c2 answers this call, whichever student is live.
client.chat.completions.create(model="f27d3be0:c2", messages=[...])Same call, same answer
When a call asks for JSON and sets no temperature, a student gives its most likely answer, so the same call always gets the same answer.
Agents
The OpenAI Agents SDK works through the endpoint. Students learn which tools to call, and with what arguments, from the frontier model’s calls.
import os
from agents import Agent, OpenAIResponsesModel, Runner
from openai import AsyncOpenAI
sous = AsyncOpenAI(base_url="https://api.sousml.com/v1", api_key=os.environ["SOUS_API_KEY"])
agent = Agent(
name="Support",
instructions="...",
tools=[...],
model=OpenAIResponsesModel("f27d3be0", sous),
)
result = Runner.run_sync(agent, "...")POST /v1/tasks/:task_id/serving/wake.Training
Training starts from the calls Sous has kept. It waits for calls to stop arriving, so ones sent together train together. Then, on its own:
- 1Keeps callsEach call and the frontier model’s answer, grouped into whole conversations. It needs at least 30.
- 2Splits themAbout 20% of the conversations go aside as the test. No student trains on them.
- 3Trains studentsOpen models in a few sizes, each fine-tuned on the frontier model’s answers.
- 4Tests themEvery student, and the same model untrained, answers the held-out calls.
- 5Recommends oneThe student that answers most like the frontier model, preferring the cheaper one when two are close.
- 6SwitchesCalls go to that student, on its own or when you say so.
The model’s activity log says what Sous did at each step and why. If no student is good enough, Sous doesn’t recommend one, and you can still pick one yourself. Training takes at most half your credits, so your models keep answering; with less, Sous trains fewer students.
With Switch automatically on, calls go to the recommended student as soon as training ends. Off, your frontier model keeps answering until you switch.
From a dataset
The same training runs on examples you already have. Upload them with POST /v1/datasets, then create the model with POST /v1/tasks and source set to dataset. goal says what the model does, instruction is how to decide, and fields is the answer. Send dataset_id for one dataset, or sources for several. Training starts immediately; start: false saves a draft, and POST /v1/tasks/:task_id/start queues it.
Leave labels out and Sous’s teacher labels the examples. On a table that already has the answers, labels maps each field to its column and Sous trains on those rows. columns are the ones the model reads; leave them out and it reads every column except the answers. A problem with the job comes back as 422, with the reason in detail. A dataset that isn’t yours, or isn’t there, is a 404.
curl -X POST https://api.sousml.com/v1/tasks \
-H "Authorization: Bearer $SOUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source": "dataset",
"name": "Review tagger",
"dataset_id": "f1a2b3c4",
"goal": "Tag each review with its sentiment.",
"instruction": "Read the review and decide whether the customer is happy, unhappy, or neither.",
"columns": ["review"],
"fields": [{"name": "sentiment", "type": "category", "options": ["positive", "negative", "neutral"]}]
}'POST /v1/tasks/:task_id/preview labels a few examples of a draft first, so you can check the job before it trains. It takes {"count": 4}, from 1 to 6.
Keeps improving
A model keeps improving after it switches. Each round, Sous trains on the calls kept since the last one, tries other settings and newer base models, and tests each against the live student on the same held-out calls. It switches only to a student that’s clearly better, and you can roll back to the one before.
So there are new calls to learn from, the frontier model keeps answering a share of them, whole conversations at a time. Sous sets the share each round, up to 20%. Both happen while Keep improving is on, a switch on the model’s page.
The model’s Calls tab keeps every call for 30 days. Mark an answer wrong and give the right one, and the next round trains or tests on your answer in place of the frontier model’s.
| Setting | Field | What it does |
|---|---|---|
| Train on its own | auto_train | Starts the first training once there are enough calls (at least 30) and they stop arriving. Off: you start it. |
| Switch automatically | auto_promote | When training or a round finds a student that’s clearly better, calls go to it right away. Off: Sous recommends it and you switch. |
| Keep improving | keep_improving | Once trained, a round every week on newer calls. So there are new calls, the frontier model keeps answering a share of them, set by Sous each round, up to 20%. It sets improve and learning together. |
| Rounds alone | improve.enabled, improve.every_days | Over HTTP only: rounds every day, week or month (1, 7 or 30 days), without changing learning. |
| New calls alone | learning.enabled | Over HTTP only: whether the frontier model keeps answering a share of calls, whole conversations at a time, without changing rounds. |
| Size | scale | "auto" (the default): Sous moves the model up a size when its busiest minutes come near what its size takes, and down after three quiet hours, never past the room its spending limit leaves. Or S, M, L or XL to pin it. Each size up takes about twice the calls and costs more per token. |
| Monthly limit | monthly_limit | The most the model may spend in a calendar month, in whole dollars of credits. Past it, its paid work and calls stop with a 402 until the 1st. 0 removes it. |
curl -X PATCH https://api.sousml.com/v1/tasks/f27d3be0 \
-H "Authorization: Bearer $SOUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"keep_improving": true, "auto_promote": true}'To switch yourself, send a student’s id to promote. Send null to send calls back to the frontier model.
curl https://api.sousml.com/v1/tasks/f27d3be0/promote \
-H "Authorization: Bearer $SOUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"candidate_id": "c2"}'Results
Every training and round reports how each student did on the held-out calls, next to the frontier model.
| Measure | Meaning |
|---|---|
| Same answers | How often a student answers like the frontier model. Structured answers are compared field by field; a judge compares free-text answers. |
| Same action | For calls with tools: how often it chose the same tools, or answered when the frontier model answered. |
| Same tool calls | The share of the frontier model’s tool calls it made with the same arguments. |
| Before training | The same student untrained, on the same held-out calls. |
| Cost and speed | What a student costs per 1,000 calls and how long it takes per call, next to the frontier model. |
On the model’s page you can read every held-out call with both answers side by side, or only the disagreements, and send any input to the frontier model and the students at once from Try it. Over HTTP:
curl https://api.sousml.com/v1/tasks/f27d3be0/examples \
-H "Authorization: Bearer $SOUS_API_KEY"Managing models
Everything on a model’s page is also an HTTP call with the same API key. Paths are relative to https://api.sousml.com, and models are called tasks in them.
curl https://api.sousml.com/v1/tasks/f27d3be0 \
-H "Authorization: Bearer $SOUS_API_KEY"Response, abridged
{
"id": "f27d3be0",
"name": "PII redactor",
"source": "traffic",
"status": "succeeded",
"readiness": { "kept": 132, "min_calls": 30, "held_out": 26 },
"selected": { "candidate_id": "c5", "agreement": 0.84, "savings": 0.88 },
"promoted": "c5",
"auto_train": false,
"auto_promote": true,
"improve": { "enabled": true, "every_days": 7 },
"learning": { "enabled": true, "share": 0.05 },
"next_round_at": 1795975537
}Calls
- POST/v1/chat/completionsCall a model with its id, or a student with id:c2. OpenAI’s request and response.
- POST/v1/responsesThe same, through OpenAI’s Responses API.
- GET/v1/modelsThe models your key can call.
- POST/v1/models/:model/callsSend a call your app made, with its answer, for the model to learn from.
Models
- POST/v1/tasksCreate a model. It learns from the app’s calls, or from uploaded datasets when source is "dataset".
- GET/v1/tasksYour models, newest first. ?archived=true lists the ones taken off that list.
- POST/v1/tasks/:task_id/archiveTake a model off the models list. Calls to it keep working.
- POST/v1/tasks/:task_id/restorePut an archived model back on the models list.
- GET/v1/tasks/:task_idStatus, readiness, students, the live one, settings, and usage.
- PATCH/v1/tasks/:task_idChange its settings: auto_train, auto_promote, keep_improving, monthly_limit, and more.
- POST/v1/tasks/:task_id/previewLabel a few examples of a dataset draft, before training starts.
- POST/v1/tasks/:task_id/startStart training a dataset draft, or a model that learns from calls, now.
- POST/v1/tasks/:task_id/promoteSend calls to a student by candidate_id, or back to the frontier model with null.
- POST/v1/tasks/:task_id/improveRun a round now. {"warm_start": true} continues the recommended student's LoRA.
- POST/v1/tasks/:task_id/cancelStop the training that’s running.
- GET/v1/tasks/:task_id/callsIts calls of the last 30 days, newest first. ?q= searches what they asked or answered; ?review=wrong or corrected.
- POST/v1/tasks/:task_id/calls/:call_id/reviewMark a call’s answer wrong, {"wrong": true}, and give the right one with "answer": the next round learns from it.
- GET/v1/tasks/:task_id/examplesThe held-out calls, with the frontier model’s answers and every student’s.
- GET/v1/tasks/:task_id/media/:nameAn image from one of those calls.
- GET/v1/tasks/:task_id/export/teacherThe frontier model’s answer and reasoning for each example it answered, beside the answer the students learned, as JSON lines.
- GET/v1/tasks/:task_id/export/:candidate_idWhat a student trained on, as chats ready for fine-tuning, then its answers to the held-out examples, as JSON lines.
- GET/v1/tasks/:task_id/export/:candidate_id/configHow a student trained, as JSON: base model, settings, the trainer’s recipe, its data and prompt versions.
- GET/v1/tasks/:task_id/export/:candidate_id/adapterA link, good for 15 minutes, that downloads a trained student’s LoRA adapter as a zip.
- POST/v1/tasks/:task_id/serving/wakeStart a sleeping model ahead of traffic.
Data
- GET/v1/datasetsEvery file and import you’ve brought.
- POST/v1/datasetsUpload past examples as files. Train on one with POST /v1/tasks.
- GET/v1/datasets/:dataset_id/previewPage through its rows or items with offset and limit.
- DELETE/v1/datasets/:dataset_idDelete it.
- GET/v1/connectorsThe warehouses and buckets you can connect, and the settings each needs.
- POST/v1/connectionsTest a connection, then save it with its secrets encrypted.
- POST/v1/connections/:connection_id/importImport a table, query, or folder as a dataset.
Webhooks
- GET/v1/webhooksYour webhook URL, its secret, and its latest deliveries.
- PUT/v1/webhooksSet the URL Sous posts your models’ events to: {"url": "https://..."}.
- POST/v1/webhooks/testPost a ping to it now, and say how it went.
- POST/v1/webhooks/rollMake a new secret. Posts are signed with it from then on.
- DELETE/v1/webhooksStop posting, and forget its secret and deliveries.
Agents
- POST/mcpSous’s MCP server, for coding agents. Same API key.
Webhooks
Set a URL on the API keys page in Sous, and Sous posts there when something happens to one of your models, so your code can act on it: tell your team, or switch to a student. Each post is JSON, signed with your webhook’s secret.
| Event | When | In data, besides model |
|---|---|---|
| model.training.succeeded | A model’s first training finished. | recommended: the student Sous recommends. answering: the one answering calls, or null. |
| model.training.failed | A model’s first training failed. | error: why. |
| model.ready_to_switch | A student Sous recommends isn’t answering calls yet: after the first training, or when a round finds a clearly better one. | student, answering, and after: training or round. After a round, gain and measure: how much better, and on what. |
| model.switched | Calls go to another student now, or back to the frontier model. | student (null: the frontier model), previous, and automatic: whether Sous switched on its own. |
| model.quality_dropped | A round found the live student agreeing with the frontier model clearly less often on the newest calls than on older ones. | student, newest: {calls, agreement}, and older: {agreement}. |
| ping | You sent a test from the API keys page. | message. |
A student is {id, base_model, agreement}, where agreement is the share of held-out calls it answers like the frontier model, from 0 to 1.
{
"id": "evt_3b8f0c2e9a1d4f6b8c0e2a4d",
"type": "model.ready_to_switch",
"created": 1764115200,
"data": {
"model": {
"id": "f27d3be0",
"name": "Ticket router",
"url": "https://app.sousml.com/models/f27d3be0"
},
"student": {"id": "c4", "base_model": "qwen3.5-4b", "agreement": 0.962},
"answering": {"id": "c2", "base_model": "qwen3.5-2b", "agreement": 0.941},
"after": "round",
"gain": 0.021,
"measure": "agreement"
}
}Check the signature
The Sous-Signature header looks like t=1764115200,v1=5257a8…: when Sous signed the post, in Unix seconds, and an HMAC-SHA256, in hex, of that time, a dot, and the raw body, keyed with your secret. Compute it over the body as it arrived, before parsing, and refuse posts more than five minutes old.
import hashlib, hmac, os, time
from fastapi import FastAPI, HTTPException, Request
app = FastAPI()
SECRET = os.environ["SOUS_WEBHOOK_SECRET"]
def verify(header: str, body: bytes) -> bool:
parts = dict(p.split("=", 1) for p in header.split(",") if "=" in p)
if not parts.get("t", "").isdigit() or "v1" not in parts:
return False
signed = parts["t"].encode() + b"." + body
expected = hmac.new(SECRET.encode(), signed, hashlib.sha256).hexdigest()
fresh = abs(time.time() - int(parts["t"])) < 300
return fresh and hmac.compare_digest(expected, parts["v1"])
@app.post("/sous-events")
async def sous_events(request: Request):
body = await request.body() # the raw body, before parsing
if not verify(request.headers.get("sous-signature", ""), body):
raise HTTPException(status_code=400)
event = await request.json()
if event["type"] == "model.ready_to_switch":
... # tell your team, or switch with POST /v1/tasks/{id}/promote
return {"ok": True}Answering and retries
Answer with any 2xx within 10 seconds. Otherwise Sous tries again after 1, 5, 30, 120 and 360 minutes, then gives up. An event can arrive more than once, with the same id in the body and in Sous-Event-Id, so skip ids you’ve seen. Sous posts only to public https URLs and doesn’t follow redirects. The API keys page shows the latest deliveries and sends a test, a ping, which is tried once.
Limits
| Limit | Value |
|---|---|
| Calls before the first training | 30; 50 or more conversations train better |
| Examples in one training or round | At most 10,000. A larger file is sampled down to that. Each later round on live calls can add another 10,000. |
| Held out for the test | About 20% of conversations, never trained on |
| Students per training or round | Up to 4 |
| Share of calls the frontier model keeps answering | Up to 20%, while Keep improving is on |
| Training budget | At most half your credits, so your models keep answering |
| Monthly spending limit | Optional, for your account and for each model. Past it, paid work stops until the 1st of the next month. |
| A model with no calls sleeps after | 2 minutes; it takes about 3 to start again |
Errors
Errors come back in OpenAI’s format, so OpenAI’s SDKs raise their usual exceptions.
{
"error": {
"message": "Incorrect API key provided. Make one in Sous under API keys.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}| Code | When |
|---|---|
| 400 Bad request | The request is malformed: a body OpenAI’s API wouldn’t accept, or a call sent without its answer. |
| 401 Unauthorized | The API key is missing or wrong. The code is invalid_api_key. |
| 402 Payment required | Out of credits (insufficient_credits), or past a monthly spending limit (spending_limit_reached). Add credits, or raise the limit, on the Billing page. |
| 404 Not found | No model, student, or dataset with that id under your key. |