API Error Reference

This page documents the error responses returned by the LocalAI API. LocalAI supports multiple API formats (OpenAI, Anthropic, Open Responses), each with its own error structure.

Error Response Formats

OpenAI-Compatible Format

Most endpoints return errors using the OpenAI-compatible format:

{
  "error": {
    "code": 400,
    "message": "A human-readable description of the error",
    "type": "invalid_request_error",
    "param": null
  }
}
FieldTypeDescription
codeinteger|stringHTTP status code or error code string
messagestringHuman-readable error description
typestringError category (e.g., invalid_request_error)
paramstring|nullThe parameter that caused the error, if applicable

This format is used by: /v1/chat/completions, /v1/completions, /v1/embeddings, /v1/images/generations, /v1/audio/transcriptions, /models, and other OpenAI-compatible endpoints.

Anthropic Format

The /v1/messages endpoint returns errors in Anthropic’s format:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "A human-readable description of the error"
  }
}
FieldTypeDescription
typestringAlways "error" for error responses
error.typestringinvalid_request_error or api_error
error.messagestringHuman-readable error description

Open Responses Format

The /v1/responses endpoint returns errors with this structure:

{
  "error": {
    "type": "invalid_request",
    "message": "A human-readable description of the error",
    "code": "",
    "param": "parameter_name"
  }
}
FieldTypeDescription
typestringOne of: invalid_request, not_found, server_error, model_error, invalid_request_error
messagestringHuman-readable error description
codestringOptional error code
paramstringThe parameter that caused the error, if applicable

HTTP Status Codes

CodeMeaningWhen It Occurs
400Bad RequestInvalid input, missing required fields, malformed JSON
401UnauthorizedMissing or invalid API key
404Not FoundModel or resource does not exist
409ConflictResource already exists (e.g., duplicate token)
422Unprocessable EntityValidation failed (e.g., invalid parameter range)
500Internal Server ErrorBackend inference failure, unexpected server errors

Global Error Handling

Authentication Errors (401)

When API keys are configured (via LOCALAI_API_KEY or --api-keys), all requests must include a valid key. Keys can be provided through:

  • Authorization: Bearer <key> header
  • x-api-key: <key> header
  • xi-api-key: <key> header
  • token cookie

Example request without a key:

curl http://localhost:8080/v1/models \
  -H "Content-Type: application/json"

Error response:

{
  "error": {
    "code": 401,
    "message": "An authentication key is required",
    "type": "invalid_request_error"
  }
}

The response also includes the header WWW-Authenticate: Bearer.

Request Parsing Errors (400)

All endpoints return a 400 error if the request body cannot be parsed:

{
  "error": {
    "code": 400,
    "message": "failed parsing request body: <details>",
    "type": ""
  }
}

Not Found (404)

Requests to undefined routes return:

{
  "error": {
    "code": 404,
    "message": "Resource not found"
  }
}

Opaque Errors Mode

When LOCALAI_OPAQUE_ERRORS=true is set, all error responses return an empty body with only the HTTP status code. This is a security hardening option that prevents information leaks.

Per-Endpoint Error Scenarios

Chat Completions — POST /v1/chat/completions

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error
# Missing model field
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "hello"}]}'

See also: Text Generation

Completions — POST /v1/completions

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
500Backend inference failureInternal Server Error

Embeddings — POST /v1/embeddings

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

See also: Embeddings

Image Generation — POST /v1/images/generations

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

See also: Image Generation

Image Editing (Inpainting) — POST /v1/images/edits

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Missing image filemissing image file
400Missing mask filemissing mask file
500Storage preparation failurefailed to prepare storage

Audio Transcription — POST /v1/audio/transcriptions

StatusCauseExample Message
400Missing file field in form dataBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

See also: Audio to Text

Text to Speech — POST /v1/audio/speech, POST /tts

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

See also: Text to Audio

ElevenLabs TTS — POST /v1/text-to-speech/:voice-id

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

ElevenLabs Sound Generation — POST /v1/sound-generation

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

Reranking — POST /v1/rerank, POST /jina/v1/rerank

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
422top_n less than 1top_n - should be greater than or equal to 1
500Backend inference failureInternal Server Error

See also: Reranker

Anthropic Messages — POST /v1/messages

StatusCauseError TypeExample Message
400Missing model fieldinvalid_request_errormodel is required
400Model not in configurationinvalid_request_errormodel configuration not found
400Missing or invalid max_tokensinvalid_request_errormax_tokens is required and must be greater than 0
500Backend inference failureapi_errormodel inference failed: <details>
500Prediction failureapi_errorprediction failed: <details>
# Missing model field
curl http://localhost:8080/v1/messages \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "hello"}], "max_tokens": 100}'
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "model is required"
  }
}

Open Responses — POST /v1/responses

StatusCauseError TypeExample Message
400Missing model fieldinvalid_requestmodel is required
400Model not in configurationinvalid_requestmodel configuration not found
400Failed to parse inputinvalid_requestfailed to parse input: <details>
400background=true without store=trueinvalid_request_errorbackground=true requires store=true
404Previous response not foundnot_foundprevious response not found: <id>
500Backend inference failuremodel_errormodel inference failed: <details>
500Prediction failuremodel_errorprediction failed: <details>
500Tool execution failuremodel_errorfailed to execute tools: <details>
500MCP configuration errorserver_errorfailed to get MCP config: <details>
500No MCP servers availableserver_errorno working MCP servers found
# Missing model field
curl http://localhost:8080/v1/responses \
  -H "Content-Type: application/json" \
  -d '{"input": "hello"}'
{
  "error": {
    "type": "invalid_request",
    "message": "model is required",
    "code": "",
    "param": ""
  }
}

Open Responses — GET /v1/responses/:id

StatusCauseError TypeExample Message
400Missing response IDinvalid_request_errorresponse ID is required
404Response not foundnot_foundresponse not found: <id>

Open Responses Events — GET /v1/responses/:id/events

StatusCauseError TypeExample Message
400Missing response IDinvalid_request_errorresponse ID is required
400Response was not created with streaminvalid_request_errorcannot stream a response that was not created with stream=true
400Invalid starting_after valueinvalid_request_errorstarting_after must be an integer
404Response not foundnot_foundresponse not found: <id>
500Failed to retrieve eventsserver_errorfailed to get events: <details>

Object Detection — POST /v1/detection

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

See also: Object Detection

Video Generation — POST /v1/video/generations

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

Voice Activity Detection — POST /v1/audio/vad

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request
500Backend inference failureInternal Server Error

Tokenize — POST /v1/tokenize

StatusCauseExample Message
400Invalid or malformed request bodyBad Request
400Model not found in configurationBad Request

Models — GET /v1/models, GET /models

StatusCauseExample Message
500Failed to list modelsInternal Server Error

See also: Model Gallery

Handling Errors in Client Code

Python (OpenAI SDK)

from openai import OpenAI, APIError

client = OpenAI(base_url="http://localhost:8080/v1", api_key="your-key")

try:
    response = client.chat.completions.create(
        model="my-model",
        messages=[{"role": "user", "content": "hello"}],
    )
except APIError as e:
    print(f"Status: {e.status_code}, Message: {e.message}")

curl

# Check HTTP status code
response=$(curl -s -w "\n%{http_code}" http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "nonexistent", "messages": [{"role": "user", "content": "hi"}]}')

http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | head -1)

if [ "$http_code" -ne 200 ]; then
  echo "Error $http_code: $body"
fi
Environment VariableDescription
LOCALAI_API_KEYComma-separated list of valid API keys
LOCALAI_OPAQUE_ERRORSSet to true to hide error details (returns empty body with status code only)
LOCALAI_SUBTLEKEY_COMPARISONUse constant-time key comparison for timing-attack resistance