> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hitheo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 生成文檔

> 根據自然語言生成 PDF、DOCX、PPTX、XLSX 或 CSV 文檔。

根據自然語言提示生成結構化文檔。支持 PDF、DOCX、PPTX、XLSX 和 CSV 格式。

## 身份驗證

需要 Bearer 令牌。參見[身份驗證](/api-reference/authentication)。

## 請求正文

<ParamField body="prompt" type="string" required>
  要生成的文檔的描述。
</ParamField>

<ParamField body="format" type="string" default="pdf">
  輸出格式。可選值：`pdf`、`docx`、`pptx`、`xlsx`、`csv`。
</ParamField>

## 請求示例

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://www.hitheo.ai/api/v1/documents \
    -H "Authorization: Bearer $THEO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "Create a Q1 2026 sales report with executive summary and charts",
      "format": "pdf"
    }'
  ```

  ```typescript SDK theme={null}
  const res = await theo.documents({
    prompt: "Create a Q1 2026 sales report with executive summary and charts",
    format: "pdf",
  });

  console.log(res.title);        // "Q1 2026 Sales Report"
  console.log(res.download_url); // Presigned download URL
  console.log(res.content);      // Document text content
  ```
</CodeGroup>

## 響應

<ResponseField name="id" type="string">
  唯一文檔 ID（以 `doc_` 為前綴）。
</ResponseField>

<ResponseField name="created" type="string">
  ISO 8601 時間戳。
</ResponseField>

<ResponseField name="format" type="string">
  輸出格式（例如 `"pdf"`）。
</ResponseField>

<ResponseField name="title" type="string">
  自動生成的文檔標題。
</ResponseField>

<ResponseField name="download_url" type="string | null">
  用於下載文檔文件的預簽名 URL。若文件仍在生成中，則可能為 `null`。
</ResponseField>

<ResponseField name="size_bytes" type="integer | null">
  文件大小（字節）。
</ResponseField>

<ResponseField name="content" type="string">
  生成文檔的文本內容。
</ResponseField>

<ResponseField name="usage" type="object">
  <Expandable title="Usage object">
    <ResponseField name="cost_cents" type="number">費用（美分）。</ResponseField>
  </Expandable>
</ResponseField>

### 響應示例

```json theme={null}
{
  "id": "doc_abc123",
  "created": "2026-04-10T12:00:00Z",
  "format": "pdf",
  "title": "Q1 2026 Sales Report",
  "download_url": "https://artifacts.hitheo.ai/docs/abc123.pdf?token=...",
  "size_bytes": 245760,
  "content": "# Q1 2026 Sales Report\n\n## Executive Summary\n...",
  "usage": { "cost_cents": 0.12 }
}
```

## 錯誤

| 狀態碼 | 代碼 | 描述 |
| - | - | - |
| 400 | `missing_prompt` | 缺少必需的 `prompt` 參數 |
| 400 | `invalid_format` | 不支持的格式。支持的格式：`pdf`、`docx`、`pptx`、`xlsx`、`csv` |
| 401 | `invalid_api_key` | 缺少 API 密鑰或密鑰無效 |
| 429 | `rate_limit_exceeded` | 請求次數過多 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.