REST API
This guide will instruct you through setting up and deploying your first Workers AI project. You will use the Workers AI REST API to experiment with a large language model (LLM).
Sign up for a Cloudflare account ↗ if you have not already.
You need your API token and Account ID to use the REST API.
To get these values:
- Log in to the Cloudflare dashboard ↗ and select your account.
- Go to AI > Workers AI.
- Select Use REST API.
- Get your API token:
- Select Create a Workers AI API Token.
- Review the prefilled information.
- Select Create API Token.
- Select Copy API Token.
- Save that value for future use.
- For Get Account ID, copy the value for Account ID. Save that value for future use.
After creating your API token, authenticate and make requests to the API using your API token in the request.
You will use the Execute AI model endpoint to run the @cf/meta/llama-3.1-8b-instruct
model:
Replace the values for {ACCOUNT_ID}
and {API_token}
.
The API response will look like the following:
This example execution uses the @cf/meta/llama-3.1-8b-instruct
model, but you can use any of the models in the Workers AI models catalog. If using another model, you will need to replace {model}
with your desired model name.
By completing this guide, you have created a Cloudflare account (if you did not have one already) and an API token that grants Workers AI read permissions to your account. You executed the @cf/meta/llama-3.1-8b-instruct
model using a cURL command from the terminal and received an answer to your prompt in a JSON response.
- Models - Browse the Workers AI models catalog.