models
Classes
ModelsClient
ModelsClient(client: OWUIClientBase)
Bases: ResourceBase
Client for the Models endpoints.
- Code Reference client Classes OpenWebUI Attributes models
Source code in src/owui_client/client_base.py
Functions
get_models
get_models(
query: Optional[str] = None,
view_option: Optional[str] = None,
tag: Optional[str] = None,
order_by: Optional[str] = None,
direction: Optional[str] = None,
page: Optional[int] = 1,
) -> ModelListResponse
Get a list of models with optional filtering and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Optional[str]
|
Search query string. |
None
|
view_option
|
Optional[str]
|
View option. Accepted values:
- |
None
|
tag
|
Optional[str]
|
Filter by tag. |
None
|
order_by
|
Optional[str]
|
Field to order by ('name', 'created_at', 'updated_at'). |
None
|
direction
|
Optional[str]
|
Sort direction ('asc', 'desc'). |
None
|
page
|
Optional[int]
|
Page number (1-based). |
1
|
Returns:
| Type | Description |
|---|---|
ModelListResponse
|
|
Source code in src/owui_client/routers/models.py
get_base_model_tags
Get the distinct set of tags used across base models.
Base models are models with no base_model_id (i.e. the underlying
connected models, as opposed to workspace/derived models). Tags are
collected from each base model's meta.tags entries. Requires admin
privileges.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Sorted, de-duplicated list of base-model tag names. |
Source code in src/owui_client/routers/models.py
get_base_models
get_base_models() -> list[ModelResponse]
Get all base models.
Returns:
| Type | Description |
|---|---|
list[ModelResponse]
|
list[ModelResponse]: List of base models. |
get_base_models_direct
get_base_models_direct() -> list[ModelResponse]
Get all base models (direct endpoint).
This is the legacy endpoint from main.py that provides base models.
Returns:
| Type | Description |
|---|---|
list[ModelResponse]
|
list[ModelResponse]: List of base models. |
Source code in src/owui_client/routers/models.py
get_model_tags
Get all unique tags used in models.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: List of tag names. |
create_new_model
create_new_model(
form_data: ModelForm,
) -> Optional[ModelModel]
Create a new model.
Requires valid permissions (admin or workspace.models).
The model ID must be unique and <= 256 characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
ModelForm
|
The model data to create. |
required |
Returns:
| Type | Description |
|---|---|
Optional[ModelModel]
|
Optional[ModelModel]: The created model. |
Source code in src/owui_client/routers/models.py
export_models
export_models() -> list[ModelModel]
import_models
import_models(form_data: ModelsImportForm) -> bool
Import models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
ModelsImportForm
|
The form data containing models to import. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if import was successful. |
Source code in src/owui_client/routers/models.py
sync_models
sync_models(form_data: SyncModelsForm) -> list[ModelModel]
Sync models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
SyncModelsForm
|
The models to sync. |
required |
Returns:
| Type | Description |
|---|---|
list[ModelModel]
|
list[ModelModel]: The list of synced models. |
Source code in src/owui_client/routers/models.py
get_model_by_id
get_model_by_id(id: str) -> Optional[ModelResponse]
Get a model by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The model ID. |
required |
Returns:
| Type | Description |
|---|---|
Optional[ModelResponse]
|
Optional[ModelResponse]: The model details. |
Source code in src/owui_client/routers/models.py
get_model_profile_image
Get a model's profile image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The model ID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The image data. |
Source code in src/owui_client/routers/models.py
toggle_model_by_id
toggle_model_by_id(id: str) -> Optional[ModelResponse]
Toggle a model's active state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The model ID. |
required |
Returns:
| Type | Description |
|---|---|
Optional[ModelResponse]
|
Optional[ModelResponse]: The updated model. |
Source code in src/owui_client/routers/models.py
update_model_by_id
update_model_by_id(
form_data: ModelForm,
) -> Optional[ModelModel]
Update a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
ModelForm
|
The updated model data (must include ID). |
required |
Returns:
| Type | Description |
|---|---|
Optional[ModelModel]
|
Optional[ModelModel]: The updated model. |
Note
How access_grants is handled depends on whether the caller specifies it:
- Caller omits
access_grants(or passesNone): the model's existing grants are preserved by fetching them viaget_model_by_idand re-sending them. This mirrors the frontend, which always re-sends the current grant list on update. - Caller passes a populated list: the grants are replaced with that list.
- Caller passes
[]: the grants are cleared (intentional).
A list must always be sent (never None or omitted from the JSON body): the
backend handler re-validates the body as ModelForm(**form_data.model_dump()),
and ModelForm.access_grants is typed list[dict | None] = None (a pydantic v2
gotcha that rejects an explicit None), so sending None raises an unhandled
ValidationError -> HTTP 500 (present in Open WebUI 0.9.6-0.10.1). On the DB side,
a non-None list is passed to AccessGrants.set_access_grants, which deletes all
existing grants and re-inserts the provided ones — so an unconditional [] would
silently wipe any sharing grants. Preserving the current list avoids both pitfalls.
If the current model cannot be fetched, [] is used as a last-resort fallback.
Note: when grants are omitted they are fetched then re-sent in a separate GET
followed by the POST, so a concurrent writer could change grants between the
two calls; this matches the frontend's behavior.
Source code in src/owui_client/routers/models.py
delete_model_by_id
Delete a model by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The model ID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if deletion was successful. |
Source code in src/owui_client/routers/models.py
delete_all_models
Delete all models.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful. |
update_model_access
update_model_access(
form_data: ModelAccessGrantsForm,
) -> Optional[ModelModel]
Update a model's access grants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
ModelAccessGrantsForm
|
The form containing the model ID and access grants. |
required |
Returns:
| Type | Description |
|---|---|
Optional[ModelModel]
|
Optional[ModelModel]: The updated model. |
Source code in src/owui_client/routers/models.py
unload_model
Unload a model from its provider.
Resolves the provider that owns the model and calls its native unload mechanism. Supports Ollama (keep_alive=0) and llama.cpp (/models/unload). Requires admin privileges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model ID to unload. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Provider-specific response. Ollama returns |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 if provider doesn't support unloading, 404 if model not found, 500 on provider errors. |