---
title: "使用 LiteLLM Proxy 搭配 Anthropic File API"
url: "/docs/tutorials/anthropic_file_usage"
canonical_url: "https://docs.litellm.ai/docs/tutorials/anthropic_file_usage"
type: "docs"
last_updated: "2026-10-08"
related:
  - "/docs/tutorials/mongodb_vector_search"
  - "/docs/tutorials/gemini_realtime_with_audio"
---
# 使用 LiteLLM Proxy 搭配 Anthropic File API

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


## 概觀 {#overview}

本教學示範如何透過 LiteLLM Proxy 使用 Claude-4 在 Anthropic 上建立並分析檔案。

## 先決條件 {#prerequisites}

- LiteLLM Proxy 正在執行
- Anthropic API 金鑰

將下列內容加入您的 `.env` 檔案：
```
ANTHROPIC_API_KEY=sk-<your-api-key>
```

## 使用方式 {#usage}

### 1. 設定 config.yaml {#1-setup-configyaml}

```yaml
model_list:
  - model_name: claude-opus
    litellm_params:
      model: anthropic/claude-opus-5
      api_key: os.environ/ANTHROPIC_API_KEY
```

## 2. 建立檔案  {#2-create-a-file}

使用 `/anthropic` passthrough 端點來建立檔案。

```bash
curl -L -X POST 'http://0.0.0.0:4000/anthropic/v1/files' \
-H "x-api-key: $LITELLM_API_KEY" \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: files-api-2025-04-14' \
-F 'file=@"/path/to/your/file.csv"'
```

預期回應：

```json
{
  "created_at": "2023-11-07T05:31:56Z",
  "downloadable": false,
  "filename": "file.csv",
  "id": "file-1234",
  "mime_type": "text/csv",
  "size_bytes": 1,
  "type": "file"
}
```

## 3. 透過 `/chat/completions` 使用 Claude-4 分析檔案 {#3-analyze-the-file-with-claude-4-via-chatcompletions}

```bash
curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-d '{
    "model": "claude-opus",
    "messages": [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What is in this sheet?"},
                {
                    "type": "file",
                    "file": {
                        "file_id": "file-1234",
                        "format": "text/csv" # 👈 IMPORTANT: This is the format of the file you want to analyze
                    }
                }
            ]
        }
    ]
}'
```

## Related pages

- [在 MongoDB 中與範例文件聊天（BETA）](https://docs.litellm.ai/docs/tutorials/mongodb_vector_search.md)
- [使用音訊輸入/輸出呼叫 Gemini Realtime API](https://docs.litellm.ai/docs/tutorials/gemini_realtime_with_audio.md)
