Hugging Face and Cloudflare FastRTC Integration

Hugging Face and Cloudflare have partnered to integrate Cloudflare's global WebRTC infrastructure into FastRTC, allowing AI developers to deploy low-latency audio and video streams without managing their own TURN servers. This integration removes a significant deployment barrier for real-time multimodal AI applications by providing enterprise-grade connectivity via a Hugging Face token.

Simplified WebRTC Deployment via Cloudflare TURN Servers

FastRTC abstracts the complexities of WebRTC to enable the creation of AI-powered audio and video streams using minimal Python code. However, WebRTC applications typically require specialized TURN (Traversal Using Relays around NAT) servers to ensure reliable connections across diverse network environments.

Through this partnership, FastRTC developers gain access to Cloudflare's global network of TURN servers, which spans over 335 locations worldwide. This eliminates the need for developers to build and maintain their own TURN infrastructure, shifting the focus from network management to core application logic.

Access and Pricing Model

Developers can access the Cloudflare TURN network using a valid Hugging Face Access Token. The partnership includes a free tier providing 10GB of data streaming per month without requiring a credit card. For applications requiring higher capacity, developers can transition to their own Cloudflare accounts.

Target Use Cases for Real-Time AI

This infrastructure integration is specifically designed to support the development of multimodal AI applications that require reliable, low-latency streaming, including:

  • Voice Assistants: Applications requiring stable, low-latency audio streaming for natural conversation.
  • Real-Time Video Analysis: Applications that process live camera feeds as they happen.
  • Multimodal AI: Systems that combine audio, video, and text inputs and outputs in real-time.

Technical Implementation and Requirements

The Cloudflare integration is available in FastRTC version 0.0.20 and above. To implement the integration, developers need a Hugging Face token with read access and the fastrtc[vad] package.

Implementation Example

Developers can configure a stream to use the Cloudflare TURN network by using the get_cloudflare_turn_credentials function within the Stream configuration:

from fastrtc import ReplyOnPause, Stream, get_cloudflare_turn_credentials
import os

os.environ["HF_TOKEN"] = "<your-hf-token>"

def echo(audio):
    yield audio

stream = Stream(ReplyOnPause(echo),
                rtc_config=get_cloudflare_turn_credentials)
stream.ui.launch()

Ecosystem Resources

For further implementation details, developers can refer to the FastRTC Cookbook or the dedicated Cloudflare partnership collection on Hugging Face.

Sources