{
  "components": {
    "schemas": {
      "CreateServerVisitorTokenResponse": {
        "additionalProperties": false,
        "properties": {
          "data": {
            "additionalProperties": false,
            "properties": {
              "expires_at": {
                "format": "date-time",
                "type": "string"
              },
              "token_type": {
                "const": "Bearer",
                "type": "string"
              },
              "visitor_token": {
                "maxLength": 117,
                "minLength": 86,
                "pattern": "^vst_[A-Za-z0-9-]{1,32}_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}_[A-Za-z0-9_-]{43}$",
                "type": "string"
              }
            },
            "required": ["visitor_token", "token_type", "expires_at"],
            "type": "object"
          }
        },
        "required": ["data"],
        "type": "object"
      },
      "ServerErrorEnvelope": {
        "additionalProperties": false,
        "properties": {
          "error": {
            "additionalProperties": false,
            "properties": {
              "code": {
                "anyOf": [
                  {
                    "const": "invalid_request",
                    "type": "string"
                  },
                  {
                    "const": "invalid_credentials",
                    "type": "string"
                  },
                  {
                    "const": "idempotency_conflict",
                    "type": "string"
                  },
                  {
                    "const": "rate_limited",
                    "type": "string"
                  },
                  {
                    "const": "payload_too_large",
                    "type": "string"
                  },
                  {
                    "const": "unsupported_media_type",
                    "type": "string"
                  },
                  {
                    "const": "service_unavailable",
                    "type": "string"
                  }
                ]
              },
              "message": {
                "maxLength": 256,
                "minLength": 1,
                "type": "string"
              }
            },
            "required": ["code", "message"],
            "type": "object"
          }
        },
        "required": ["error"],
        "type": "object"
      },
      "TraceId": {
        "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
        "type": "string"
      }
    },
    "securitySchemes": {
      "serverBearer": {
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "info": {
    "title": "AI 客服 Server API",
    "version": "1.0.0"
  },
  "openapi": "3.1.0",
  "paths": {
    "/server/v1/visitor-tokens": {
      "post": {
        "operationId": "createServerVisitorToken",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "maxLength": 128,
              "minLength": 16,
              "pattern": "^[A-Za-z0-9._:-]+$",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "additionalProperties": false,
                "properties": {
                  "app_id": {
                    "pattern": "^app_[0-9A-HJKMNP-TV-Z]{26}$",
                    "type": "string"
                  },
                  "expires_in": {
                    "default": 300,
                    "maximum": 900,
                    "minimum": 60,
                    "type": "integer"
                  },
                  "external_user_ref": {
                    "maxLength": 256,
                    "minLength": 1,
                    "type": "string"
                  }
                },
                "required": ["app_id", "external_user_ref"],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": false,
                  "properties": {
                    "data": {
                      "additionalProperties": false,
                      "properties": {
                        "expires_at": {
                          "format": "date-time",
                          "type": "string"
                        },
                        "token_type": {
                          "const": "Bearer",
                          "type": "string"
                        },
                        "visitor_token": {
                          "maxLength": 117,
                          "minLength": 86,
                          "pattern": "^vst_[A-Za-z0-9-]{1,32}_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}_[A-Za-z0-9_-]{43}$",
                          "type": "string"
                        }
                      },
                      "required": ["visitor_token", "token_type", "expires_at"],
                      "type": "object"
                    }
                  },
                  "required": ["data"],
                  "type": "object"
                }
              }
            },
            "description": "成功",
            "headers": {
              "Cache-Control": {
                "required": true,
                "schema": {
                  "const": "no-store",
                  "type": "string"
                }
              },
              "Referrer-Policy": {
                "required": true,
                "schema": {
                  "const": "no-referrer",
                  "type": "string"
                }
              },
              "X-Content-Type-Options": {
                "required": true,
                "schema": {
                  "const": "nosniff",
                  "type": "string"
                }
              },
              "X-Trace-Id": {
                "required": true,
                "schema": {
                  "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": false,
                  "properties": {
                    "error": {
                      "additionalProperties": false,
                      "properties": {
                        "code": {
                          "anyOf": [
                            {
                              "const": "invalid_request",
                              "type": "string"
                            },
                            {
                              "const": "invalid_credentials",
                              "type": "string"
                            },
                            {
                              "const": "idempotency_conflict",
                              "type": "string"
                            },
                            {
                              "const": "rate_limited",
                              "type": "string"
                            },
                            {
                              "const": "payload_too_large",
                              "type": "string"
                            },
                            {
                              "const": "unsupported_media_type",
                              "type": "string"
                            },
                            {
                              "const": "service_unavailable",
                              "type": "string"
                            }
                          ]
                        },
                        "message": {
                          "maxLength": 256,
                          "minLength": 1,
                          "type": "string"
                        }
                      },
                      "required": ["code", "message"],
                      "type": "object"
                    }
                  },
                  "required": ["error"],
                  "type": "object"
                }
              }
            },
            "description": "请求失败",
            "headers": {
              "Cache-Control": {
                "required": true,
                "schema": {
                  "const": "no-store",
                  "type": "string"
                }
              },
              "Referrer-Policy": {
                "required": true,
                "schema": {
                  "const": "no-referrer",
                  "type": "string"
                }
              },
              "X-Content-Type-Options": {
                "required": true,
                "schema": {
                  "const": "nosniff",
                  "type": "string"
                }
              },
              "X-Trace-Id": {
                "required": true,
                "schema": {
                  "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": false,
                  "properties": {
                    "error": {
                      "additionalProperties": false,
                      "properties": {
                        "code": {
                          "anyOf": [
                            {
                              "const": "invalid_request",
                              "type": "string"
                            },
                            {
                              "const": "invalid_credentials",
                              "type": "string"
                            },
                            {
                              "const": "idempotency_conflict",
                              "type": "string"
                            },
                            {
                              "const": "rate_limited",
                              "type": "string"
                            },
                            {
                              "const": "payload_too_large",
                              "type": "string"
                            },
                            {
                              "const": "unsupported_media_type",
                              "type": "string"
                            },
                            {
                              "const": "service_unavailable",
                              "type": "string"
                            }
                          ]
                        },
                        "message": {
                          "maxLength": 256,
                          "minLength": 1,
                          "type": "string"
                        }
                      },
                      "required": ["code", "message"],
                      "type": "object"
                    }
                  },
                  "required": ["error"],
                  "type": "object"
                }
              }
            },
            "description": "请求失败",
            "headers": {
              "Cache-Control": {
                "required": true,
                "schema": {
                  "const": "no-store",
                  "type": "string"
                }
              },
              "Referrer-Policy": {
                "required": true,
                "schema": {
                  "const": "no-referrer",
                  "type": "string"
                }
              },
              "X-Content-Type-Options": {
                "required": true,
                "schema": {
                  "const": "nosniff",
                  "type": "string"
                }
              },
              "X-Trace-Id": {
                "required": true,
                "schema": {
                  "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": false,
                  "properties": {
                    "error": {
                      "additionalProperties": false,
                      "properties": {
                        "code": {
                          "anyOf": [
                            {
                              "const": "invalid_request",
                              "type": "string"
                            },
                            {
                              "const": "invalid_credentials",
                              "type": "string"
                            },
                            {
                              "const": "idempotency_conflict",
                              "type": "string"
                            },
                            {
                              "const": "rate_limited",
                              "type": "string"
                            },
                            {
                              "const": "payload_too_large",
                              "type": "string"
                            },
                            {
                              "const": "unsupported_media_type",
                              "type": "string"
                            },
                            {
                              "const": "service_unavailable",
                              "type": "string"
                            }
                          ]
                        },
                        "message": {
                          "maxLength": 256,
                          "minLength": 1,
                          "type": "string"
                        }
                      },
                      "required": ["code", "message"],
                      "type": "object"
                    }
                  },
                  "required": ["error"],
                  "type": "object"
                }
              }
            },
            "description": "请求失败",
            "headers": {
              "Cache-Control": {
                "required": true,
                "schema": {
                  "const": "no-store",
                  "type": "string"
                }
              },
              "Referrer-Policy": {
                "required": true,
                "schema": {
                  "const": "no-referrer",
                  "type": "string"
                }
              },
              "X-Content-Type-Options": {
                "required": true,
                "schema": {
                  "const": "nosniff",
                  "type": "string"
                }
              },
              "X-Trace-Id": {
                "required": true,
                "schema": {
                  "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
                  "type": "string"
                }
              }
            }
          },
          "413": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": false,
                  "properties": {
                    "error": {
                      "additionalProperties": false,
                      "properties": {
                        "code": {
                          "anyOf": [
                            {
                              "const": "invalid_request",
                              "type": "string"
                            },
                            {
                              "const": "invalid_credentials",
                              "type": "string"
                            },
                            {
                              "const": "idempotency_conflict",
                              "type": "string"
                            },
                            {
                              "const": "rate_limited",
                              "type": "string"
                            },
                            {
                              "const": "payload_too_large",
                              "type": "string"
                            },
                            {
                              "const": "unsupported_media_type",
                              "type": "string"
                            },
                            {
                              "const": "service_unavailable",
                              "type": "string"
                            }
                          ]
                        },
                        "message": {
                          "maxLength": 256,
                          "minLength": 1,
                          "type": "string"
                        }
                      },
                      "required": ["code", "message"],
                      "type": "object"
                    }
                  },
                  "required": ["error"],
                  "type": "object"
                }
              }
            },
            "description": "请求失败",
            "headers": {
              "Cache-Control": {
                "required": true,
                "schema": {
                  "const": "no-store",
                  "type": "string"
                }
              },
              "Referrer-Policy": {
                "required": true,
                "schema": {
                  "const": "no-referrer",
                  "type": "string"
                }
              },
              "X-Content-Type-Options": {
                "required": true,
                "schema": {
                  "const": "nosniff",
                  "type": "string"
                }
              },
              "X-Trace-Id": {
                "required": true,
                "schema": {
                  "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
                  "type": "string"
                }
              }
            }
          },
          "415": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": false,
                  "properties": {
                    "error": {
                      "additionalProperties": false,
                      "properties": {
                        "code": {
                          "anyOf": [
                            {
                              "const": "invalid_request",
                              "type": "string"
                            },
                            {
                              "const": "invalid_credentials",
                              "type": "string"
                            },
                            {
                              "const": "idempotency_conflict",
                              "type": "string"
                            },
                            {
                              "const": "rate_limited",
                              "type": "string"
                            },
                            {
                              "const": "payload_too_large",
                              "type": "string"
                            },
                            {
                              "const": "unsupported_media_type",
                              "type": "string"
                            },
                            {
                              "const": "service_unavailable",
                              "type": "string"
                            }
                          ]
                        },
                        "message": {
                          "maxLength": 256,
                          "minLength": 1,
                          "type": "string"
                        }
                      },
                      "required": ["code", "message"],
                      "type": "object"
                    }
                  },
                  "required": ["error"],
                  "type": "object"
                }
              }
            },
            "description": "请求失败",
            "headers": {
              "Cache-Control": {
                "required": true,
                "schema": {
                  "const": "no-store",
                  "type": "string"
                }
              },
              "Referrer-Policy": {
                "required": true,
                "schema": {
                  "const": "no-referrer",
                  "type": "string"
                }
              },
              "X-Content-Type-Options": {
                "required": true,
                "schema": {
                  "const": "nosniff",
                  "type": "string"
                }
              },
              "X-Trace-Id": {
                "required": true,
                "schema": {
                  "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": false,
                  "properties": {
                    "error": {
                      "additionalProperties": false,
                      "properties": {
                        "code": {
                          "anyOf": [
                            {
                              "const": "invalid_request",
                              "type": "string"
                            },
                            {
                              "const": "invalid_credentials",
                              "type": "string"
                            },
                            {
                              "const": "idempotency_conflict",
                              "type": "string"
                            },
                            {
                              "const": "rate_limited",
                              "type": "string"
                            },
                            {
                              "const": "payload_too_large",
                              "type": "string"
                            },
                            {
                              "const": "unsupported_media_type",
                              "type": "string"
                            },
                            {
                              "const": "service_unavailable",
                              "type": "string"
                            }
                          ]
                        },
                        "message": {
                          "maxLength": 256,
                          "minLength": 1,
                          "type": "string"
                        }
                      },
                      "required": ["code", "message"],
                      "type": "object"
                    }
                  },
                  "required": ["error"],
                  "type": "object"
                }
              }
            },
            "description": "请求失败",
            "headers": {
              "Cache-Control": {
                "required": true,
                "schema": {
                  "const": "no-store",
                  "type": "string"
                }
              },
              "Referrer-Policy": {
                "required": true,
                "schema": {
                  "const": "no-referrer",
                  "type": "string"
                }
              },
              "Retry-After": {
                "required": true,
                "schema": {
                  "pattern": "^[0-9]+$",
                  "type": "string"
                }
              },
              "X-Content-Type-Options": {
                "required": true,
                "schema": {
                  "const": "nosniff",
                  "type": "string"
                }
              },
              "X-Trace-Id": {
                "required": true,
                "schema": {
                  "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": false,
                  "properties": {
                    "error": {
                      "additionalProperties": false,
                      "properties": {
                        "code": {
                          "anyOf": [
                            {
                              "const": "invalid_request",
                              "type": "string"
                            },
                            {
                              "const": "invalid_credentials",
                              "type": "string"
                            },
                            {
                              "const": "idempotency_conflict",
                              "type": "string"
                            },
                            {
                              "const": "rate_limited",
                              "type": "string"
                            },
                            {
                              "const": "payload_too_large",
                              "type": "string"
                            },
                            {
                              "const": "unsupported_media_type",
                              "type": "string"
                            },
                            {
                              "const": "service_unavailable",
                              "type": "string"
                            }
                          ]
                        },
                        "message": {
                          "maxLength": 256,
                          "minLength": 1,
                          "type": "string"
                        }
                      },
                      "required": ["code", "message"],
                      "type": "object"
                    }
                  },
                  "required": ["error"],
                  "type": "object"
                }
              }
            },
            "description": "请求失败",
            "headers": {
              "Cache-Control": {
                "required": true,
                "schema": {
                  "const": "no-store",
                  "type": "string"
                }
              },
              "Referrer-Policy": {
                "required": true,
                "schema": {
                  "const": "no-referrer",
                  "type": "string"
                }
              },
              "X-Content-Type-Options": {
                "required": true,
                "schema": {
                  "const": "nosniff",
                  "type": "string"
                }
              },
              "X-Trace-Id": {
                "required": true,
                "schema": {
                  "pattern": "^tr_[0-9A-HJKMNP-TV-Z]{26}$",
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "serverBearer": []
          }
        ]
      }
    }
  }
}
