From f87f9af2771ead3637af4cef87932dd282e05607 Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Mon, 9 Mar 2026 08:01:59 -0700 Subject: [PATCH] docs: document API error response format Co-Authored-By: Claude Opus 4.6 --- docs/api.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/api.md b/docs/api.md index 150479e6a..fad97c6b0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -32,6 +32,47 @@ All durations are returned in nanoseconds. Certain endpoints stream responses as JSON objects. Streaming can be disabled by providing `{"stream": false}` for these endpoints. +### Error responses + +If a request fails, the API returns an appropriate HTTP status code along with a JSON object containing an `error` field with a description of the issue: + +```json +{ + "error": "model 'nomodel' not found" +} +``` + +Common HTTP status codes: + +| Status Code | Description | +|-------------|-------------| +| 400 | Bad request - the request body is invalid or missing required fields | +| 404 | Not found - the requested model does not exist | +| 500 | Internal server error - an unexpected error occurred on the server | + +#### Example + +##### Request + +```shell +curl http://localhost:11434/api/generate -d '{ + "model": "nomodel", + "prompt": "Hello" +}' +``` + +##### Response + +``` +HTTP/1.1 404 Not Found +``` + +```json +{ + "error": "model 'nomodel' not found" +} +``` + ## Generate a completion ```