{
  "openapi": "3.0.0",
  "info": {
    "description": "OpenAPI specification for the entire Messari API",
    "title": "Messari API - Ai V2",
    "version": "1.0.0"
  },
  "servers": [
    {
      "description": "Messari API",
      "url": "https://api.messari.io"
    }
  ],
  "security": [],
  "paths": {
    "/ai/v2/chat/completions": {
      "post": {
        "description": "Processes a conversation and returns an AI-generated response with Messari's standard format. Consumes 5 credits per request.",
        "operationId": "postChatCompletionV2",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ChatCompletionResponse"
                    },
                    "error": {
                      "type": "string"
                    },
                    "metadata": {
                      "$ref": "#/components/schemas/ChatCompletionResponseMetadataV2"
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "type": "object"
                }
              }
            },
            "description": "Default response"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "data": {},
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "type": "object"
                }
              }
            },
            "description": "Bad Request"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "data": {},
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "type": "object"
                }
              }
            },
            "description": "Unauthorized"
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "data": {},
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "type": "object"
                }
              }
            },
            "description": "Internal Server Error"
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "summary": "Generate chat completions with Messari AI"
      }
    }
  },
  "components": {
    "schemas": {
      "ChatCompletionRequest": {
        "properties": {
          "allow_clarification_query": {
            "description": "Whether the AI can ask for clarification when the query is ambiguous",
            "type": "boolean",
            "default": true
          },
          "generate_related_questions": {
            "description": "Adds AI generated related questions to use as follow up questions",
            "format": "int64",
            "type": "integer",
            "default": 2
          },
          "inline_citations": {
            "description": "Adds inline citation document references in the payload metadata",
            "type": "boolean",
            "default": true
          },
          "messages": {
            "description": "Array of messages in the conversation history",
            "items": {
              "$ref": "#/components/schemas/ChatCompletionMessage"
            },
            "type": "array"
          },
          "response_format": {
            "description": "Text format for the response. Values accepted are 'markdown' and 'plaintext'.",
            "type": "string",
            "default": "markdown"
          },
          "stream": {
            "description": "Stream the response through the API",
            "type": "boolean",
            "default": false
          },
          "verbosity": {
            "description": "Controls the length and detail level of the AI-generated response. Values accepted are 'succinct', 'balanced', and 'verbose'.",
            "type": "string",
            "default": "balanced"
          }
        },
        "required": [
          "messages"
        ],
        "type": "object"
      },
      "ChatCompletionResponse": {
        "properties": {
          "messages": {
            "description": "Array of response messages from the assistant",
            "items": {
              "$ref": "#/components/schemas/ChatCompletionResponseMessage"
            },
            "type": "array"
          }
        },
        "required": [
          "messages"
        ],
        "type": "object"
      },
      "ChatCompletionResponseMetadataV2": {
        "properties": {
          "charts": {
            "description": "Chart data referenced in the response",
            "items": {
              "$ref": "#/components/schemas/ChartSource"
            },
            "type": "array"
          },
          "related_questions": {
            "description": "Follow-up questions related to the original query",
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "sources": {
            "description": "Sources used to construct the response content. If using inline citations, sources will include citationIds associated with the response citations.",
            "items": {
              "$ref": "#/components/schemas/StandardSource"
            },
            "type": "array"
          },
          "status": {
            "description": "Current status of the completion request",
            "type": "string"
          },
          "trace_id": {
            "description": "Unique identifier for tracing the request",
            "format": "byte",
            "type": "string"
          }
        },
        "required": [
          "status",
          "trace_id"
        ],
        "type": "object"
      },
      "StandardSource": {
        "type": "object",
        "description": "Schema for StandardSource",
        "properties": {},
        "additionalProperties": true
      },
      "ChatCompletionMessage": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "user",
              "assistant",
              "system"
            ],
            "default": "user",
            "description": "The role of the message author"
          },
          "content": {
            "type": "string",
            "default": "What is Solana?",
            "description": "The content of the message"
          }
        },
        "required": [
          "role",
          "content"
        ]
      },
      "ChartSource": {
        "type": "object",
        "description": "Schema for ChartSource",
        "properties": {},
        "additionalProperties": true
      },
      "ChatCompletionResponseMessage": {
        "type": "object",
        "description": "Schema for ChatCompletionResponseMessage",
        "properties": {},
        "additionalProperties": true
      }
    },
    "securitySchemes": {
      "apiKey": {
        "in": "header",
        "name": "X-Messari-API-Key",
        "type": "apiKey"
      }
    }
  }
}
