Skip to content

replicate/cloudflare-ai-gateway-replicate-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare AI Gateway with Replicate

This repository contains a bash script to test Cloudflare AI Gateway with Replicate using the anthropic/claude-4.5-haiku model.

See the official Cloudflare documentation for more information about using Replicate with AI Gateway.

Setup

  1. Create a Cloudflare AI Gateway by following the getting started guide

  2. Copy .env.example to .env:

    cp .env.example .env
  3. Fill in your credentials in .env:

Usage

Run the script with an optional prompt:

./replicate-test.sh "Your prompt here"

Or use the default prompt:

./replicate-test.sh

Parameters

Prompt (optional): The prompt to send to Claude. Default: "Write a haiku about Cloudflare"

The script uses a 30-second timeout with the Prefer: wait header, which tells Replicate to keep the connection open and wait for the model to complete, rather than returning immediately with a prediction ID.

How it works

The script:

  1. Loads environment variables from .env
  2. Validates required credentials are present
  3. Constructs the Cloudflare AI Gateway endpoint for the ai-gateway-ziki gateway
  4. Makes a POST request to create a prediction with the Claude 4.5 Haiku model
  5. Uses standard Replicate authentication with Authorization: Bearer header
  6. Includes Prefer: wait header to get synchronous responses
  7. Routes the request through Cloudflare AI Gateway for monitoring and caching

Endpoint Format

https://gateway.ai.cloudflare.com/v1/{account_id}/ai-gateway-ziki/replicate/predictions

Example Response

The script will output the JSON response from Replicate, which includes the model's completion when using Prefer: wait.

Languages