{
  "openapi": "3.1.0",
  "info": {
    "title": "API do Packia",
    "version": "1.2.0",
    "description": "API REST para usar as IAs do Packia (chat, imagem, vídeo, narração, música e planilhas) a partir do seu sistema. Consome os créditos do plano da conta dona da chave. Documentação completa em https://packia.com.br/docs/api",
    "contact": {
      "name": "Suporte Packia",
      "url": "https://wa.me/5511948338029"
    },
    "termsOfService": "https://packia.com.br/termos"
  },
  "servers": [
    {
      "url": "https://packia.com.br/api/v1"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "tags": [
    {
      "name": "Conta"
    },
    {
      "name": "Texto"
    },
    {
      "name": "Imagem e áudio"
    },
    {
      "name": "Vídeo e música"
    },
    {
      "name": "Biblioteca"
    }
  ],
  "paths": {
    "/account": {
      "get": {
        "tags": [
          "Conta"
        ],
        "operationId": "getAccount",
        "summary": "Consultar conta",
        "description": "Plano e saldo de créditos da conta dona da chave.",
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/models": {
      "get": {
        "tags": [
          "Conta"
        ],
        "operationId": "listModels",
        "summary": "Listar modelos",
        "description": "Modelos de chat, imagem, vídeo e música, com o que cada um aceita.",
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "chat",
                "image",
                "video",
                "music"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "object",
                    "data"
                  ],
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Model"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/chat": {
      "post": {
        "tags": [
          "Texto"
        ],
        "operationId": "createChat",
        "summary": "Conversar com IA",
        "description": "Envia o histórico e recebe a resposta. Com stream: true, responde text/event-stream com eventos delta, done e error.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resposta completa, ou fluxo SSE quando stream é true.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "event: delta | done | error, data: JSON"
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Recurso fora do plano ou assinatura expirada (plan_required, subscription_expired).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Falha do provedor de IA (provider_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "tags": [
          "Texto"
        ],
        "operationId": "createChatCompletion",
        "summary": "Chat compatível com OpenAI",
        "description": "Recebe e devolve o formato de chat completions da OpenAI, para usar os SDKs oficiais com base_url apontando para a API do Packia. A conversa não fica salva no histórico. Com stream: true, responde text/event-stream com chunks chat.completion.chunk e termina com data: [DONE].",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "enum": [
                      "gpt-5",
                      "claude-sonnet",
                      "gemini-pro",
                      "llama-4",
                      "deepseek-v3",
                      "grok-4",
                      "mistral-large",
                      "perplexity-sonar",
                      "copilot",
                      "qwen",
                      "command-r-plus",
                      "poe",
                      "gemini-3-flash"
                    ],
                    "default": "gpt-5"
                  },
                  "messages": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "type": "object",
                      "required": [
                        "role"
                      ],
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": [
                            "system",
                            "developer",
                            "user",
                            "assistant"
                          ]
                        },
                        "content": {
                          "oneOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "text"
                                  },
                                  "text": {
                                    "type": "string"
                                  }
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  },
                  "stream": {
                    "type": "boolean",
                    "default": false
                  },
                  "stream_options": {
                    "type": "object",
                    "properties": {
                      "include_usage": {
                        "type": "boolean"
                      }
                    }
                  },
                  "n": {
                    "type": "integer",
                    "const": 1
                  }
                },
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Objeto chat.completion, ou fluxo SSE quando stream é true.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "object": {
                      "const": "chat.completion"
                    },
                    "created": {
                      "type": "integer"
                    },
                    "model": {
                      "type": "string"
                    },
                    "choices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "index": {
                            "type": "integer"
                          },
                          "message": {
                            "type": "object",
                            "properties": {
                              "role": {
                                "const": "assistant"
                              },
                              "content": {
                                "type": "string"
                              },
                              "refusal": {
                                "type": "null"
                              }
                            }
                          },
                          "logprobs": {
                            "type": "null"
                          },
                          "finish_reason": {
                            "const": "stop"
                          }
                        }
                      }
                    },
                    "usage": {
                      "type": "object",
                      "description": "Sempre zerado: o consumo é cobrado em créditos.",
                      "properties": {
                        "prompt_tokens": {
                          "type": "integer"
                        },
                        "completion_tokens": {
                          "type": "integer"
                        },
                        "total_tokens": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "data: chat.completion.chunk em JSON, terminando com data: [DONE]"
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Recurso fora do plano ou assinatura expirada (plan_required, subscription_expired).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Falha do provedor de IA (provider_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/prompts/improve": {
      "post": {
        "tags": [
          "Texto"
        ],
        "operationId": "improvePrompt",
        "summary": "Melhorar prompt",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 5000
                  },
                  "context": {
                    "type": "string",
                    "enum": [
                      "general",
                      "image",
                      "video",
                      "music",
                      "avatar",
                      "chat"
                    ],
                    "default": "general"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "prompt"
                    },
                    "context": {
                      "type": "string"
                    },
                    "prompt": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Créditos insuficientes (insufficient_credits).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Recurso fora do plano ou assinatura expirada (plan_required, subscription_expired).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Requisição com a mesma Idempotency-Key em andamento (idempotency_in_progress).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Idempotency-Key reutilizada com outro corpo (idempotency_key_reused).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Falha do provedor de IA (provider_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/images": {
      "post": {
        "tags": [
          "Imagem e áudio"
        ],
        "operationId": "createImage",
        "summary": "Gerar imagem",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 5000
                  },
                  "model": {
                    "type": "string",
                    "enum": [
                      "gpt-image-2.5-flare",
                      "gpt-image-2.5-sunburst",
                      "gpt-image-2",
                      "nano-banana-2",
                      "grok-imagine",
                      "midjourney",
                      "dalle3",
                      "leonardo",
                      "flux",
                      "ideogram",
                      "stable-diffusion",
                      "firefly",
                      "playground",
                      "nano-banana-pro",
                      "seedream-5",
                      "qwen-image-3",
                      "ideogram-character"
                    ],
                    "default": "gpt-image-2.5-flare"
                  },
                  "aspect_ratio": {
                    "type": "string",
                    "enum": [
                      "1:1",
                      "16:9",
                      "9:16",
                      "4:3",
                      "3:4",
                      "21:9"
                    ],
                    "default": "1:1"
                  },
                  "quality": {
                    "type": "string",
                    "enum": [
                      "low",
                      "medium",
                      "high",
                      "xhigh",
                      "max"
                    ],
                    "description": "Modelos GPT Image."
                  },
                  "resolution": {
                    "type": "string",
                    "enum": [
                      "0.5K",
                      "1K",
                      "2K",
                      "4K",
                      "1k",
                      "2k"
                    ],
                    "description": "Nano Banana (0.5K a 4K) e Grok Imagine (1k, 2k)."
                  },
                  "output_format": {
                    "type": "string",
                    "enum": [
                      "png",
                      "jpeg",
                      "webp"
                    ]
                  },
                  "rendering_speed": {
                    "type": "string",
                    "enum": [
                      "TURBO",
                      "BALANCED",
                      "QUALITY"
                    ],
                    "description": "Modelos Ideogram."
                  },
                  "n": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 4,
                    "default": 1
                  },
                  "enhance_prompt": {
                    "type": "boolean",
                    "description": "Modelos Flux."
                  },
                  "reference_images": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 14,
                    "items": {
                      "type": "string",
                      "description": "URL https ou data URL base64."
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "image.generation"
                    },
                    "model": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "url": {
                            "type": "string",
                            "format": "uri"
                          },
                          "b64_json": {
                            "type": "string"
                          },
                          "mime_type": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Créditos insuficientes (insufficient_credits).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Recurso fora do plano ou assinatura expirada (plan_required, subscription_expired).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Requisição com a mesma Idempotency-Key em andamento (idempotency_in_progress).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Idempotency-Key reutilizada com outro corpo (idempotency_key_reused).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Falha do provedor de IA (provider_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/voices": {
      "get": {
        "tags": [
          "Imagem e áudio"
        ],
        "operationId": "listVoices",
        "summary": "Listar vozes",
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "object": {
                            "const": "voice"
                          },
                          "name": {
                            "type": "string"
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/audio/speech": {
      "post": {
        "tags": [
          "Imagem e áudio"
        ],
        "operationId": "createSpeech",
        "summary": "Gerar narração",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "maxLength": 5000
                  },
                  "voice_id": {
                    "type": "string"
                  },
                  "speed": {
                    "type": "number",
                    "minimum": 0.7,
                    "maximum": 1.2,
                    "default": 1
                  },
                  "stability": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1,
                    "default": 0.5
                  },
                  "similarity": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1,
                    "default": 0.75
                  },
                  "style": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1,
                    "default": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "audio.speech"
                    },
                    "audio_url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Créditos insuficientes (insufficient_credits).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Recurso fora do plano ou assinatura expirada (plan_required, subscription_expired).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Requisição com a mesma Idempotency-Key em andamento (idempotency_in_progress).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Idempotency-Key reutilizada com outro corpo (idempotency_key_reused).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Falha do provedor de IA (provider_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/spreadsheets": {
      "post": {
        "tags": [
          "Imagem e áudio"
        ],
        "operationId": "createSpreadsheet",
        "summary": "Gerar planilha",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 6000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "spreadsheet"
                    },
                    "file_name": {
                      "type": "string"
                    },
                    "mime_type": {
                      "type": "string"
                    },
                    "file_base64": {
                      "type": "string",
                      "contentEncoding": "base64"
                    },
                    "sheets": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "rows": {
                            "type": "integer"
                          },
                          "columns": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Créditos insuficientes (insufficient_credits).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Recurso fora do plano ou assinatura expirada (plan_required, subscription_expired).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Requisição com a mesma Idempotency-Key em andamento (idempotency_in_progress).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Idempotency-Key reutilizada com outro corpo (idempotency_key_reused).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Falha do provedor de IA (provider_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/videos": {
      "post": {
        "tags": [
          "Vídeo e música"
        ],
        "operationId": "createVideo",
        "summary": "Gerar vídeo",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 2500
                  },
                  "model": {
                    "type": "string",
                    "enum": [
                      "seedance",
                      "seedance2",
                      "seedance25",
                      "kling",
                      "kling26",
                      "klingo3",
                      "veo",
                      "wan",
                      "minimax",
                      "pixverse",
                      "ltx",
                      "happyhorse",
                      "pika",
                      "grok"
                    ],
                    "default": "seedance"
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "text",
                      "image",
                      "reference"
                    ]
                  },
                  "aspect_ratio": {
                    "type": "string",
                    "enum": [
                      "16:9",
                      "9:16",
                      "1:1"
                    ],
                    "default": "16:9"
                  },
                  "duration": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 30,
                    "description": "Dentro do que o modelo aceita (GET /models?type=video)."
                  },
                  "resolution": {
                    "type": "string",
                    "enum": [
                      "480p",
                      "540p",
                      "720p",
                      "1080p",
                      "1440p",
                      "2160p",
                      "4k"
                    ]
                  },
                  "quality": {
                    "type": "string",
                    "enum": [
                      "standard",
                      "fast"
                    ]
                  },
                  "generate_audio": {
                    "type": "boolean"
                  },
                  "negative_prompt": {
                    "type": "string",
                    "maxLength": 2500
                  },
                  "seed": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "style": {
                    "type": "string",
                    "enum": [
                      "anime",
                      "3d_animation",
                      "clay",
                      "comic",
                      "cyberpunk"
                    ]
                  },
                  "optimize_prompt": {
                    "type": "boolean"
                  },
                  "fps": {
                    "type": "integer",
                    "enum": [
                      24,
                      25,
                      48,
                      50
                    ]
                  },
                  "image": {
                    "type": "string",
                    "description": "Modo image. URL https ou data URL base64."
                  },
                  "end_image": {
                    "type": "string",
                    "description": "Modo image. URL https ou data URL base64."
                  },
                  "reference_images": {
                    "type": "array",
                    "maxItems": 30,
                    "items": {
                      "type": "string"
                    }
                  },
                  "reference_videos": {
                    "type": "array",
                    "maxItems": 10,
                    "items": {
                      "type": "string"
                    }
                  },
                  "reference_audios": {
                    "type": "array",
                    "maxItems": 10,
                    "items": {
                      "type": "string"
                    }
                  },
                  "webhook_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL https pública."
                  }
                }
              }
            }
          }
        },
        "callbacks": {
          "jobFinished": {
            "{$request.body#/webhook_url}": {
              "post": {
                "requestBody": {
                  "required": true,
                  "content": {
                    "application/json": {
                      "schema": {
                        "$ref": "#/components/schemas/WebhookEvent"
                      }
                    }
                  }
                },
                "responses": {
                  "200": {
                    "description": "Recebido"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job criado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Créditos insuficientes (insufficient_credits).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Recurso fora do plano ou assinatura expirada (plan_required, subscription_expired).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Requisição com a mesma Idempotency-Key em andamento (idempotency_in_progress).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Idempotency-Key reutilizada com outro corpo (idempotency_key_reused).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Falha do provedor de IA (provider_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/music": {
      "post": {
        "tags": [
          "Vídeo e música"
        ],
        "operationId": "createMusic",
        "summary": "Gerar música",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 5000
                  },
                  "instrumental": {
                    "type": "boolean",
                    "default": false
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "style": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "model": {
                    "type": "string",
                    "enum": [
                      "V6",
                      "V6_WILD",
                      "V6_MINI",
                      "V5_5",
                      "V5",
                      "V4_5PLUS",
                      "V4_5ALL",
                      "V4_5",
                      "V4"
                    ],
                    "default": "V6"
                  },
                  "negative_tags": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "vocal_gender": {
                    "type": "string",
                    "enum": [
                      "m",
                      "f"
                    ]
                  },
                  "style_weight": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "weirdness": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "audio_weight": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "webhook_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL https pública."
                  }
                }
              }
            }
          }
        },
        "callbacks": {
          "jobFinished": {
            "{$request.body#/webhook_url}": {
              "post": {
                "requestBody": {
                  "required": true,
                  "content": {
                    "application/json": {
                      "schema": {
                        "$ref": "#/components/schemas/WebhookEvent"
                      }
                    }
                  }
                },
                "responses": {
                  "200": {
                    "description": "Recebido"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job criado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Créditos insuficientes (insufficient_credits).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Recurso fora do plano ou assinatura expirada (plan_required, subscription_expired).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Requisição com a mesma Idempotency-Key em andamento (idempotency_in_progress).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Idempotency-Key reutilizada com outro corpo (idempotency_key_reused).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Falha do provedor de IA (provider_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/jobs/{id}": {
      "get": {
        "tags": [
          "Vídeo e música"
        ],
        "operationId": "getJob",
        "summary": "Consultar job",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^job_"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Job não encontrado (not_found).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/creations": {
      "get": {
        "tags": [
          "Biblioteca"
        ],
        "operationId": "listCreations",
        "summary": "Listar criações",
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "image",
                "video",
                "audio",
                "doc"
              ]
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 60,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Creation"
                      }
                    },
                    "page": {
                      "type": "integer"
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Requisição inválida (invalid_request).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida ou revogada (invalid_api_key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (rate_limited, daily_limit_reached).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (internal_error).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pk_live_...",
        "description": "Chave gerada em Perfil, aba API."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Valor único (ex.: UUID). Repetir a mesma chave em até 24h devolve a resposta original sem cobrar de novo.",
        "schema": {
          "type": "string",
          "maxLength": 255
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "request_id"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_request",
                  "invalid_api_key",
                  "insufficient_credits",
                  "plan_required",
                  "subscription_expired",
                  "forbidden",
                  "not_found",
                  "conflict",
                  "payload_too_large",
                  "idempotency_in_progress",
                  "idempotency_key_reused",
                  "rate_limited",
                  "daily_limit_reached",
                  "internal_error",
                  "provider_error"
                ]
              },
              "message": {
                "type": "string"
              },
              "param": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            }
          }
        }
      },
      "Account": {
        "type": "object",
        "properties": {
          "object": {
            "const": "account"
          },
          "plan": {
            "type": [
              "string",
              "null"
            ]
          },
          "subscription_expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "credits": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "balance": {
                "type": "integer"
              },
              "monthly_allowance": {
                "type": "integer"
              },
              "renews_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "daily_limit": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "spent_usd": {
                "type": "number"
              },
              "cap_usd": {
                "type": "number"
              },
              "resets_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "Model": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "model"
          },
          "type": {
            "type": "string",
            "enum": [
              "chat",
              "image",
              "video",
              "music"
            ]
          },
          "description": {
            "type": "string"
          },
          "aspect_ratios": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "modes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "durations": {
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              {
                "type": "object",
                "properties": {
                  "min": {
                    "type": "integer"
                  },
                  "max": {
                    "type": "integer"
                  }
                }
              }
            ]
          },
          "resolutions": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "quality": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "styles": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "fps": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "references": {
            "type": "object",
            "properties": {
              "images": {
                "type": "integer"
              },
              "videos": {
                "type": "integer"
              },
              "audios": {
                "type": "integer"
              }
            }
          },
          "parameters": {
            "description": "Imagem: objeto com os ajustes aceitos. Vídeo: lista dos parâmetros extras aceitos.",
            "oneOf": [
              {
                "type": "object"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "notes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "ChatMessage": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "user",
              "assistant"
            ]
          },
          "content": {
            "type": "string",
            "maxLength": 120000
          }
        }
      },
      "ChatRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "messages": {
            "type": "array",
            "minItems": 1,
            "maxItems": 200,
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            },
            "description": "A última mensagem precisa ter role user."
          },
          "model": {
            "type": "string",
            "enum": [
              "gpt-5",
              "claude-sonnet",
              "gemini-pro",
              "llama-4",
              "deepseek-v3",
              "grok-4",
              "mistral-large",
              "perplexity-sonar",
              "copilot",
              "qwen",
              "command-r-plus",
              "poe",
              "gemini-3-flash"
            ],
            "default": "gpt-5"
          },
          "system": {
            "type": "string",
            "maxLength": 20000
          },
          "conversation_id": {
            "type": "string",
            "format": "uuid"
          },
          "stream": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "chat.completion"
          },
          "model": {
            "type": "string"
          },
          "conversation_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "message": {
            "$ref": "#/components/schemas/ChatMessage"
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "job"
          },
          "kind": {
            "type": "string",
            "enum": [
              "video",
              "music"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "processing",
              "completed",
              "failed"
            ]
          },
          "result": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "properties": {
                  "video_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              },
              {
                "type": "object",
                "properties": {
                  "tracks": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "title": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "audio_url": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "image_url": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "duration": {
                          "type": [
                            "number",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            ]
          },
          "error": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "message": {
                "type": "string"
              }
            }
          },
          "webhook_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Creation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "creation"
          },
          "kind": {
            "type": "string",
            "enum": [
              "image",
              "video",
              "audio",
              "doc"
            ]
          },
          "tool": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "url": {
            "type": "string"
          },
          "thumbnail_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "description": "Assinado no header Packia-Signature: t=<unix>,v1=<HMAC SHA-256 hex de \"{t}.{corpo}\">.",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "event"
          },
          "type": {
            "type": "string",
            "enum": [
              "video.completed",
              "video.failed",
              "music.completed",
              "music.failed"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "$ref": "#/components/schemas/Job"
          }
        }
      }
    }
  }
}
