Model management
Endpoints to download, load, change, remove and import models — what Settings → Models and the `midium models` commands do, from your own scripts.
For developers
Besides the inference API, the engine has endpoints that control which models are on disk and which are in memory. Settings → Models and midium models use them; you can script them too. They take your key in Authorization (with or without Bearer), return JSON, and live at the root of http://127.0.0.1:9100 (no /v1).
A model goes through three states: in the library (Midium knows it, nothing downloaded) → added to your models (weights downloaded; shown as Installed until it loads) → loaded (in memory, answering requests). Flex models load on their first request and unload after a while idle; static models stay loaded.
Several request bodies have an api_key field. The schema requires it, but the Authorization header is what authenticates — send any string, or your key.
Add a model#
POST /add-workbench-model/ adds a model to your models and downloads its weights to ~/Midium/models/.
curl http://127.0.0.1:9100/add-workbench-model/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"api_key": "-", "name": "gpt-oss-20b", "install_only": true}'
| Name | Type | Description |
|---|---|---|
name | string | Required. The model's catalog or library name (midium models catalog lists them). |
api_key | string | Required by the schema; see the note above. |
install_only | boolean | true: download only, don't load. Default false (a static model loads once downloaded). |
api_type | string | flex (loads when used, unloads when idle) or static (always loaded). Default: your default from Settings. |
context_window | integer | Default: the model's own maximum. |
nickname | string | A second name to call it by. |
instances | integer | Copies of the model to run, each with its own memory. Default 1. |
batch_size | integer | Requests each copy works on at once. Default 1. |
speculative_decoding | boolean | Omit to turn it on automatically when the model has a speculative-decoding helper; false to leave it off. The helper downloads alongside. |
Response (201):
{
"detail": "gpt-oss-20b added to workbench successfully",
"model_id": "5f0c1a7e-3d2b-4c8e-9a61-2b7d4e0f9c13",
"download_job_id": "8e2f4c1a-…",
"download_status_endpoint": "/models/download-status/?job_id=8e2f4c1a-…",
"speculative_decoding": false,
"drafter_download_job_id": null
}
If the model is already one of yours you get 200 with "deduplicated": true and its existing model_id. Weights already on disk aren't downloaded again, and a download cut off by a restart resumes on the next start. An unknown name returns 404.
Watch a download#
| Route | What it does |
|---|---|
GET /models/download-status/?job_id=<id> | One job. Use ?model_id=<id> for a model's latest job, or neither for {"jobs": [...]} (recent jobs). |
GET /models/download-status/stream?job_id=<id> | The same as server-sent events, one frame per change; closes when the job ends. |
POST /models/download/retry/ | Retry a failed job: {"job_id": "<id>"} or {"model_id": "<id>"}. Returns 202 with the new download_job_id. Only failed jobs can be retried. |
A job reports status (queued, downloading, loading, ready, error or cancelled), stage, message, percent, downloaded_gb / total_gb, mb_per_sec, eta_seconds and error. gated: true means the Hugging Face repo needs you to sign in or accept its terms (add a Hugging Face token in Settings → Advanced).
Load a model#
POST /load-workbench-model/ brings an installed model into memory. It does nothing if it's already loaded.
{"api_key": "-", "name": "gpt-oss-20b", "model_id": "5f0c1a7e-3d2b-4c8e-9a61-2b7d4e0f9c13"}
| Name | Type | Description |
|---|---|---|
name, model_id | string | Required. The model's name and id. |
auto_fit | boolean | Default true: if it won't fit in memory at its context, load it at the largest context that fits. false: don't load; report what would fit instead. |
persist_fit | boolean | With an auto-fit load, save the reduced context as the model's setting. |
Response: {"loaded": true, "fits": true, "model_id": "…", "context_window": 131072}. With auto_fit: false and not enough memory: {"loaded": false, "fits": false, "max_fitting_context": 32768, "required_gb": …, "available_gb": …} (max_fitting_context is null when no context would fit).
Change a model#
POST /update-workbench-model/ changes a model in place, keeping its model_id. Send model_id and only the fields you're changing:
{"model_id": "5f0c1a7e-3d2b-4c8e-9a61-2b7d4e0f9c13", "context_window": 32768, "instances": 2}
| Name | Type | Description |
|---|---|---|
context_window | integer | At least 1. If it doesn't fit memory, Midium uses the largest that does. |
api_type | string | flex or static. Switching an idle model to static loads it. |
instances | integer | 1–8. |
batch_size | integer | 1–32. |
speculative_decoding | boolean | Only for models that have a helper (400 otherwise). |
file_path | string | Point the model at another folder, or a .safetensors / .gguf file, on this Mac. Owner only. If it can't load from there, the old location is kept and you get 409. |
A loaded model reloads to apply a change (running requests finish first); an idle one picks it up on its next load.
Remove and delete#
POST /remove-workbench-model/with{"api_key": "-", "name": "…", "model_id": "…"}takes a model off your models (Remove from my models). It's unloaded and any download in progress is cancelled. Its files stay on disk, so adding it back needs no download.POST /delete-model-files/with{"api_key": "-", "name": "…"}deletes its downloaded files from~/Midium/models/and reportsfreed_gb. Admin key. It refuses with409while the model is still one of yours — remove it first. Files outside the models folder are never deleted; the response names them inkept_outside.
Import models already on disk#
For model folders in ~/Midium/models/ that Midium doesn't know — copied in by hand, or downloaded by another tool:
GET /local-model-candidates/(admin) lists them as{"candidates": [...], "skipped": [{"folder", "reason"}]}, each candidate with a suggestedname,model_type,familyandcontext_window.POST /import-local-models/(admin) registers the ones you pick — no copy, no download:
{"models": [{"folder": "mlx-community_gpt-oss-20b-MXFP4-Q8", "name": "gpt-oss-20b (local)"}]}
Each item can override name, model_type, family and context_window. The response is {"imported": [...], "errors": [...]}. Then add the model as above.
GET /installed-model-dirs/ lists the folder names under ~/Midium/models/: {"dirs": [...], "external": []}.
Register a library model#
POST /add-library-model/ (admin) adds a model that isn't in the catalog. file_path is a Hugging Face repo id; re-posting a name updates it.
{
"api_key": "-",
"name": "gpt-oss-20b",
"family": "GPT-OSS",
"context_window": 131072,
"adapter_path": null,
"model_type": "text-text",
"file_path": "mlx-community/gpt-oss-20b-MXFP4-Q8",
"weights_gb": 12
}
All fields are required (adapter_path may be null).
List models#
GET /v1/models— the OpenAI list: every model your key can use, withtype,capabilitiesandcontext_length.GET /get-workbench-models/—{"models": [...]}: your models with theirid, settings,loaded_in_memoryandinstalled.
Errors#
These routes return {"error": "…"} (or {"detail": "…"}) with the status: 400 for a bad value (instances out of range, api_type not flex/static), 401 for a model your key can't change, 404 for an unknown model or job, 409 for a delete while the model is still yours or a file_path that won't load, and 500 when a load or download fails. See Errors & limits.
Something here wrong or out of date? Tell us.
