This tutorial guides you through creating your first AI Gateway using Workers AI on the Cloudflare dashboard. The intended audience is beginners who are new to AI Gateway and Workers AI. Creating an AI Gateway enables the user to efficiently manage and secure AI requests, allowing them to utilize AI models for tasks such as content generation, data processing, or predictive analysis with enhanced control and performance.
Sign up and log in
Sign up: If you do not have a Cloudflare account, sign up ↗.
Using that API token and Account ID, send a POST request to the Cloudflare API.
Connect Your AI Provider
In the AI Gateway section, select the gateway you created.
Select Workers AI as your provider to set up an endpoint specific to Workers AI.
You will receive an endpoint URL for sending requests.
Configure Your Workers AI
Go to AI > Workers AI in the Cloudflare dashboard.
Select Use REST API and follow the steps to create and copy the API token and Account ID.
Send Requests to Workers AI: Use the provided API endpoint. For example, you can run a model via the API using a curl command. Replace {account_id}, {gateway_id} and {cf_api_token} with your actual account ID and API token:
The expected output would be similar to :
View Analytics
Monitor your AI Gateway to view usage metrics.
Go to AI > AI Gateway in the dashboard.
Select your gateway to view metrics such as request counts, token usage, caching efficiency, errors, and estimated costs. You can also turn on additional configurations like logging and rate limiting.
If you have any questions, need assistance, or would like to share your project, join the Cloudflare Developer community on Discord ↗ to connect with other developers and the Cloudflare team.