---
title: "預測輸出"
url: "/docs/completion/predict_outputs"
canonical_url: "https://docs.litellm.ai/docs/completion/predict_outputs"
type: "docs"
last_updated: "2026-10-08"
related:
  - "/docs/completion/prefix"
  - "/docs/completion/prompt_compression"
---
# 預測輸出

> Index of all LiteLLM docs: https://docs.litellm.ai/llms.txt


| 屬性 | 詳細資訊 |
|-------|-------|
| 說明 | 當 LLM 的大部分輸出可事先得知時，請使用此功能。例如，如果您要請模型僅做少量修改來重寫某段文字或程式碼，您可以將既有內容作為預測輸入，藉由 Predicted Outputs 大幅降低延遲。 |
| 支援的提供者 | `openai` |
| OpenAI 關於 Predicted Outputs 的文件連結 | [Predicted Outputs ↗](https://platform.openai.com/docs/guides/latency-optimization#use-predicted-outputs) |
| LiteLLM 版本起支援 | `v1.51.4` |

## 使用 Predicted Outputs {#using-predicted-outputs}

**LiteLLM Python SDK**

在此範例中，我們要重構一段 C# 程式碼，並將 Username 屬性改為 Email：
```python
import litellm
os.environ["OPENAI_API_KEY"] = "your-api-key"
code = """
/// <summary>
/// Represents a user with a first name, last name, and username.
/// </summary>
public class User
{
    /// <summary>
    /// Gets or sets the user's first name.
    /// </summary>
    public string FirstName { get; set; }

    /// <summary>
    /// Gets or sets the user's last name.
    /// </summary>
    public string LastName { get; set; }

    /// <summary>
    /// Gets or sets the user's username.
    /// </summary>
    public string Username { get; set; }
}
"""

completion = litellm.completion(
    model="gpt-5.6-luna",
    messages=[
        {
            "role": "user",
            "content": "Replace the Username property with an Email property. Respond only with code, and with no markdown formatting.",
        },
        {"role": "user", "content": code},
    ],
    prediction={"type": "content", "content": code},
)

print(completion)
```

**LiteLLM Proxy Server**

1. 在 config.yaml 中定義模型

```yaml
model_list:
  - model_name: gpt-5.6-luna # OpenAI gpt-5.6-luna
    litellm_params:
      model: openai/gpt-5.6-luna
      api_key: os.environ/OPENAI_API_KEY 

```

2. 執行 proxy server

```bash
litellm --config config.yaml
```

3. 使用 OpenAI Python SDK 進行測試

```python
from openai import OpenAI

client = OpenAI(
    api_key="LITELLM_PROXY_KEY", # sk-<your-litellm-api-key>
    base_url="LITELLM_PROXY_BASE" # http://0.0.0.0:4000
)

completion = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=[
        {
            "role": "user",
            "content": "Replace the Username property with an Email property. Respond only with code, and with no markdown formatting.",
        },
        {"role": "user", "content": code},
    ],
    prediction={"type": "content", "content": code},
)

print(completion)
```

## Related pages

- [前置助手訊息](https://docs.litellm.ai/docs/completion/prefix.md)
- [提示壓縮 (compress())](https://docs.litellm.ai/docs/completion/prompt_compression.md)
