Skip to main content
POST /declare takes the declaration fields of decide and applies them to an element, creating or superseding its experiment exactly as a secret-key decide would, without a user, a decision or any serving. Full field reference: the endpoint.

When to use it

  • Before browser traffic. A publishable key can only decide for an element that already has a live experiment; declare is how a setup script or a deploy step provisions it, with no invented user.
  • Setup separate from serving. When configuration lives with your release process and the serving code should carry nothing but the element name and the user.
  • Review-driven change. A declaration change that supersedes an experiment is deliberate; making it in one place, on purpose, is easier to review than finding it in a request builder.
Inline declaration on decide remains fully supported; both paths run the same validation and the same transaction. Use whichever fits how your configuration is managed, and use only one of them per element, so the two never disagree.

Rules

  • Secret keys only. A publishable key gets a 403 with Declare requires a secret key.
  • user_id, identifiers, attributes, context and idempotency_key are a 400 here: there is no user and no decision to attach them to. There is no batch form; declare each element with its own call.
  • Idempotent: an identical declaration changes nothing and returns the current experiment, so a deploy step can run it on every release. A declaration-class change supersedes through the normal chain; a mutable change applies in place; see Declarations.
  • warnings appears only when there is something to say, with the same codes as decide, for example a declared arm skipped for failing validation.

In a deploy step

declare() throws a CuriousError on failure, so a bad declaration fails the deploy rather than reaching production. Run it with the test key in staging and the live key in production, and send the same declaration from both. Test and live keys configure the same element and experiment, so a staging declaration that changes a declaration-class field supersedes the experiment live traffic is served from. See Test with test keys. If a new experiment appears that you did not mean to start, see The experiment restarted. A field the API does not recognize is a 400; see A request is rejected for an unknown field.