{
  "asyncapi": "3.0.0",
  "info": {
    "title": "core/ai-platforms",
    "version": ""
  },
  "channels": {
    "systemEventsAiPlatform": {
      "address": "system-events.ai-platform",
      "messages": {
        "coreAiPlatformConversationsJobFinished": {
          "$ref": "#/components/messages/ai-platform.coreAiPlatformConversationsJobFinished"
        }
      }
    }
  },
  "operations": {
    "coreAiPlatformConversationsJobFinished": {
      "action": "send",
      "channel": {
        "$ref": "#/channels/systemEventsAiPlatform"
      },
      "messages": [
        {
          "$ref": "#/channels/systemEventsAiPlatform/messages/coreAiPlatformConversationsJobFinished"
        }
      ]
    }
  },
  "components": {
    "messages": {
      "ai-platform.coreAiPlatformConversationsJobFinished": {
        "name": "com.qlik.core.ai-platform.conversations-job.finished",
        "title": "Conversations finished",
        "payload": {
          "type": "object",
          "allOf": [
            {
              "$ref": "#/components/schemas/cloudEventsContextAttributes"
            },
            {
              "$ref": "#/components/schemas/cloudEventsQlikExtensionsAttributes"
            },
            {
              "type": "object",
              "properties": {
                "data": {
                  "type": "object",
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/conversationFinishedData"
                    }
                  ],
                  "description": "Conversations finished event specific data."
                },
                "type": {
                  "type": "string",
                  "default": "com.qlik.core.ai-platform.conversations-job.finished",
                  "description": "Unique identifier for the event type."
                }
              }
            }
          ]
        },
        "description": "This event will be published when conversations have been received from the LLM provider.",
        "x-qlik-stability": "stable",
        "x-qlik-visibility": "public",
        "x-qlik-deprecated": false
      }
    },
    "schemas": {
      "authclaims": {
        "type": "object",
        "properties": {
          "iss": {
            "type": "string",
            "description": "Issuer of the impersonating entity's identity."
          },
          "sub": {
            "type": "string",
            "description": "Subject of the impersonating entity."
          },
          "subType": {
            "type": "string",
            "description": "Type of the impersonating entity's subject."
          }
        },
        "description": "Details of the impersonating entity (the JWT \"act\" claim), present when the request was made on behalf of another principal."
      },
      "cloudEventsContextAttributes": {
        "type": "object",
        "required": [
          "id",
          "source",
          "specversion",
          "type"
        ],
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "A234-1234-1234"
            ],
            "minLength": 1,
            "description": "Identifies the event."
          },
          "time": {
            "type": "string",
            "format": "date-time",
            "examples": [
              "2023-01-01T12:00:00Z"
            ],
            "minLength": 1,
            "description": "Timestamp of when the occurrence happened. Must adhere to RFC 3339."
          },
          "type": {
            "type": "string",
            "examples": [
              "com.qlik.core.ai-platform.chat-completions-job.finished"
            ],
            "minLength": 1,
            "description": "Describes the type of event related to the originating occurrence."
          },
          "source": {
            "type": "string",
            "format": "uri-reference",
            "examples": [
              "com.qlik/ai-platform"
            ],
            "minLength": 1,
            "description": "Identifies the context in which an event happened."
          },
          "specversion": {
            "type": "string",
            "examples": [
              "1.0"
            ],
            "minLength": 1,
            "description": "The version of the CloudEvents specification which the event uses."
          },
          "datacontenttype": {
            "type": "string",
            "default": "application/json",
            "examples": [
              "application/json"
            ],
            "minLength": 1,
            "description": "Content type of the data value. Must adhere to RFC 2046 format."
          }
        },
        "description": "CloudEvents Specification JSON Schema"
      },
      "cloudEventsQlikExtensionsAttributes": {
        "type": "object",
        "required": [
          "tenantid"
        ],
        "properties": {
          "host": {
            "type": "string",
            "examples": [
              "ai-platform-llm-gateway-844db7d4c7-4glrb"
            ],
            "description": "Unique identifier for the host related to the event."
          },
          "reason": {
            "type": "string",
            "description": "Reason associated with the occurrence, when applicable."
          },
          "userid": {
            "type": "string",
            "examples": [
              "00000000-0000-0000-0000-000000000000"
            ],
            "description": "Unique identifier for the user related to the event."
          },
          "ownerid": {
            "type": "string",
            "examples": [
              "00000000-0000-0000-0000-000000000000"
            ],
            "description": "Unique identifier for the owner related to the event."
          },
          "spaceid": {
            "type": "string",
            "examples": [
              "00000000-0000-0000-0000-000000000000"
            ],
            "description": "Unique identifier for the space related to the event."
          },
          "authtype": {
            "type": "string",
            "examples": [
              "user",
              "app"
            ],
            "description": "Representing the type of principal that triggered the occurrence."
          },
          "clientid": {
            "type": "string",
            "examples": [
              "00000000-0000-0000-0000-000000000000"
            ],
            "description": "Unique identifier for the client related to the event."
          },
          "tenantid": {
            "type": "string",
            "examples": [
              "00000000-0000-0000-0000-000000000000"
            ],
            "description": "Unique identifier for the tenant related to the event."
          },
          "sessionid": {
            "type": "string",
            "examples": [
              "00000000-0000-0000-0000-000000000000"
            ],
            "description": "Unique identifier for the session related to the event."
          },
          "authclaims": {
            "type": "string",
            "examples": [
              "{\"sub\":\"1234567890\",\"subType\":\"user\",\"iss\":\"qlik.api.internal\"}"
            ],
            "description": "A JSON string representing the impersonating entity (the JWT \"act\" claim), if any."
          },
          "tracestate": {
            "type": "string",
            "examples": [
              "congo=t61rcWkgMzE"
            ],
            "description": "A comma-delimited list of key-value pairs."
          },
          "traceparent": {
            "type": "string",
            "examples": [
              "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
            ],
            "description": "Contains a version, trace ID, span ID, and trace options."
          },
          "toplevelresourceid": {
            "type": "string",
            "examples": [
              "id123"
            ],
            "description": "If the event originated from a sub resource the toplevelresourceid MUST contain\nthe id of the top level resource associated with the sub resource. If the event\noriginated from a top level resource it MUST NOT be defined.\n"
          }
        }
      },
      "conversationChoices": {
        "type": "object",
        "required": [
          "finishReason",
          "index"
        ],
        "properties": {
          "index": {
            "type": "integer",
            "example": 0,
            "description": "Position of a specific token within the generated output. Each token in the model's response has an associated index, starting from 0."
          },
          "message": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/components/schemas/conversationMessage"
              }
            ],
            "example": "",
            "description": "Individual communication within a conversation. This field (along with toolCalls/functionCall and any other generated content) is redacted and is never present on the published event; it is documented here only for historical/reference purposes."
          },
          "finishReason": {
            "type": "string",
            "example": "stop",
            "description": "Reason why a model's response generation process ended."
          }
        }
      },
      "conversationFinishedData": {
        "type": "object",
        "examples": [
          {
            "id": "converse-393592ed-ca78-4740-aa87-0ca97480706f",
            "cost": {
              "inputCost": "0.000300",
              "totalCost": "0.003300",
              "outputCost": "0.003000"
            },
            "model": "anthropic.claude-3-sonnet-20240229-v1:0",
            "usage": {
              "totalTokens": 238,
              "promptTokens": 16,
              "completionTokens": 222
            },
            "object": "conversation",
            "createdAt": 1728909071,
            "systemFingerprint": null,
            "performanceMetrics": {
              "ttft": "0.57",
              "endTime": "2024-07-10T15:48:30.416262",
              "startTime": "2024-07-10T15:48:21.598495",
              "totalTime": "8.82",
              "inferenceSpeed": "34.5"
            }
          }
        ],
        "required": [
          "id",
          "choices",
          "createdAt",
          "object"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "converse-393592ed-ca78-4740-aa87-0ca97480706f",
            "description": "A unique identifier for the completion."
          },
          "cost": {
            "allOf": [
              {
                "$ref": "#/components/schemas/cost"
              }
            ]
          },
          "_meta": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/components/schemas/metaClaims"
              }
            ],
            "description": "Internal metadata associated with the request."
          },
          "jobId": {
            "$ref": "#/components/schemas/rfsJobId"
          },
          "model": {
            "type": "string",
            "example": "anthropic.claude-3-sonnet-20240229-v1:0",
            "description": "The model used for conversation."
          },
          "usage": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/components/schemas/conversationUsage"
              }
            ],
            "example": {
              "totalTokens": 238,
              "promptTokens": 16,
              "completionTokens": 222,
              "cacheReadInputTokens": 43181,
              "cacheWriteInputTokens": 0
            }
          },
          "callId": {
            "type": "string",
            "description": "The call ID associated with this request."
          },
          "object": {
            "type": "string",
            "example": "conversation",
            "description": "The object type. Always set to conversation."
          },
          "choices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/conversationChoices"
            },
            "description": "A list of conversation choices."
          },
          "traceId": {
            "type": "string",
            "description": "The trace ID associated with this request."
          },
          "createdAt": {
            "type": "integer",
            "example": 1728909071,
            "description": "Unix timestamp of when the response was generated."
          },
          "systemFingerprint": {
            "type": [
              "string",
              "null"
            ],
            "description": "This fingerprint represents the backend configuration that the model runs with."
          },
          "performanceMetrics": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/components/schemas/performanceMetrics"
              }
            ],
            "example": {
              "ttft": "0.57",
              "endTime": "2024-07-10T15:48:30.416262",
              "startTime": "2024-07-10T15:48:21.598495",
              "totalTime": "8.82",
              "inferenceSpeed": "34.5"
            },
            "description": "Only present on streaming requests."
          }
        },
        "description": "Conversations finished operation specific data."
      },
      "conversationMessage": {
        "type": "object",
        "examples": [
          {
            "role": "assistant"
          }
        ],
        "required": [
          "role"
        ],
        "properties": {
          "role": {
            "enum": [
              "user",
              "assistant"
            ],
            "type": "string",
            "description": "The role of the message sender, either \"user\" or \"assistant\"."
          }
        }
      },
      "conversationUsage": {
        "allOf": [
          {
            "$ref": "#/components/schemas/usage"
          },
          {
            "type": "object",
            "properties": {
              "cacheReadInputTokens": {
                "type": "integer",
                "description": "Tokens read from the prompt cache."
              },
              "cacheWriteInputTokens": {
                "type": "integer",
                "description": "Tokens written to the prompt cache."
              }
            }
          }
        ],
        "description": "Token usage for a conversations response, including optional prompt-cache token counts."
      },
      "cost": {
        "type": "object",
        "properties": {
          "inputCost": {
            "type": "string",
            "example": "0.000300",
            "description": "Cost of prompt/input tokens in USD."
          },
          "totalCost": {
            "type": "string",
            "example": "0.003300",
            "description": "Sum of inputCost and outputCost."
          },
          "outputCost": {
            "type": "string",
            "example": "0.003000",
            "description": "Cost of completion/output tokens in USD."
          }
        },
        "description": "Estimated token cost in USD. When per-token pricing is configured for the model, the object contains input, output, and total cost values. When pricing is not configured for the model, this property is omitted entirely. Prompt-cache token pricing is not included."
      },
      "metaClaims": {
        "type": "object",
        "properties": {
          "act": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/components/schemas/authclaims"
              }
            ],
            "description": "Details of the impersonating entity."
          },
          "aud": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Audience(s) the JWT was issued for."
          },
          "iss": {
            "type": "string",
            "description": "Issuer of the principal's identity."
          },
          "sid": {
            "type": "string",
            "description": "ID of the session associated with this JWT, if any."
          },
          "sub": {
            "type": "string",
            "description": "Subject of the principal's identity."
          },
          "level": {
            "type": "string",
            "description": "Access level of the principal."
          },
          "userId": {
            "type": "string",
            "description": "Internal ID of the user making the request. Present when subType is \"user\"."
          },
          "subType": {
            "type": "string",
            "description": "Type of the principal's subject."
          },
          "clientId": {
            "type": "string",
            "description": "ID of the client making the request."
          },
          "tenantId": {
            "type": "string",
            "description": "Internal ID of the tenant to restrict access to."
          },
          "licenseId": {
            "type": "string",
            "description": "License ID associated with the principal."
          },
          "parentLicenseId": {
            "type": "string",
            "description": "Parent license ID associated with the principal."
          }
        },
        "description": "PII-safe subset of the JWT claims of the principal that triggered the event, propagated internally as request metadata."
      },
      "performanceMetrics": {
        "type": "object",
        "required": [
          "endTime",
          "inferenceSpeed",
          "startTime",
          "totalTime",
          "ttft"
        ],
        "properties": {
          "ttft": {
            "type": [
              "string",
              "null"
            ],
            "example": "0.57",
            "description": "Time to first token (TTFT) in seconds. Null when timing data is unavailable."
          },
          "endTime": {
            "type": "string",
            "example": "2024-07-10T15:48:30.416262",
            "description": "Finishing time of the task."
          },
          "startTime": {
            "type": "string",
            "example": "2024-07-10T15:48:21.598495",
            "description": "Starting time of the task."
          },
          "totalTime": {
            "type": [
              "string",
              "null"
            ],
            "example": "8.82",
            "description": "Total time of the task in seconds. Null when timing data is unavailable."
          },
          "inferenceSpeed": {
            "type": [
              "string",
              "null"
            ],
            "example": "34.5",
            "description": "Tokens per second generated by the model in response to the input. Null when timing data is unavailable."
          }
        }
      },
      "rfsJobId": {
        "type": "string",
        "example": "7d6d4e39-6aa9-4b77-b6fc-2b9bd62a3e5d",
        "description": "Optional RFS job ID forwarded from the X-Qlik-RFS-JobID request header to correlate triggered and finished events."
      },
      "usage": {
        "type": "object",
        "required": [
          "promptTokens",
          "completionTokens",
          "totalTokens"
        ],
        "properties": {
          "totalTokens": {
            "type": "integer",
            "example": 238,
            "description": "Addition of the completion and prompt tokens."
          },
          "promptTokens": {
            "type": "integer",
            "example": 16,
            "description": "Tokens explicitly provided as input to the model."
          },
          "completionTokens": {
            "type": "integer",
            "example": 222,
            "description": "Tokens generated by the model in response to the input."
          }
        }
      }
    }
  }
}