Skip to main content

LlamaIndex LLM Integration for Cloudflare AI Gateway

This package provides integration between LlamaIndex and Cloudflare AI Gateway, allowing you to use multiple AI models from different providers with automatic fallback.

Features

  • Multiple Providers: Use OpenAI, Anthropic, Mistral, Groq, and more
  • Automatic Fallback: If one provider fails, automatically tries the next
  • Streaming Support: Both chat and completion streaming
  • Async Support: Full async/await support
  • Caching: Built-in request caching with Cloudflare AI Gateway

Installation

pip install llama-index-llms-cloudflare-ai-gateway

Quick Start

from llama_index.llms.cloudflare_ai_gateway import CloudflareAIGateway
from llama_index.llms.openai import OpenAI
from llama_index.llms.anthropic import Anthropic
from llama_index.core.llms import ChatMessage

# Create LLM instances
openai_llm = OpenAI(model="gpt-4o-mini", api_key="your-openai-key")
anthropic_llm = Anthropic(
    model="claude-3-5-sonnet-20241022", api_key="your-anthropic-key"
)

# Create Cloudflare AI Gateway LLM
llm = CloudflareAIGateway(
    llms=[openai_llm, anthropic_llm],  # Try OpenAI first, then Anthropic
    account_id="your-cloudflare-account-id",
    gateway="your-ai-gateway-name",
    api_key="your-cloudflare-api-key",
)

# Use the LLM
messages = [ChatMessage(role="user", content="What is 2+2?")]
response = llm.chat(messages)
print(response.message.content)

Supported Providers

  • OpenAI
  • Anthropic
  • Mistral AI
  • Groq
  • DeepSeek
  • Perplexity
  • Replicate
  • Grok
  • Azure OpenAI

Testing

# Set environment variables
export OPENAI_API_KEY="your-key"
export ANTHROPIC_API_KEY="your-key"
export CLOUDFLARE_ACCOUNT_ID="your-id"
export CLOUDFLARE_API_KEY="your-key"
export CLOUDFLARE_GATEWAY="your-gateway"

# Run tests
uv run pytest tests/

Metadata

Release files for llama-index-llms-cloudflare-ai-gateway 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-llms-cloudflare-ai-gateway 0.3.0
File Size Uploaded Provenance Actions
llama_index_llms_cloudflare_ai_gateway-0.3.0.tar.gz 8.1 kB Without provenance Details for llama_index_llms_cloudflare_ai_gateway-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-llms-cloudflare-ai-gateway 0.3.0
File Interpreter ABI Platform Actions
llama_index_llms_cloudflare_ai_gateway-0.3.0-py3-none-any.whl Python 3 none any Details for llama_index_llms_cloudflare_ai_gateway-0.3.0-py3-none-any.whl

Total release size: 16.2 kB

Release files / llama_index_llms_cloudflare_ai_gateway-0.3.0.tar.gz

Download URL llama_index_llms_cloudflare_ai_gateway-0.3.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
26942396ac63bdce74d4fd22d4494803d9e9a0c5ce354a995d2fab114ba2deb3
BLAKE2b-256 checksum
How to use checksums
fec08a549ff6233d4ba9880a4657422e50fc716eaefd338bd302f2f32b3ed25f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_llms_cloudflare_ai_gateway-0.3.0-py3-none-any.whl

Download URL llama_index_llms_cloudflare_ai_gateway-0.3.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5d8eb03c853f860bcdd746b9f62ed6c837e65f638f12b3014d53732b7cba898
BLAKE2b-256 checksum
How to use checksums
dd48334abc52f25e0a53cd38244d89922a90033d2f787b81238a97294d054ef8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-llms-cloudflare-ai-gateway 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page