Overview
Access the AI Gateway API:Gateways
Manage AI Gateway instances.Create a gateway
Create a new AI Gateway.string
required
Your Cloudflare account ID
string
required
Gateway identifier (used in API calls)
number
Cache time-to-live in seconds (null to disable caching)
boolean
required
Invalidate cache when gateway is updated
boolean
required
Enable request/response logging
number
Rate limit window in seconds (null to disable)
number
Maximum requests per interval (null to disable)
string
required
Rate limiting algorithm: ‘fixed’ or ‘sliding’
string
The gateway ID
string
Your account ID
string
ISO 8601 timestamp when the gateway was created
string
ISO 8601 timestamp when the gateway was last modified
List gateways
Retrieve all AI Gateways in your account.string
required
Your Cloudflare account ID
string
Filter gateways by ID
number
Page number for pagination
number
Number of gateways per page
Get a gateway
Retrieve details about a specific gateway.string
required
The gateway ID
string
required
Your Cloudflare account ID
Update a gateway
Update gateway configuration.string
required
The gateway ID to update
string
required
Your Cloudflare account ID
Delete a gateway
Delete an AI Gateway.string
required
The gateway ID to delete
string
required
Your Cloudflare account ID
Logs
Manage and query AI Gateway request logs.List logs
Retrieve logs for a gateway.string
required
The gateway ID
string
required
Your Cloudflare account ID
string
Start date for logs (ISO 8601)
string
End date for logs (ISO 8601)
number
Page number for pagination
number
Number of logs per page
Get a log entry
Retrieve a specific log entry.string
The log entry ID
string
ISO 8601 timestamp of the request
string
AI provider (e.g., ‘openai’, ‘anthropic’)
string
Model used for the request
number
HTTP status code
boolean
Whether the response was served from cache
number
Request duration in milliseconds
Get log request
Retrieve the request payload for a log entry.Get log response
Retrieve the response payload for a log entry.Delete logs
Delete logs for a gateway.string
Delete logs before this date (ISO 8601)
Datasets
Manage datasets for AI model evaluation.Create a dataset
string
required
The gateway ID
string
required
Your Cloudflare account ID
string
required
Dataset name
array
required
Array of test cases with input and expected output
List datasets
Get a dataset
Update a dataset
Delete a dataset
Evaluations
Run model evaluations using datasets.Create an evaluation
string
required
The gateway ID
string
required
Your Cloudflare account ID
string
required
Dataset to evaluate against
string
required
Evaluation metric type
List evaluations
Get an evaluation
string
Evaluation ID
string
Evaluation status: ‘pending’, ‘running’, or ‘complete’
number
Evaluation score (0-1)
array
Detailed results per test case
Using AI Gateway
With OpenAI SDK
With Workers AI
Best practices
- Caching: Enable caching for repeated queries to reduce costs and latency
- Rate limiting: Set appropriate rate limits to control costs
- Logging: Enable logging for debugging and analytics
- Monitoring: Regularly review logs and analytics for usage patterns
- Security: Use authentication to protect your gateway from unauthorized access
- Cost control: Set up alerts for spending thresholds