Skip to main content

Langchain Integrations for Cloudflare's WorkersAI and Vectorize

Project description

langchain-cloudflare

This package contains the LangChain integration with CloudflareWorkersAI

Installation

pip install -U langchain-cloudflare

And you should configure credentials by setting the following environment variables:

  • CF_ACCOUNT_ID

AND

  • CF_API_TOKEN (if using a single token scoped for all services)

OR (if using separately scoped tokens)

  • CF_AI_API_TOKEN (CloudflareWorkersAI and CloudflareWorkersAIEmbeddings)
  • CF_VECTORIZE_API_TOKEN (CloudflareVectorize)
  • CF_D1_API_TOKEN (CloudflareVectorize)
  • CF_D1_DATABASE_ID (CloudflareVectorize)

Chat Models

ChatCloudflareWorkersAI class exposes chat models from CloudflareWorkersAI.

from langchain_cloudflare.chat_models import ChatCloudflareWorkersAI

llm = ChatCloudflareWorkersAI()
llm.invoke("Sing a ballad of LangChain.")

REST endpoint format

By default, ChatCloudflareWorkersAI uses the native Workers AI run endpoint:

llm = ChatCloudflareWorkersAI(
    model="@cf/moonshotai/kimi-k2.6",
    endpoint_format="workers_ai",  # default
)

For REST calls that need Cloudflare's OpenAI-compatible chat completions API, set endpoint_format="openai_compatible":

llm = ChatCloudflareWorkersAI(
    model="@cf/moonshotai/kimi-k2.6",
    endpoint_format="openai_compatible",
)

When ai_gateway is configured, OpenAI-compatible mode routes through the Workers AI chat completions path on AI Gateway. This option is REST-only; Worker bindings use env.AI.run() and do not expose a chat completions route.

Embeddings

CloudflareWorkersAIEmbeddings class exposes embeddings from CloudflareWorkersAI.

from langchain_cloudflare.embeddings import CloudflareWorkersAIEmbeddings

embeddings = CloudflareWorkersAIEmbeddings(
    model_name="@cf/baai/bge-base-en-v1.5"
)
embeddings.embed_query("What is the meaning of life?")

VectorStores

CloudflareVectorize class exposes vectorstores from Cloudflare Vectorize.

from langchain_cloudflare.vectorstores import CloudflareVectorize

vst = CloudflareVectorize(
    embedding=embeddings
)
vst.create_index(index_name="my-cool-vectorstore")

Release Notes

v0.1.1 (2025-04-08)

  • Added ChatCloudflareWorkersAI integration
  • Added CloudflareWorkersAIEmbeddings support
  • Added CloudflareVectorize integration

v0.1.3 (2025-04-10)

  • Added AI Gateway support for CloudflareWorkersAIEmbeddings
  • Added Async support for CloudflareWorkersAIEmbeddings

v0.1.4 (2025-04-14)

  • Added support for additional model parameters as explicit class attributes for ChatCloudflareWorkersAI

v0.1.6 (2025-05-01)

  • Added Standalone D1 Metadata Filtering Methods
  • Update Docs for more clarity around D1 Table/Vectorize Index Names

v0.1.8 (2025-05-11)

  • Added support for environmental variables (embeddings, vectorstores)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_cloudflare-0.3.5.tar.gz (93.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_cloudflare-0.3.5-py3-none-any.whl (48.7 kB view details)

Uploaded Python 3

File details

Details for the file langchain_cloudflare-0.3.5.tar.gz.

File metadata

  • Download URL: langchain_cloudflare-0.3.5.tar.gz
  • Upload date:
  • Size: 93.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for langchain_cloudflare-0.3.5.tar.gz
Algorithm Hash digest
SHA256 8253a92c86737c833e8ff7bee31c11a41cce923da376d6c49db591b2cc1905d7
MD5 c93e8136398f01b884bb568efe4b70f8
BLAKE2b-256 421042bd23b3ca69a036d0feb193aeca9c3254f1f1f2202134011066d292a73d

See more details on using hashes here.

File details

Details for the file langchain_cloudflare-0.3.5-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_cloudflare-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 04ec0301eb673e8115821f2785bbba831d8ce5a37db0d1fb26503dbec805a950
MD5 63f6da370ccc07a721ddc8c64201f1d3
BLAKE2b-256 2d72d97f083d3f9754d4516592445c693f0858a17a46e08df627a19a1f165a18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page