{
    "schema_version": "1.2",
    "catalog_version": "9.95",
    "updated_at": "2026-12-05",
    "canonical_source": "https://www.promptbox.cn/api/docs.html",
    "generated_from": "https://www.promptbox.cn/api/docs.html",
    "purpose": "Complete machine-callable specification for one Promptbox helper.",
    "selection_defaults": {
        "text_llm": {
            "helper": "llm.php",
            "rule": "Preferred for ordinary text LLM requests. Set model=fast for local Qwen."
        },
        "text_to_image": {
            "helper": "image_gen_local.php",
            "rule": "Preferred for ordinary text-to-image generation."
        },
        "specialized_helpers_rule": "Choose another helper only when its documented capability, such as multimodal input, image editing, neural simulation, or speech synthesis, is required."
    },
    "browser_access_policy": {
        "publish_first_required": true,
        "rule": "Browser calls to helpers normally require HTTPS promptbox.cn or a subdomain. Publish the app first, then test at its returned Promptbox URL.",
        "server_to_server": "Originless server-to-server and CLI calls remain supported.",
        "exceptions": [
            {
                "helper": "publish.php",
                "rule": "Unrestricted browser origin so external agents can publish."
            },
            {
                "helper": "doomfly.php",
                "rule": "Unrestricted browser origin with automatic service credentials; shared computation and rate limits still apply."
            },
            {
                "helper": "nas",
                "rule": "Requires NAS authentication. Originless server and CLI requests work, and browser requests use the matching Promptbox origin."
            }
        ]
    },
    "error_policy": {
        "caller_errors": [
            400,
            401,
            403,
            404,
            405,
            409,
            413,
            415,
            422
        ],
        "rate_limit": 429,
        "storage_full": 507,
        "infrastructure_errors": [
            500,
            503,
            504
        ],
        "ambiguous": [
            502
        ]
    },
    "index_url": "https://www.promptbox.cn/api/catalog.json",
    "helper": {
        "id": "nas",
        "name": "NAS API",
        "summary": "Authenticated access to private file storage",
        "description": "Lists folders, reports storage capacity, streams downloads, uploads files in chunks, and manages folders, descriptions, and Trash. Access requires the NAS credential.",
        "how_to_use": "Send the NAS password from your secret store as JSON to POST https://promptbox.cn/api/nas.php?op=api_login. Save the returned access_token privately and send Authorization: Bearer <access_token> on each following request. Reuse the token for up to 24 hours. api_logout revokes it, and changing the NAS password revokes all API tokens. Use an HTTPS client or server-side integration. For browser requests, use the matching HTTPS origin on promptbox.cn or www.promptbox.cn.",
        "browser_access": {
            "policy": "same_origin_only",
            "origins": [
                "https://promptbox.cn",
                "https://www.promptbox.cn"
            ],
            "publish_first": false,
            "server_to_server_without_origin": true
        },
        "endpoints": [
            {
                "url": "https://promptbox.cn/api/nas.php",
                "methods": [
                    "GET",
                    "POST",
                    "PUT"
                ]
            }
        ],
        "operations": [
            {
                "name": "api_login",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"password\": string}. Returns ok, access_token, token_type (Bearer), and expires_in (86400 seconds)."
            },
            {
                "name": "api_logout",
                "methods": [
                    "POST"
                ],
                "description": "Send the bearer token with an empty request body. Revokes that token and returns {\"ok\":true}."
            },
            {
                "name": "list",
                "methods": [
                    "GET"
                ],
                "description": "Optional query path. Returns path and items. Each item includes name, path, folder, size in bytes, modified as Unix seconds, and description. Description status is pending, processing, ready, limited, edited, changed, or error. Failures appear in reader.error; a scheduled retry includes reader.retry_at."
            },
            {
                "name": "status",
                "methods": [
                    "GET"
                ],
                "description": "Returns storage status including free and total bytes."
            },
            {
                "name": "download",
                "methods": [
                    "GET"
                ],
                "description": "Query path. Streams file bytes with Content-Disposition. Supports single byte ranges using the Range header and HTTP 206."
            },
            {
                "name": "mkdir",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"path\": string, \"name\": string}. Creates a folder under path. Use \"\" for the root."
            },
            {
                "name": "rename",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"path\": string, \"name\": string}. Renames a file or folder within its current parent."
            },
            {
                "name": "trash",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"path\": string}. Moves the file or folder and its contents to Trash."
            },
            {
                "name": "trash_list",
                "methods": [
                    "GET"
                ],
                "description": "Returns items with id, the original path, and created as Unix seconds."
            },
            {
                "name": "restore",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"id\": string}. Restores a Trash entry using its ID from trash_list."
            },
            {
                "name": "description",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"path\": string, \"description\": string}. Saves a file description of up to 5,000 characters."
            },
            {
                "name": "describe",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"path\": string}. Queues background generation and returns HTTP 202 with ok:true, queued:true, and the current file immediately. Existing pending jobs are deduplicated. Use this to retry a failed description or regenerate one; completion does not depend on keeping the caller connected. Supported files up to 10 MB may be sent to the reader for temporary processing. Larger files can use an excerpt or metadata."
            },
            {
                "name": "upload_begin",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"path\": string, \"name\": string, \"size\": integer}. Pass the destination folder and exact file size in bytes. Returns an upload id for staging."
            },
            {
                "name": "upload_chunk",
                "methods": [
                    "PUT"
                ],
                "description": "Query id and offset. Send raw bytes as application/octet-stream with an explicit Content-Length between 1 and 8,388,608 bytes. Returns total staged bytes as received. Send chunks sequentially."
            },
            {
                "name": "upload_finish",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"id\": string}. Saves the complete file, atomically queues its background description, and returns file immediately without waiting for file-reading or language services. Existing files are protected from overwrite. For an empty file, go directly from upload_begin to upload_finish. Descriptions run automatically, including API uploads, and unfinished jobs resume after a service restart. Refresh the folder with list later to see the result; do not poll continuously. Temporary failures have up to three total attempts before a visible error status. Description failures never remove the saved file."
            },
            {
                "name": "upload_cancel",
                "methods": [
                    "POST"
                ],
                "description": "JSON {\"id\": string}. Discards the staged upload. If a chunk's result is uncertain and the next request reports an offset conflict, cancel and start over."
            }
        ],
        "request_content_types": [
            "application/json",
            "application/octet-stream"
        ],
        "parameter_groups": [
            {
                "name": "query parameters",
                "parameters": [
                    {
                        "name": "op",
                        "type": "string",
                        "requirement": "required",
                        "required": true,
                        "description": "Pick an operation from the table below."
                    },
                    {
                        "name": "path",
                        "type": "string",
                        "requirement": "required for download",
                        "required": true,
                        "description": "URL-encode the path relative to the NAS root. For list, omit it or use an empty string to list the root."
                    },
                    {
                        "name": "id",
                        "type": "string",
                        "requirement": "required for upload_chunk",
                        "required": true,
                        "description": "Upload ID returned by upload_begin."
                    },
                    {
                        "name": "offset",
                        "type": "integer",
                        "requirement": "required for upload_chunk",
                        "required": true,
                        "description": "Zero-based byte offset. Start at 0 and use the previous chunk’s received value for the next request."
                    }
                ]
            }
        ],
        "responses": [
            {
                "name": "response and limits",
                "description": "Send JSON POST bodies as application/json, up to 64 KiB. Use root-relative paths such as Reports/sample.pdf. Use the path returned by list or upload_finish to address an existing item.\nSuccessful JSON responses include \"ok\":true. Errors include \"ok\":false and error. Common statuses are 400 for invalid input, 401 for missing, expired or revoked credentials, 403 for a disallowed origin, 404 for a missing item, 409 for a conflict, 413 for a request above the size limit, 415 for an unsupported request content type, and 503 when storage or its connection is unavailable. Successful downloads return file bytes.\nAuthenticated NAS file operations and description requests have no NAS request-rate quota. Password attempts remain limited to 8 per IP and 80 across the service in 15 minutes; rejected login attempts return HTTP 429 with Retry-After. Upload-size limits and downstream description-helper limits still apply.",
                "content_types": [
                    "application/json"
                ]
            }
        ],
        "examples": [
            "POST https://promptbox.cn/api/nas.php?op=api_login\nContent-Type: application/json\n{\"password\":\"<NAS_PASSWORD_FROM_SECRET_STORE>\"}\n\nGET https://promptbox.cn/api/nas.php?op=list&path=Reports\nAuthorization: Bearer <ACCESS_TOKEN>\n\nGET https://promptbox.cn/api/nas.php?op=download&path=Reports%2Fsample.pdf\nAuthorization: Bearer <ACCESS_TOKEN>\nRange: bytes=0-1023\n\nPOST https://promptbox.cn/api/nas.php?op=upload_begin\nAuthorization: Bearer <ACCESS_TOKEN>\nContent-Type: application/json\n{\"path\":\"Reports\",\"name\":\"sample.txt\",\"size\":5}\n\nPUT https://promptbox.cn/api/nas.php?op=upload_chunk&id=<UPLOAD_ID>&offset=0\nAuthorization: Bearer <ACCESS_TOKEN>\nContent-Type: application/octet-stream\nContent-Length: 5\n\nhello\n\nPOST https://promptbox.cn/api/nas.php?op=upload_finish\nAuthorization: Bearer <ACCESS_TOKEN>\nContent-Type: application/json\n{\"id\":\"<UPLOAD_ID>\"}\n\nPOST https://promptbox.cn/api/nas.php?op=api_logout\nAuthorization: Bearer <ACCESS_TOKEN>"
        ],
        "rate_limit": {
            "description": "Authenticated NAS file operations and description requests have no NAS request-rate quota. Password attempts remain limited to 8 per IP or 80 overall in 15 minutes; login HTTP 429 includes Retry-After. Upload-size and downstream helper limits still apply."
        },
        "side_effects": [
            "writes_private_storage",
            "moves_items_to_trash",
            "optionally_sends_file_content_for_description_processing"
        ],
        "authentication": {
            "required": true,
            "scheme": "bearer",
            "login_url": "https://promptbox.cn/api/nas.php?op=api_login",
            "logout_url": "https://promptbox.cn/api/nas.php?op=api_logout",
            "expires_in_seconds": 86400,
            "credential_source": "NAS password supplied privately by the caller"
        },
        "usage_summary": {
            "what": "Lists folders, reports storage capacity, streams downloads, uploads files in chunks, and manages folders, descriptions, and Trash. Access requires the NAS credential.",
            "how": "Send the NAS password from your secret store as JSON to POST https://promptbox.cn/api/nas.php?op=api_login. Save the returned access_token privately and send Authorization: Bearer <access_token> on each following request. Reuse the token for up to 24 hours. api_logout revokes it, and changing the NAS password revokes all API tokens. Use an HTTPS client or server-side integration. For browser requests, use the matching HTTPS origin on promptbox.cn or www.promptbox.cn."
        }
    }
}