# Sous > Sous, by Roe, trains a small open model on your app's own calls to a frontier model, tests it on calls it never saw, and switches your app to it when it answers like the frontier model for less. Then it keeps training on newer calls. - OpenAI-compatible base URL: https://api.sousml.com/v1 - Auth: send `Authorization: Bearer $SOUS_API_KEY` on every request. The SDK reads `SOUS_API_KEY` from the environment. - A model has an id like `f27d3be0`. Its students are c1, c2, and so on; call one by name with `f27d3be0:c2`. - Errors use OpenAI's error format. ## Links - [Docs](https://sousml.com/docs): quickstart, ways to connect, calling your model, training, keeps improving, results, endpoints, webhooks, limits, errors - [Use cases](https://sousml.com/use-cases): the decisions Sous learns, and solutions by team - [PII redaction](https://sousml.com/use-cases/pii-redaction): train a small PII redaction model on your own data, in any language and with your own types of personal data - [Document extraction](https://sousml.com/use-cases/document-extraction): train a small model that pulls the fields you need out of PDFs, invoices, receipts and forms into JSON - [Pricing](https://sousml.com/pricing) - [Guides](https://sousml.com/guides): [How to use Jev: API key, Python SDK and your first decision](https://sousml.com/guides/how-to-use-jev), [Jev as a judge: a cheaper LLM-as-a-judge for typed checks](https://sousml.com/guides/jev-as-a-judge), [Qwen 3.8 27B: vision, context, benchmarks and how to fine-tune it](https://sousml.com/guides/fine-tune-qwen-3-8-27b), [OpenPipe and Predibase alternatives: where to fine-tune in 2026](https://sousml.com/guides/openpipe-predibase-alternatives), [How to train your own Jev: a decision model for your app](https://sousml.com/guides/train-your-own-jev), [Jev vs Laya vs OpenAI Decisions API: decision models compared](https://sousml.com/guides/jev-vs-laya), [Private LLM: how to run a model you own, and what it takes](https://sousml.com/guides/private-llm), [OpenAI fine-tuning is ending: where to move your fine-tuned models](https://sousml.com/guides/openai-fine-tuning-alternative), [Best small open models to fine-tune in 2026](https://sousml.com/guides/best-small-open-models-to-fine-tune), [How to cut LLM costs](https://sousml.com/guides/llm-cost-optimization), [How to fine-tune an LLM without an ML team](https://sousml.com/guides/fine-tune-llm-without-ml-team), [LLM distillation explained](https://sousml.com/guides/llm-distillation), [Fine-tuning vs RAG vs prompting](https://sousml.com/guides/fine-tuning-vs-rag-vs-prompting), [LoRA vs QLoRA vs full fine-tuning](https://sousml.com/guides/lora-vs-qlora-vs-full-fine-tuning), [SLM vs LLM: when a small model beats a large one](https://sousml.com/guides/slm-vs-llm) ## Use cases Sous fits any decision an app asks a model to make many times a day, where the answer has a shape: a label from a list, yes or no, fields, a score. Text, images, or both can go in. - Route: Send each item to the right queue, team or tool. For example, support tickets, inbound email, an agent’s next tool. - Flag: Say yes or no, and why: what needs a person and what doesn’t. For example, fraud alerts, spam and scams, account takeover. - Check: Hold a message, document or reply up to your policy. For example, content moderation, refund rules, an agent’s replies. - Tag: Apply labels from your own list, one or several. For example, bank transactions, products, document types. - Redact: Find what must not leak, in text and in images. For example, chats, ID photos, call transcripts. - Extract: Pull fields out into the JSON your app expects. For example, invoices, receipts, contracts. - Score: Put a grade on each item, on your own scale. For example, leads, risk, urgency. - Match: Decide whether two records are the same thing. For example, duplicate customers, payments and invoices, sanctions lists. By team: - Fraud and risk: clear or escalate transaction alerts; spot account takeover in login events; sort disputes by reason code. - Compliance: close or escalate AML alerts, with the reason; clear or confirm sanctions list hits; check KYC documents for missing or expired details. - Customer support: send tickets to the right queue; set priority and sentiment; decide whether a refund fits your policy. - Trust and safety: moderate posts and messages against your rules; catch spam and scams; remove personal details before they’re stored. - Finance operations: pull totals, dates and lines from invoices; code expenses to your ledger accounts; match payments to invoices. - Marketplaces: put listings in the right category; check listings against your rules; find duplicate listings and sellers. - Sales: score inbound leads; send each lead to the right rep; tag industry and company size from a website. - Legal operations: find the clauses that matter in a contract; mark documents relevant or not in a review; remove names before documents are shared. ## Ways to connect - 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 ```python # 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}], ) ``` ```ts // npm install sous-ai import OpenAI from "openai"; import { sous } from "sous-ai"; const client = sous(new OpenAI(), { model: "f27d3be0" }); // The rest of your code stays as it is. const response = await client.chat.completions.create({ model: "gpt-5.5", messages: [{ role: "user", content: chat }], }); ``` Anthropic and Azure OpenAI clients are wrapped the same way: ```python # pip install sousml from anthropic import Anthropic from sousml import Sous client = Sous(Anthropic(), model="f27d3be0") ``` ### No code changes ```bash 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:app ``` ```bash npm install sous-ai # Every OpenAI, Azure OpenAI and Anthropic client the app makes now trains f27d3be0. SOUS_MODEL=f27d3be0 node --import sous-ai/register app.js SOUS_MODEL=f27d3be0 NODE_OPTIONS="--import sous-ai/register" npm start ``` A bundled app, such as a Next.js app, hides the openai package from Node: wrap its client in code instead. ### Point at Sous Sous calls the frontier model for you until a student is live. If the app has no model yet, Sous picks one. ```python 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 ```bash 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"} ] } }' ``` For Anthropic's shape, add `"api": "messages"` and send the Messages request and response. ### Coding agents ```bash claude mcp add --transport http sous https://api.sousml.com/mcp \ --header "Authorization: Bearer $SOUS_API_KEY" ``` ## Calling your model - 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. - 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. The `x-sous-answered-by` response header says which one did. - When a call asks for JSON and sets no temperature, a student gives its most likely answer, so the same call gets the same answer. - A model with no calls for 2 minutes sleeps and takes about 3 minutes to start again. `POST /v1/tasks/{task_id}/serving/wake` starts it ahead of traffic. ## Training Sous keeps each call and the frontier model's answer as whole conversations. With at least 30 (50 or more trains better), and once calls pause, it holds about 20% of conversations out as the test, fine-tunes open models in a few sizes on the rest, tests every student and the untrained model on the held-out calls, and recommends the student that answers most like the frontier model, preferring the cheaper one when two are close. Training takes at most half your credits. ## Keeps improving Each round, Sous trains on 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. While Keep improving is on, the frontier model keeps answering a share of calls (up to 20%, set by Sous each round) so rounds have new calls. - 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. ## Endpoints Paths are relative to https://api.sousml.com. Models are called tasks in the paths. ### Calls - `POST /v1/chat/completions`: Call a model with its id, or a student with id:c2. OpenAI’s request and response. - `POST /v1/responses`: The same, through OpenAI’s Responses API. - `GET /v1/models`: The models your key can call. - `POST /v1/models/{model}/calls`: Send a call your app made, with its answer, for the model to learn from. ### Models - `POST /v1/tasks`: Create a model. It learns from the app’s calls, or from uploaded datasets when source is "dataset". - `GET /v1/tasks`: Your models, newest first. ?archived=true lists the ones taken off that list. - `POST /v1/tasks/{task_id}/archive`: Take a model off the models list. Calls to it keep working. - `POST /v1/tasks/{task_id}/restore`: Put an archived model back on the models list. - `GET /v1/tasks/{task_id}`: Status, readiness, students, the live one, settings, and usage. - `PATCH /v1/tasks/{task_id}`: Change its settings: auto_train, auto_promote, keep_improving, monthly_limit, and more. - `POST /v1/tasks/{task_id}/preview`: Label a few examples of a dataset draft, before training starts. - `POST /v1/tasks/{task_id}/start`: Start training a dataset draft, or a model that learns from calls, now. - `POST /v1/tasks/{task_id}/promote`: Send calls to a student by candidate_id, or back to the frontier model with null. - `POST /v1/tasks/{task_id}/improve`: Run a round now. {"warm_start": true} continues the recommended student's LoRA. - `POST /v1/tasks/{task_id}/cancel`: Stop the training that’s running. - `GET /v1/tasks/{task_id}/calls`: Its 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}/review`: Mark 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}/examples`: The held-out calls, with the frontier model’s answers and every student’s. - `GET /v1/tasks/{task_id}/media/{name}`: An image from one of those calls. - `GET /v1/tasks/{task_id}/export/teacher`: The 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_id}`: What 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}/config`: How 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}/adapter`: A link, good for 15 minutes, that downloads a trained student’s LoRA adapter as a zip. - `POST /v1/tasks/{task_id}/serving/wake`: Start a sleeping model ahead of traffic. ### Data - `GET /v1/datasets`: Every file and import you’ve brought. - `POST /v1/datasets`: Upload past examples as files. Train on one with POST /v1/tasks. - `GET /v1/datasets/{dataset_id}/preview`: Page through its rows or items with offset and limit. - `DELETE /v1/datasets/{dataset_id}`: Delete it. - `GET /v1/connectors`: The warehouses and buckets you can connect, and the settings each needs. - `POST /v1/connections`: Test a connection, then save it with its secrets encrypted. - `POST /v1/connections/{connection_id}/import`: Import a table, query, or folder as a dataset. ### Webhooks - `GET /v1/webhooks`: Your webhook URL, its secret, and its latest deliveries. - `PUT /v1/webhooks`: Set the URL Sous posts your models’ events to: {"url": "https://..."}. - `POST /v1/webhooks/test`: Post a ping to it now, and say how it went. - `POST /v1/webhooks/roll`: Make a new secret. Posts are signed with it from then on. - `DELETE /v1/webhooks`: Stop posting, and forget its secret and deliveries. ### Agents - `POST /mcp`: Sous’s MCP server, for coding agents. Same API key. ## Webhooks Set a URL on the API keys page (or `PUT /v1/webhooks` with `{"url": "https://..."}`), and Sous posts JSON there when something happens to one of your models: - `model.training.succeeded`: a model's first training finished. data.recommended is the student Sous recommends, data.answering the one answering calls (or null). - `model.training.failed`: a model's first training failed. data.error says why. - `model.ready_to_switch`: a student Sous recommends isn't answering calls yet, after the first training or a round (data.after). data.student, data.answering; after a round, data.gain and data.measure. - `model.switched`: calls go to another student (data.student; null is the frontier model). data.previous, data.automatic. - `model.quality_dropped`: the live student agrees with the frontier model clearly less often on the newest calls. data.newest {calls, agreement}, data.older {agreement}. - `ping`: a test from the API keys page. A student is {id, base_model, agreement}. Every event's data has model {id, name, url}. ```json { "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" } } ``` The `Sous-Signature` header is `t=,v1=.", keyed with the webhook's secret>`. Check it on the raw body and refuse posts more than five minutes old. Answer 2xx within 10 seconds; otherwise Sous retries after 1, 5, 30, 120 and 360 minutes. The same event can arrive twice with the same id (also in `Sous-Event-Id`). ```python 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} ``` ## Limits - 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 ```json { "error": { "message": "Incorrect API key provided. Make one in Sous under API keys.", "type": "invalid_request_error", "param": null, "code": "invalid_api_key" } } ``` - 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.