{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/modelslab-com/json-schema/modelslab-com-llm-response-schema.json",
  "title": "LLM response",
  "description": "OpenAI-compatible chat completion, or the shared error envelope. Streaming requests (`stream: true`) return text/event-stream instead of this object.",
  "x-generated": "2026-10-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/modelslab-com-api-openapi.json#/components/schemas/LlmResponse",
  "oneOf": [
    {
      "$ref": "#/$defs/LlmChatCompletion"
    },
    {
      "$ref": "#/$defs/GenerationError"
    }
  ],
  "$defs": {
    "GenerationError": {
      "type": "object",
      "title": "Generation error",
      "description": "Failure envelope. Note that generation endpoints return this on HTTP 200 — branch on `status` and `code`, not on the HTTP status.",
      "required": [
        "status",
        "message"
      ],
      "properties": {
        "status": {
          "type": "string",
          "const": "error"
        },
        "code": {
          "type": "string",
          "description": "Stable machine-readable error code. Branch on this.",
          "enum": [
            "validation_error",
            "invalid_api_key",
            "unauthenticated",
            "forbidden",
            "no_subscription",
            "insufficient_balance",
            "not_found",
            "rate_limited",
            "provider_error",
            "content_moderated",
            "upstream_unavailable",
            "server_error"
          ]
        },
        "message": {
          "type": "string",
          "description": "Human-readable explanation. Wording is not stable; do not parse it."
        },
        "errors": {
          "type": "object",
          "description": "Per-field validation detail. Present when code is \"validation_error\".",
          "additionalProperties": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "tips": {
          "type": "string",
          "description": "Optional remediation hint."
        }
      },
      "additionalProperties": true
    },
    "LlmChatCompletion": {
      "type": "object",
      "title": "Chat completion",
      "required": [
        "id",
        "choices"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "object": {
          "type": "string"
        },
        "created": {
          "type": "integer",
          "description": "Unix timestamp."
        },
        "model": {
          "type": "string"
        },
        "choices": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "index": {
                "type": "integer"
              },
              "finish_reason": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "message": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string"
                  },
                  "content": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "additionalProperties": true
              }
            },
            "additionalProperties": true
          }
        },
        "usage": {
          "type": "object",
          "properties": {
            "prompt_tokens": {
              "type": "integer"
            },
            "completion_tokens": {
              "type": "integer"
            },
            "total_tokens": {
              "type": "integer"
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    }
  }
}