---
title: "Cloudflare Workers AI"
url: "/docs/providers/cloudflare_workers"
canonical_url: "https://docs.litellm.ai/docs/providers/cloudflare_workers"
type: "docs"
last_updated: "2026-10-08"
related:
  - "/docs/providers/clf_ai_gateway"
  - "/docs/providers/codestral"
---
# Cloudflare Workers AI

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

https://developers.cloudflare.com/workers-ai/models/text-generation/

## API 金鑰 {#api-key}
```python
# env variable
os.environ['CLOUDFLARE_API_KEY'] = "3dnSGlxxxx"
os.environ['CLOUDFLARE_ACCOUNT_ID'] = "03xxxxx"
```

## 範例用法 {#sample-usage}
```python
from litellm import completion
import os

os.environ['CLOUDFLARE_API_KEY'] = "3dnSGlxxxx"
os.environ['CLOUDFLARE_ACCOUNT_ID'] = "03xxxxx"

response = completion(
    model="cloudflare/@cf/meta/llama-2-7b-chat-int8", 
    messages=[
       {"role": "user", "content": "hello from litellm"}
   ],
)
print(response)
```

## 範例用法 - 串流 {#sample-usage---streaming}
```python
from litellm import completion
import os

os.environ['CLOUDFLARE_API_KEY'] = "3dnSGlxxxx"
os.environ['CLOUDFLARE_ACCOUNT_ID'] = "03xxxxx"

response = completion(
    model="cloudflare/@hf/thebloke/codellama-7b-instruct-awq", 
    messages=[
       {"role": "user", "content": "hello from litellm"}
   ],
    stream=True
)

for chunk in response:
    print(chunk)
```

## 支援的模型 {#supported-models}
此處列出的所有模型 https://developers.cloudflare.com/workers-ai/models/text-generation/ 都支援

| 模型名稱                        | 函式呼叫                                            |
|-----------------------------------|----------------------------------------------------------|
| @cf/meta/llama-2-7b-chat-fp16     | `completion(model="mistral/mistral-tiny", messages)`    |
| @cf/meta/llama-2-7b-chat-int8     | `completion(model="mistral/mistral-small", messages)`   |
| @cf/mistral/mistral-7b-instruct-v0.1 | `completion(model="mistral/mistral-medium", messages)` |
| @hf/thebloke/codellama-7b-instruct-awq | `completion(model="codellama/codellama-medium", messages)` |

## Related pages

- [CLF AI Gateway](https://docs.litellm.ai/docs/providers/clf_ai_gateway.md)
- [Codestral API [Mistral AI]](https://docs.litellm.ai/docs/providers/codestral.md)
