Skip to content

Evaluation API

Last updated View as MarkdownAgent setup

Use the evaluation API when you cannot use the Workers binding. The API accepts query parameters or a JSON request body.

Send scalar query context

The GET endpoint accepts context attributes as query parameters. Use it for scalar context values.

Flagship coerces unambiguous number and boolean query values. For example, 42 becomes a number and true becomes a boolean. Other values remain strings.

JSON-looking query values remain strings. A value such as {"plan":"enterprise"} does not create a nested object.

Send structured JSON context

Use POST to send nested objects, arrays, or null. The following request evaluates new-checkout with structured context:

Required API token permissions

At least one of the following token permissions is required:
  • Flagship Read
  • Flagship Write
  • Flagship Evaluate
Evaluate flag with JSON contextbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/flagship/apps/$APP_ID/evaluate" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"flagKey": "new-checkout",
		"context": {
				"targetingKey": "user-42",
				"profile": {
						"plan": "enterprise"
				},
				"tags": [
						"beta"
				]
		}
	}'

The POST response contains the same fields as GET:

{
	"flagKey": "new-checkout",
	"value": true,
	"variant": "on",
	"reason": "TARGETING_MATCH"
}

Invalid context returns a 400 response. Refer to Limits and evaluation error codes for details.

Was this helpful?