{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/berget-ai/json-schema/berget-ai-chat-completion-response-schema.json",
  "title": "ChatCompletionResponse",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/berget-ai-openapi.yml#/components/schemas/ChatCompletionResponse",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique identifier for the chat completion"
    },
    "object": {
      "type": "string",
      "enum": [
        "chat.completion"
      ],
      "description": "Object type, always \"chat.completion\""
    },
    "created": {
      "type": "number",
      "description": "Unix timestamp when the completion was created"
    },
    "model": {
      "type": "string",
      "description": "ID of the model used"
    },
    "system_fingerprint": {
      "description": "System fingerprint for reproducibility",
      "type": [
        "string",
        "null"
      ]
    },
    "service_tier": {
      "description": "Service tier used",
      "type": [
        "string",
        "null"
      ]
    },
    "choices": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "index": {
            "type": "number"
          },
          "message": {
            "type": "object",
            "properties": {
              "role": {
                "type": "string"
              },
              "content": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "reasoning_content": {
                "description": "Reasoning trace from the provider reasoning parser",
                "type": [
                  "string",
                  "null"
                ]
              },
              "reasoning": {
                "description": "Reasoning trace (alternate key used by some parsers)",
                "type": [
                  "string",
                  "null"
                ]
              },
              "tool_calls": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Unique identifier for the tool call"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "function"
                      ],
                      "description": "Tool call type, always \"function\""
                    },
                    "function": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Name of the function"
                        },
                        "arguments": {
                          "type": "string",
                          "description": "JSON-encoded arguments for the function"
                        }
                      },
                      "required": [
                        "name",
                        "arguments"
                      ],
                      "additionalProperties": false,
                      "description": "Function call details"
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "function"
                  ],
                  "additionalProperties": {}
                }
              },
              "function_call": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "arguments": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "arguments"
                ],
                "additionalProperties": false
              },
              "refusal": {
                "description": "Reason for refusal",
                "type": [
                  "string",
                  "null"
                ]
              },
              "annotations": {
                "description": "Annotations (e.g. web-search URL citations)",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "url_citation"
                      ],
                      "description": "Annotation type, always \"url_citation\""
                    },
                    "url_citation": {
                      "type": "object",
                      "properties": {
                        "end_index": {
                          "type": "number",
                          "description": "Index of the last character of the citation"
                        },
                        "start_index": {
                          "type": "number",
                          "description": "Index of the first character of the citation"
                        },
                        "url": {
                          "type": "string",
                          "description": "URL of the cited web resource"
                        },
                        "title": {
                          "type": "string",
                          "description": "Title of the cited web resource"
                        }
                      },
                      "required": [
                        "end_index",
                        "start_index",
                        "url",
                        "title"
                      ],
                      "additionalProperties": false,
                      "description": "URL citation details"
                    }
                  },
                  "required": [
                    "type",
                    "url_citation"
                  ],
                  "additionalProperties": {}
                }
              },
              "audio": {
                "description": "Audio output",
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Audio ID"
                  },
                  "data": {
                    "description": "Base64-encoded audio data",
                    "type": "string"
                  },
                  "expires_at": {
                    "description": "Unix timestamp when the audio expires",
                    "type": "number"
                  },
                  "transcript": {
                    "description": "Transcript of the audio",
                    "type": "string"
                  }
                },
                "required": [
                  "id"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "role",
              "content"
            ],
            "additionalProperties": {},
            "description": "Message object"
          },
          "finish_reason": {
            "description": "Reason the completion finished",
            "type": [
              "string",
              "null"
            ]
          },
          "logprobs": {
            "description": "Log probabilities",
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "content": {
                "description": "Content log probabilities",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string"
                    },
                    "bytes": {
                      "type": [
                        "array",
                        "null"
                      ],
                      "items": {
                        "type": "number"
                      }
                    },
                    "logprob": {
                      "type": "number"
                    },
                    "top_logprobs": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "token": {
                            "type": "string"
                          },
                          "bytes": {
                            "type": [
                              "array",
                              "null"
                            ],
                            "items": {
                              "type": "number"
                            }
                          },
                          "logprob": {
                            "type": "number"
                          }
                        },
                        "required": [
                          "token",
                          "bytes",
                          "logprob"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "token",
                    "bytes",
                    "logprob",
                    "top_logprobs"
                  ],
                  "additionalProperties": false
                }
              },
              "refusal": {
                "description": "Refusal log probabilities",
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string"
                    },
                    "bytes": {
                      "type": [
                        "array",
                        "null"
                      ],
                      "items": {
                        "type": "number"
                      }
                    },
                    "logprob": {
                      "type": "number"
                    },
                    "top_logprobs": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "token": {
                            "type": "string"
                          },
                          "bytes": {
                            "type": [
                              "array",
                              "null"
                            ],
                            "items": {
                              "type": "number"
                            }
                          },
                          "logprob": {
                            "type": "number"
                          }
                        },
                        "required": [
                          "token",
                          "bytes",
                          "logprob"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "token",
                    "bytes",
                    "logprob",
                    "top_logprobs"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "additionalProperties": false
          }
        },
        "required": [
          "index",
          "message",
          "finish_reason"
        ],
        "additionalProperties": {},
        "description": "Completion choice"
      },
      "description": "Array of completion choices"
    },
    "usage": {
      "description": "Token usage information. Optional because some vLLM/SGLang backends return HTTP 200 with a valid completion but no `usage` object; the pipeline skips token-derived side effects (metrics, CO₂, billing) when absent and forwards the response untouched.",
      "type": "object",
      "properties": {
        "prompt_tokens": {
          "type": "number",
          "description": "Number of prompt tokens"
        },
        "completion_tokens": {
          "type": "number",
          "description": "Number of completion tokens"
        },
        "total_tokens": {
          "type": "number",
          "description": "Total number of tokens"
        },
        "prompt_tokens_details": {
          "description": "Prompt token details",
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "audio_tokens": {
              "description": "Number of audio tokens",
              "type": "number"
            },
            "cached_tokens": {
              "description": "Number of cached tokens",
              "type": "number"
            },
            "cache_write_tokens": {
              "description": "Number of tokens written to the prompt cache",
              "type": "number"
            }
          },
          "additionalProperties": {}
        },
        "completion_tokens_details": {
          "description": "Completion token details",
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "audio_tokens": {
              "description": "Number of audio tokens",
              "type": "number"
            },
            "reasoning_tokens": {
              "description": "Number of reasoning tokens",
              "type": "number"
            },
            "accepted_prediction_tokens": {
              "description": "Number of accepted prediction tokens",
              "type": "number"
            },
            "rejected_prediction_tokens": {
              "description": "Number of rejected prediction tokens",
              "type": "number"
            }
          },
          "additionalProperties": {}
        }
      },
      "required": [
        "prompt_tokens",
        "completion_tokens",
        "total_tokens"
      ],
      "additionalProperties": {}
    }
  },
  "required": [
    "id",
    "object",
    "created",
    "model",
    "choices"
  ],
  "additionalProperties": {}
}