{
  "openapi": "3.1.0",
  "info": {
    "title": "Prompt Anything API",
    "version": "1.0.0",
    "description": "Turn an idea into a full, specialized prompt built with your Prompt Anything profile, business context and learned preferences. Call it from your server only: browsers cannot call the API. Request bodies are up to 262,144 bytes.",
    "termsOfService": "https://www.promptanything.io/terms#api"
  },
  "externalDocs": {
    "description": "API docs",
    "url": "https://www.promptanything.io/docs/api"
  },
  "servers": [
    {
      "url": "https://www.promptanything.io/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/prompts": {
      "post": {
        "operationId": "createPrompt",
        "summary": "Create an enhanced prompt",
        "description": "Turn an idea into a full, specialized prompt, built with your Prompt Anything profile, business context and learned preferences. { status: 'done', prompt, mode, credits_charged, run_id, blanks?, files? } (files: one { name, status, note } per file you sent, saying what was read), or { status: 'questions', run_id, questions: [{ id, question, suggested_answer, category }] } when ask_first is true, or { status: 'working', run_id } when it takes longer than about 40 seconds.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PromptRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done, waiting for answers, or still working.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/PromptDone"
                    },
                    {
                      "$ref": "#/components/schemas/Questions"
                    },
                    {
                      "$ref": "#/components/schemas/Working"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "402": {
            "$ref": "#/components/responses/Error402"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/prompts/{run_id}/answers": {
      "post": {
        "operationId": "answerQuestions",
        "summary": "Answer the questions of a run",
        "description": "Answer the questions from an ask_first run. Send only the answers you want to change; the rest keep their suggested answers. No extra credits. The same as POST /prompts once the prompt is done.",
        "parameters": [
          {
            "name": "run_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The run_id from an earlier response."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnswersRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done or still working.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/PromptDone"
                    },
                    {
                      "$ref": "#/components/schemas/Working"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/improve": {
      "post": {
        "operationId": "improvePrompt",
        "summary": "Improve an existing prompt",
        "description": "Make an existing prompt better. { status: 'done', prompt, credits_charged, run_id } or { status: 'working', run_id }.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImproveRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done or still working.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/ImproveDone"
                    },
                    {
                      "$ref": "#/components/schemas/Working"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "402": {
            "$ref": "#/components/responses/Error402"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/runs/{run_id}": {
      "get": {
        "operationId": "getRun",
        "summary": "Read a run",
        "description": "Check a run that answered 'working'. Wait about 10 seconds between checks. Only your keys can read it. Runs are kept for 24 hours. The run as POST /prompts would answer it now, or { status: 'failed', run_id, credits_charged: 0, error } if it failed.",
        "parameters": [
          {
            "name": "run_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The run_id from an earlier response."
          }
        ],
        "responses": {
          "200": {
            "description": "The run as it is now.",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/PromptDone"
                    },
                    {
                      "$ref": "#/components/schemas/ImproveDone"
                    },
                    {
                      "$ref": "#/components/schemas/Questions"
                    },
                    {
                      "$ref": "#/components/schemas/Working"
                    },
                    {
                      "$ref": "#/components/schemas/Failed"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/runs/{run_id}/blanks": {
      "post": {
        "operationId": "fillBlanks",
        "summary": "Fill in the blanks of a finished prompt",
        "description": "Fill in the blanks of a finished prompt. We put your answers into the prompt and send it back whole. No credits are charged and no callback is sent. Answers you type or keep are saved to what Prompt Anything has learned about the key owner, as confirmed answers; answers the AI guesses are never saved. The same as a done POST /prompts: { status: 'done', run_id, prompt, mode, credits_charged, blanks, needs_user?, not_applied? }. credits_charged is the run's original charge; filling blanks costs nothing extra. prompt already holds your answers. AI guesses carry [ASSUMED - confirm] until you keep them. needs_user lists blanks the AI left for you with a reason (number, private or none). not_applied lists items we could not use. A run that is still working or waiting for answers answers 400 invalid_request: This run is not finished yet. Fill blanks after it is done. A done run with no blanks answers 400 invalid_request: This run has no blanks to fill.",
        "parameters": [
          {
            "name": "run_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The run_id from an earlier response."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BlanksRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The finished prompt with the answers in it.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/PromptDone"
                    },
                    {
                      "$ref": "#/components/schemas/ImproveDone"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    },
    "/balance": {
      "get": {
        "operationId": "getBalance",
        "summary": "Read the credit balance",
        "description": "Your credits by bucket. { credits: { included, free, purchased, total }, included_resets_at }",
        "responses": {
          "200": {
            "description": "Your credits by bucket.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Balance"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Prompt Anything API key, pa_live_..."
      }
    },
    "schemas": {
      "PromptRequest": {
        "type": "object",
        "required": [
          "idea"
        ],
        "properties": {
          "idea": {
            "type": "string",
            "minLength": 1,
            "maxLength": 20000,
            "description": "The idea to turn into a prompt."
          },
          "mode": {
            "type": "string",
            "enum": [
              "agent",
              "automation",
              "web-app",
              "mobile-app",
              "claude-skill",
              "code-script",
              "data-extraction",
              "code-generation",
              "image",
              "copywriting",
              "video",
              "voice-tts",
              "improve-prompt",
              "improve-code",
              "improve-copy",
              "basic"
            ],
            "description": "What the prompt is for. Leave out and Prompt Anything picks."
          },
          "provider": {
            "type": "string",
            "enum": [
              "google",
              "openai",
              "anthropic",
              "grok",
              "deepseek",
              "mistral",
              "meta"
            ],
            "description": "Which AI the prompt is written for."
          },
          "quality": {
            "type": "string",
            "enum": [
              "standard",
              "premium"
            ],
            "default": "standard",
            "description": "standard or premium."
          },
          "ask_first": {
            "type": "boolean",
            "default": false,
            "description": "True to get questions first, then call the answers endpoint."
          },
          "callback_url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2000,
            "description": "Optional https address on the public internet. The run is posted to it when it has questions, finishes or fails."
          },
          "wait": {
            "type": "boolean",
            "default": true,
            "description": "Set false to get { status: 'working', run_id } at once instead of waiting. Then read GET /runs/{run_id}, or use callback_url where the endpoint takes one."
          },
          "files": {
            "type": "array",
            "maxItems": 5,
            "description": "Optional files to build the prompt from: PDF, Word, Excel, PowerPoint, zip, images, audio, video or text, 10 MB each (16 MB per request). Each has exactly one of text, data or url.",
            "items": {
              "type": "object",
              "required": [
                "name"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200,
                  "description": "The file name, with its extension."
                },
                "text": {
                  "type": "string",
                  "maxLength": 200000,
                  "description": "The file's text."
                },
                "data": {
                  "type": "string",
                  "maxLength": 14000000,
                  "description": "The file itself, base64."
                },
                "url": {
                  "type": "string",
                  "format": "uri",
                  "description": "A public https link to the file."
                }
              }
            }
          }
        }
      },
      "ImproveRequest": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "type": "string",
            "minLength": 1,
            "maxLength": 20000,
            "description": "The prompt to improve."
          },
          "mode": {
            "type": "string",
            "enum": [
              "improve-prompt",
              "improve-code",
              "improve-copy"
            ],
            "default": "improve-prompt"
          },
          "quality": {
            "type": "string",
            "enum": [
              "standard",
              "premium"
            ],
            "default": "standard",
            "description": "standard or premium."
          },
          "callback_url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2000,
            "description": "Optional https address on the public internet. The run is posted to it when it has questions, finishes or fails."
          },
          "wait": {
            "type": "boolean",
            "default": true,
            "description": "Set false to get { status: 'working', run_id } at once instead of waiting. Then read GET /runs/{run_id}, or use callback_url where the endpoint takes one."
          }
        }
      },
      "AnswersRequest": {
        "type": "object",
        "required": [
          "answers"
        ],
        "properties": {
          "answers": {
            "type": "array",
            "maxItems": 200,
            "description": "Only the answers you want to change. The rest keep their suggested answers.",
            "items": {
              "type": "object",
              "required": [
                "id",
                "answer"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^\\d{1,3}\\.\\d{1,3}$",
                  "description": "The question id from the questions, like 1.2."
                },
                "answer": {
                  "type": "string",
                  "maxLength": 5000
                }
              }
            }
          },
          "wait": {
            "type": "boolean",
            "default": true,
            "description": "Set false to get { status: 'working', run_id } at once instead of waiting. Then read GET /runs/{run_id}, or use callback_url where the endpoint takes one."
          }
        }
      },
      "BlanksRequest": {
        "type": "object",
        "minProperties": 1,
        "description": "Send answers, ai_fill, or both. Each answer needs a value or keep: true.",
        "properties": {
          "answers": {
            "type": "array",
            "maxItems": 40,
            "items": {
              "type": "object",
              "required": [
                "id"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64,
                  "description": "A blank id from blanks, like p:city."
                },
                "value": {
                  "type": "string",
                  "maxLength": 500,
                  "description": "Your answer. It is confirmed and saved for the key owner."
                },
                "keep": {
                  "type": "boolean",
                  "description": "True confirms the AI guess or suggestion on the blank now."
                }
              }
            }
          },
          "ai_fill": {
            "type": "array",
            "maxItems": 40,
            "items": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Blank ids for the AI to guess, or [\"all\"]. Guesses are tagged [ASSUMED - confirm] and never saved."
          }
        }
      },
      "Blank": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "label",
          "why",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "key_fact",
              "assumption",
              "placeholder",
              "default"
            ]
          },
          "label": {
            "type": "string"
          },
          "why": {
            "type": "string"
          },
          "current": {
            "type": "string",
            "description": "What the prompt says there now."
          },
          "value": {
            "type": "string",
            "description": "The answer on the blank now, if any."
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "ai",
              "confirmed"
            ]
          }
        }
      },
      "BlankReason": {
        "type": "object",
        "required": [
          "id",
          "reason"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          }
        }
      },
      "PromptDone": {
        "type": "object",
        "required": [
          "status",
          "run_id",
          "prompt",
          "mode",
          "credits_charged"
        ],
        "properties": {
          "status": {
            "const": "done"
          },
          "run_id": {
            "type": "string"
          },
          "prompt": {
            "type": "string",
            "description": "The enhanced prompt."
          },
          "mode": {
            "type": [
              "string",
              "null"
            ]
          },
          "credits_charged": {
            "type": "integer",
            "minimum": 0
          },
          "blanks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Blank"
            },
            "description": "Only when the prompt has blanks. prompt already holds any answers."
          },
          "needs_user": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlankReason"
            },
            "description": "Blanks the AI left for you (reason: number, private or none)."
          },
          "not_applied": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlankReason"
            },
            "description": "Items that could not be used, like an unknown id."
          }
        }
      },
      "ImproveDone": {
        "type": "object",
        "required": [
          "status",
          "run_id",
          "prompt",
          "credits_charged"
        ],
        "properties": {
          "status": {
            "const": "done"
          },
          "run_id": {
            "type": "string"
          },
          "prompt": {
            "type": "string",
            "description": "The improved prompt."
          },
          "credits_charged": {
            "type": "integer",
            "minimum": 0
          },
          "blanks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Blank"
            },
            "description": "Only when the prompt has blanks. prompt already holds any answers."
          },
          "needs_user": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlankReason"
            },
            "description": "Blanks the AI left for you (reason: number, private or none)."
          },
          "not_applied": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlankReason"
            },
            "description": "Items that could not be used, like an unknown id."
          }
        }
      },
      "Questions": {
        "type": "object",
        "required": [
          "status",
          "run_id",
          "questions"
        ],
        "properties": {
          "status": {
            "const": "questions"
          },
          "run_id": {
            "type": "string"
          },
          "questions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "question",
                "suggested_answer",
                "category"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "question": {
                  "type": "string"
                },
                "suggested_answer": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "category": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "Working": {
        "type": "object",
        "required": [
          "status",
          "run_id"
        ],
        "properties": {
          "status": {
            "const": "working"
          },
          "run_id": {
            "type": "string"
          }
        }
      },
      "Failed": {
        "type": "object",
        "required": [
          "status",
          "run_id",
          "credits_charged",
          "error"
        ],
        "properties": {
          "status": {
            "const": "failed"
          },
          "run_id": {
            "type": "string"
          },
          "credits_charged": {
            "const": 0
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_key",
                  "revoked_key",
                  "out_of_credits",
                  "rate_limited",
                  "spend_cap_reached",
                  "too_large",
                  "invalid_request",
                  "not_found",
                  "content_refused",
                  "server_error"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Balance": {
        "type": "object",
        "required": [
          "credits",
          "included_resets_at"
        ],
        "properties": {
          "credits": {
            "type": "object",
            "required": [
              "included",
              "free",
              "purchased",
              "total"
            ],
            "properties": {
              "included": {
                "type": "number"
              },
              "free": {
                "type": "number"
              },
              "purchased": {
                "type": "number"
              },
              "total": {
                "type": "number"
              }
            }
          },
          "included_resets_at": {
            "type": [
              "string",
              "null"
            ],
            "description": "When the included credits reset."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_key",
                  "revoked_key",
                  "out_of_credits",
                  "rate_limited",
                  "spend_cap_reached",
                  "too_large",
                  "invalid_request",
                  "not_found",
                  "content_refused",
                  "server_error"
                ]
              },
              "message": {
                "type": "string"
              },
              "topup_url": {
                "type": "string",
                "format": "uri",
                "description": "Where to add credits. Sent with out_of_credits."
              },
              "run_id": {
                "type": "string",
                "description": "Sent when a started run failed."
              },
              "credits_charged": {
                "type": "integer",
                "description": "Sent when a started run failed. Always 0."
              }
            }
          }
        }
      }
    },
    "responses": {
      "Error400": {
        "description": "invalid_request: Something in the request is missing or wrong. The message says what.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error401": {
        "description": "invalid_key: No key, or not a valid key. revoked_key: The key was revoked, or paused after too many failed calls. Resume or replace it on the Developers page.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error402": {
        "description": "out_of_credits: Not enough credits for this call. The error has a topup_url.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error404": {
        "description": "not_found: No such endpoint, or no such run for your account.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error413": {
        "description": "too_large: An idea, prompt or answer is over its limit.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error422": {
        "description": "content_refused: The request breaks the content rules.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error429": {
        "description": "rate_limited: Too many requests or runs at once. Wait for the Retry-After seconds. spend_cap_reached: The key reached its daily credit cap. It resets at midnight UTC.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait before trying again.",
            "schema": {
              "type": "integer"
            }
          }
        }
      },
      "Error500": {
        "description": "server_error: Our side failed. No credits were charged. Try again.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
