← Back
Cloudflare
Cloudflare launches REST API endpoints for AI Search with OpenAI-compatible format
Cloudflare · apifeaturereleaseintegration · developers.cloudflare.com ↗

New AI Search REST API Endpoints

Cloudflare has released two new REST API endpoints for its AI Search service, bringing OpenAI-compatible REST interfaces to its search and chat capabilities:

  • Chat Completions: POST /accounts/{account_id}/ai-search/instances/{name}/chat/completions
  • Search: POST /accounts/{account_id}/ai-search/instances/{name}/search

OpenAI-Compatible Format

Both endpoints use the familiar OpenAI messages array structure, enabling seamless integration with existing OpenAI SDKs and tooling. The messages array format allows developers to pass previous messages within a session, enabling the model to maintain context across multiple conversation turns.

Example Usage

A Chat Completions request follows standard OpenAI conventions:

curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/instances/{NAME}/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {API_TOKEN}" \
  -d '{
    "messages": [
      {"role": "system", "content": "You are a helpful documentation assistant."},
      {"role": "user", "content": "How do I get started?"}
    ]
  }'

Migration Guidance

Developers currently using the previous AutoRAG API endpoints (/autorag/rags/) should plan to migrate to these new endpoints. The legacy endpoints remain fully supported, but Cloudflare recommends transitioning to the new REST API for improved compatibility and future-proofed integrations. A detailed migration guide is available in the documentation.