open-webui/open-webui · error · HTTPException
str(e)
Error message
str(e)
What it means
Generic 500 raised by the catch-all handler at the end of POST /api/v1/models/import (backend/open_webui/routers/models.py:475). Any non-HTTPException error escaping the import loop — most commonly a pydantic ValidationError when a malformed entry is coerced with ModelForm(**model_data), or a database failure during insert/update — is logged via log.exception and re-raised as HTTP 500 with the raw exception string as detail. Note the inner try/except only guards knowledge-file access; every other failure in the loop bubbles up.
Source
Thrown at backend/open_webui/routers/models.py:475
user.id,
user.role,
new_model.access_grants,
'sharing.public_models',
)
await Models.insert_new_model(user_id=user.id, form_data=new_model, db=db)
await publish_event(
request,
EVENTS.MODEL_IMPORTED,
actor=user,
subject_type='model',
data={'count': len(imported_ids), 'model_ids': imported_ids},
)
return True
else:
raise HTTPException(status_code=400, detail='Invalid JSON format')
except Exception as e:
log.exception(e)
raise HTTPException(status_code=500, detail=str(e))
############################
# SyncModels
############################
class SyncModelsForm(BaseModel):
models: list[ModelModel] = []
@router.post('/sync', response_model=list[ModelModel])
async def sync_models(
request: Request,
form_data: SyncModelsForm,
user=Depends(get_admin_user),
db: AsyncSession = Depends(get_async_session),
):View on GitHub (pinned to 01f4282f1f)
Solutions
- Check the server log — log.exception(e) prints the full traceback with the offending entry; the 500 detail (str(e)) usually names the failing pydantic field.
- Re-export the models from a source instance running the same Open WebUI version and import that file unmodified.
- Validate each entry against the current ModelForm schema (id, name, meta, params types) before POSTing; drop or fix entries that fail.
- If the traceback shows an IntegrityError/DB error, retry once the database is healthy; the endpoint is not transactional, so previously inserted models may need manual cleanup before re-import.
Example fix
// before: importing a hand-edited payload with a bad params type
await fetch('/api/v1/models/import', {method:'POST', body: JSON.stringify({models: rawExport.models})}); // 500 'params Input should be a valid dictionary'
// after: schema-check each entry client-side first
const valid = rawExport.models.filter(m =>
typeof m.id === 'string' && m.id &&
typeof m.name === 'string' &&
(m.params ?? {}) instanceof Object && !Array.isArray(m.params ?? {})
);
await fetch('/api/v1/models/import', {method:'POST', body: JSON.stringify({models: valid})}); Defensive patterns
Strategy: validation
Validate before calling
// Client-side: screen every entry before POST /api/v1/models/import
function isValidModelEntry(m) {
return m && typeof m === 'object' &&
typeof m.id === 'string' && m.id.length > 0 &&
typeof m.name === 'string' && m.name.length > 0 &&
(m.meta === undefined || (m.meta instanceof Object && !Array.isArray(m.meta))) &&
(m.params === undefined || (m.params instanceof Object && !Array.isArray(m.params)));
}
const payload = { models: exportData.models.filter(isValidModelEntry) }; Try / catch
try {
const res = await fetch('/api/v1/models/import', {method: 'POST', headers: authHeaders(), body: JSON.stringify(payload)});
if (!res.ok) {
const { detail } = await res.json();
// detail is the raw str(e): parse the pydantic field name out of it
console.error('import failed:', detail);
return { ok: false, reason: detail };
}
return { ok: true };
} catch (networkErr) {
// transport-level failure only; HTTP errors handled above
throw networkErr;
} Prevention
- Always import files exported by the same Open WebUI version you are importing into.
- Never hand-edit exported JSON beyond simple field values; schema drift surfaces as an opaque 500.
- Remember the endpoint is not atomic — a failure mid-list may leave earlier entries inserted; verify state after any 500.
- Check server logs first: the traceback names the exact entry and field that failed.
When it happens
Trigger: POST /api/v1/models/import where form_data.models is a list but an entry contains fields that fail ModelForm validation (wrong types in meta/params, bad access_grants shape, missing name), or the DB connection/commit fails mid-import. Entries with valid shape but invalid ids are silently skipped (is_valid_model_id), so this 500 specifically means schema/DB failure, not bad ids.
Common situations: Importing a models-export.json produced by a different (older/newer) Open WebUI version whose ModelForm schema has drifted; hand-edited export files; importing a file that contains tool/prompt exports mixed in; concurrent imports hitting a uniqueness conflict on model id; DB restart during import.
Related errors
- Error creating model entry
- Unable to get OAuth token
- Model not found
- Internal Server Error
- Failed to re-register OAuth client
AI-assisted analysis of open-webui/open-webui@01f4282f1f (2026-08-14).
Data as JSON: /api/errors/6963a630f6c149ca.
Report an issue: GitHub.