Cloudflare Enablement
Workers AI
Testing
Edit this page on GitHub
Set theme to dark (⇧+D)

Get started with the Workers AI 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).

​​ Prerequisites

Sign up for a Cloudflare account if you have not already.

​​ 1. Get an API token

To create an API token:

  1. Log in to the Cloudflare dashboard .
  2. Select the user icon on the top right of your dashboard > My Profile.
  3. Select API Tokens > Create Token.
  4. Go to the Workers AI template > select Use template. You can also go to Create Custom Token > Get started to customize a token.
  5. Select Continue to summary > in the Workers AI API token summary, select Create Token.

​​ 2. Run a model via API

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 @cloudflare/meta-llama/llama-2-7b-chat-int8 model:

Replace {ACCOUNT_ID} with your account ID and {API_token} with the API token you generated in step 1.

The API response will look like the following:

This example execution uses the @cf/meta/llama-2-7b-chat-int8 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 @cloudflare/meta-llama/llama-2-7b-chat-int8 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.