For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • REST API overview
    • Access Tokens
    • Account Members
    • Account Usage Beta
    • AI Configs
      • POSTAdd AI models to the restricted list
      • POSTCreate a prompt snippet
      • POSTCreate agent optimization
      • POSTCreate agent optimization result
      • POSTCreate AI Config variation
      • POSTCreate an AI model config
      • POSTCreate an AI tool
      • POSTCreate new agent graph
      • POSTCreate new AI Config
      • DELDelete a prompt snippet
      • DELDelete agent graph
      • DELDelete AI Config
      • DELDelete AI Config variation
      • DELDelete AI tool
      • DELDelete an agent optimization
      • DELDelete an AI model config
      • GETGet a prompt snippet
      • GETGet agent graph
      • GETGet AI Config
      • GETGet AI Config metrics
      • GETGet AI Config metrics by variation
      • GETGet AI Config quick stats
      • GETGet AI Config variation
      • GETGet AI model config
      • GETGet AI tool
      • GETGet an agent optimization
      • GETList agent graphs
      • GETList agent optimization results for a run
      • GETList agent optimization runs
      • GETList agent optimization runs
      • GETList agent optimizations
      • GETList AI Configs
      • GETList AI model configs
      • GETList AI tool references
      • GETList AI tool versions
      • GETList AI tools
      • GETList all agent optimization results across versions
      • GETList prompt snippet references
      • GETList prompt snippet versions
      • GETList prompt snippets
      • DELRemove AI models from the restricted list
      • GETShow an AI Config's targeting
      • PATCHUpdate a prompt snippet
      • PATCHUpdate agent graph
      • PATCHUpdate AI Config
      • PATCHUpdate AI Config targeting
      • PATCHUpdate AI Config variation
      • PATCHUpdate AI tool
      • PATCHUpdate an agent optimization
      • PATCHUpdate an agent optimization result
    • Announcements
    • Applications Beta
    • Approvals
    • Approvals Beta
    • Audit Log
    • Code References
    • Contexts
    • Context Settings
    • Custom Roles
    • Data Export Destinations
    • Environments
    • Experiments
    • Feature Flags
    • Feature Flags Beta
    • Flag Import Configurations Beta
    • Flag Links Beta
    • Flag Triggers
    • Follow Flags
    • Holdouts Beta
    • Insights Charts Beta
    • Insights Deployments Beta
    • Insights Flag Events Beta
    • Insights Pull Requests Beta
    • Insights Repositories Beta
    • Insights Scores Beta
    • Integration Audit Log Subscriptions
    • Integration Delivery Configurations Beta
    • Integrations Beta
    • Layers
    • Metrics
    • Metrics Beta
    • OAuth2 Clients
    • Persistent Store Integrations Beta
    • Projects
    • Relay Proxy Configurations
    • Release Pipelines Beta
    • Releases Beta
    • Scheduled Changes
    • Segments
    • Tags
    • Teams
    • Teams Beta
    • Users
    • Users Beta
    • User Settings
    • Views Beta
    • Webhooks
    • Workflows
    • Workflow Templates
    • Other
Sign inTry it free
LogoLogo
REST API overviewAI Configs

Update AI Config targeting

PATCH
/api/v2/projects/:projectKey/ai-configs/:configKey/targeting
PATCH
/api/v2/projects/:projectKey/ai-configs/:configKey/targeting
$curl -X PATCH https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/targeting \
> -H "Authorization: <apiKey>" \
> -H "Content-Type: application/json" \
> -d '{
> "environmentKey": "environmentKey",
> "instructions": [
> {
> "key": ""
> },
> {
> "key": ""
> }
> ],
> "comment": "comment"
>}'
1{
2 "createdAt": 0,
3 "environments": {
4 "key": {
5 "contextTargets": [
6 {
7 "contextKind": "contextKind",
8 "values": [
9 "values",
10 "values"
11 ],
12 "variation": 5
13 },
14 {
15 "contextKind": "contextKind",
16 "values": [
17 "values",
18 "values"
19 ],
20 "variation": 5
21 }
22 ],
23 "enabled": true,
24 "fallthrough": {
25 "variation": 5,
26 "rollout": {
27 "contextKind": "contextKind",
28 "variations": [
29 {
30 "variation": 9,
31 "weight": 3,
32 "_untracked": true
33 },
34 {
35 "variation": 9,
36 "weight": 3,
37 "_untracked": true
38 }
39 ],
40 "bucketBy": "bucketBy",
41 "experimentAllocation": {
42 "canReshuffle": true,
43 "defaultVariation": 2,
44 "type": "type"
45 },
46 "seed": 7
47 }
48 },
49 "lastModified": 2,
50 "rules": [
51 {
52 "clauses": [
53 {
54 "attribute": "attribute",
55 "id": "id",
56 "negate": true,
57 "op": "op",
58 "values": [
59 "",
60 ""
61 ]
62 },
63 {
64 "attribute": "attribute",
65 "id": "id",
66 "negate": true,
67 "op": "op",
68 "values": [
69 "",
70 ""
71 ]
72 }
73 ],
74 "trackEvents": true
75 },
76 {
77 "clauses": [
78 {
79 "attribute": "attribute",
80 "id": "id",
81 "negate": true,
82 "op": "op",
83 "values": [
84 "",
85 ""
86 ]
87 },
88 {
89 "attribute": "attribute",
90 "id": "id",
91 "negate": true,
92 "op": "op",
93 "values": [
94 "",
95 ""
96 ]
97 }
98 ],
99 "trackEvents": true
100 }
101 ],
102 "targets": [
103 {
104 "contextKind": "contextKind",
105 "values": [
106 "values",
107 "values"
108 ],
109 "variation": 5
110 },
111 {
112 "contextKind": "contextKind",
113 "values": [
114 "values",
115 "values"
116 ],
117 "variation": 5
118 }
119 ],
120 "trackEvents": true,
121 "trackEventsFallthrough": true,
122 "_environmentName": "_environmentName",
123 "_version": 7,
124 "offVariation": 4
125 }
126 },
127 "experiments": {
128 "baselineIdx": 1,
129 "items": [
130 {
131 "metricKey": "my-metric",
132 "_metric": {
133 "_id": "5902deadbeef667524a01290",
134 "_versionId": "version-id-123abc",
135 "key": "metric-key-123abc",
136 "name": "My metric",
137 "kind": "custom",
138 "_links": {
139 "parent": {
140 "href": "/api/v2/metrics/my-project",
141 "type": "application/json"
142 },
143 "self": {
144 "href": "/api/v2/metrics/my-project/my-metric",
145 "type": "application/json"
146 }
147 },
148 "tags": [],
149 "_creationDate": 1,
150 "dataSource": {
151 "key": "key",
152 "environmentKey": "environmentKey",
153 "_name": "_name",
154 "_integrationKey": "_integrationKey"
155 },
156 "experimentCount": 0,
157 "metricGroupCount": 0,
158 "guardedRolloutCount": 0,
159 "releasePolicyCount": 0,
160 "activeExperimentCount": 2,
161 "activeGuardedRolloutCount": 1,
162 "_version": 1,
163 "_attachedFlagCount": 0,
164 "_site": {
165 "href": "href",
166 "type": "type"
167 },
168 "_access": {
169 "denied": [
170 {
171 "action": "action",
172 "reason": {
173 "effect": "allow",
174 "resources": [
175 "proj/*:env/*;qa_*:/flag/*"
176 ],
177 "notResources": [
178 "notResources",
179 "notResources"
180 ],
181 "actions": [
182 "*"
183 ],
184 "notActions": [
185 "string",
186 "string"
187 ],
188 "role_name": "role_name"
189 }
190 },
191 {
192 "action": "action",
193 "reason": {
194 "effect": "allow",
195 "resources": [
196 "proj/*:env/*;qa_*:/flag/*"
197 ],
198 "notResources": [
199 "notResources",
200 "notResources"
201 ],
202 "actions": [
203 "*"
204 ],
205 "notActions": [
206 "string",
207 "string"
208 ],
209 "role_name": "role_name"
210 }
211 }
212 ],
213 "allowed": [
214 {
215 "action": "action",
216 "reason": {
217 "effect": "allow",
218 "resources": [
219 "proj/*:env/*;qa_*:/flag/*"
220 ],
221 "notResources": [
222 "notResources",
223 "notResources"
224 ],
225 "actions": [
226 "*"
227 ],
228 "notActions": [
229 "string",
230 "string"
231 ],
232 "role_name": "role_name"
233 }
234 },
235 {
236 "action": "action",
237 "reason": {
238 "effect": "allow",
239 "resources": [
240 "proj/*:env/*;qa_*:/flag/*"
241 ],
242 "notResources": [
243 "notResources",
244 "notResources"
245 ],
246 "actions": [
247 "*"
248 ],
249 "notActions": [
250 "string",
251 "string"
252 ],
253 "role_name": "role_name"
254 }
255 }
256 ]
257 },
258 "lastModified": {
259 "date": "2021-08-05T19:46:31.148Z"
260 },
261 "maintainerId": "569fdeadbeef1644facecafe",
262 "_maintainer": {
263 "_links": {
264 "self": {
265 "href": "/api/v2/members/569f183514f4432160000007",
266 "type": "application/json"
267 }
268 },
269 "_id": "569f183514f4432160000007",
270 "role": "admin",
271 "email": "ariel@acme.com",
272 "firstName": "Ariel",
273 "lastName": "Flores"
274 },
275 "description": "description",
276 "category": "Error monitoring",
277 "isNumeric": true,
278 "successCriteria": "HigherThanBaseline",
279 "unit": "unit",
280 "eventKey": "Order placed",
281 "analysisUnits": [
282 "user"
283 ],
284 "filters": {
285 "type": "contextAttribute",
286 "op": "op",
287 "values": [
288 "JP"
289 ],
290 "negate": false,
291 "attribute": "country",
292 "contextKind": "user"
293 },
294 "unitAggregationType": "average",
295 "analysisType": "mean",
296 "percentileValue": 95,
297 "eventDefault": {
298 "disabled": true,
299 "value": 0
300 },
301 "lastSeen": 1,
302 "archived": true,
303 "archivedAt": 6,
304 "selector": "selector",
305 "urls": [
306 {},
307 {}
308 ],
309 "windowStartOffset": 7,
310 "windowEndOffset": 1,
311 "winsorLowerPercentile": 1,
312 "winsorUpperPercentile": 99.5,
313 "winsorExcludeImputed": false,
314 "traceQuery": "service.name = \"checkout\"",
315 "traceValueLocation": "duration",
316 "randomizationUnits": [
317 "user"
318 ]
319 },
320 "environments": [
321 "production",
322 "test",
323 "my-environment"
324 ],
325 "_environmentSettings": {
326 "key": {
327 "startDate": 4,
328 "stopDate": 5,
329 "enabledPeriods": [
330 {
331 "startDate": 9,
332 "stopDate": 9
333 },
334 {
335 "startDate": 9,
336 "stopDate": 9
337 }
338 ]
339 }
340 }
341 },
342 {
343 "metricKey": "my-metric",
344 "_metric": {
345 "_id": "5902deadbeef667524a01290",
346 "_versionId": "version-id-123abc",
347 "key": "metric-key-123abc",
348 "name": "My metric",
349 "kind": "custom",
350 "_links": {
351 "parent": {
352 "href": "/api/v2/metrics/my-project",
353 "type": "application/json"
354 },
355 "self": {
356 "href": "/api/v2/metrics/my-project/my-metric",
357 "type": "application/json"
358 }
359 },
360 "tags": [],
361 "_creationDate": 1,
362 "dataSource": {
363 "key": "key",
364 "environmentKey": "environmentKey",
365 "_name": "_name",
366 "_integrationKey": "_integrationKey"
367 },
368 "experimentCount": 0,
369 "metricGroupCount": 0,
370 "guardedRolloutCount": 0,
371 "releasePolicyCount": 0,
372 "activeExperimentCount": 2,
373 "activeGuardedRolloutCount": 1,
374 "_version": 1,
375 "_attachedFlagCount": 0,
376 "_site": {
377 "href": "href",
378 "type": "type"
379 },
380 "_access": {
381 "denied": [
382 {
383 "action": "action",
384 "reason": {
385 "effect": "allow",
386 "resources": [
387 "proj/*:env/*;qa_*:/flag/*"
388 ],
389 "notResources": [
390 "notResources",
391 "notResources"
392 ],
393 "actions": [
394 "*"
395 ],
396 "notActions": [
397 "string",
398 "string"
399 ],
400 "role_name": "role_name"
401 }
402 },
403 {
404 "action": "action",
405 "reason": {
406 "effect": "allow",
407 "resources": [
408 "proj/*:env/*;qa_*:/flag/*"
409 ],
410 "notResources": [
411 "notResources",
412 "notResources"
413 ],
414 "actions": [
415 "*"
416 ],
417 "notActions": [
418 "string",
419 "string"
420 ],
421 "role_name": "role_name"
422 }
423 }
424 ],
425 "allowed": [
426 {
427 "action": "action",
428 "reason": {
429 "effect": "allow",
430 "resources": [
431 "proj/*:env/*;qa_*:/flag/*"
432 ],
433 "notResources": [
434 "notResources",
435 "notResources"
436 ],
437 "actions": [
438 "*"
439 ],
440 "notActions": [
441 "string",
442 "string"
443 ],
444 "role_name": "role_name"
445 }
446 },
447 {
448 "action": "action",
449 "reason": {
450 "effect": "allow",
451 "resources": [
452 "proj/*:env/*;qa_*:/flag/*"
453 ],
454 "notResources": [
455 "notResources",
456 "notResources"
457 ],
458 "actions": [
459 "*"
460 ],
461 "notActions": [
462 "string",
463 "string"
464 ],
465 "role_name": "role_name"
466 }
467 }
468 ]
469 },
470 "lastModified": {
471 "date": "2021-08-05T19:46:31.148Z"
472 },
473 "maintainerId": "569fdeadbeef1644facecafe",
474 "_maintainer": {
475 "_links": {
476 "self": {
477 "href": "/api/v2/members/569f183514f4432160000007",
478 "type": "application/json"
479 }
480 },
481 "_id": "569f183514f4432160000007",
482 "role": "admin",
483 "email": "ariel@acme.com",
484 "firstName": "Ariel",
485 "lastName": "Flores"
486 },
487 "description": "description",
488 "category": "Error monitoring",
489 "isNumeric": true,
490 "successCriteria": "HigherThanBaseline",
491 "unit": "unit",
492 "eventKey": "Order placed",
493 "analysisUnits": [
494 "user"
495 ],
496 "filters": {
497 "type": "contextAttribute",
498 "op": "op",
499 "values": [
500 "JP"
501 ],
502 "negate": false,
503 "attribute": "country",
504 "contextKind": "user"
505 },
506 "unitAggregationType": "average",
507 "analysisType": "mean",
508 "percentileValue": 95,
509 "eventDefault": {
510 "disabled": true,
511 "value": 0
512 },
513 "lastSeen": 1,
514 "archived": true,
515 "archivedAt": 6,
516 "selector": "selector",
517 "urls": [
518 {},
519 {}
520 ],
521 "windowStartOffset": 7,
522 "windowEndOffset": 1,
523 "winsorLowerPercentile": 1,
524 "winsorUpperPercentile": 99.5,
525 "winsorExcludeImputed": false,
526 "traceQuery": "service.name = \"checkout\"",
527 "traceValueLocation": "duration",
528 "randomizationUnits": [
529 "user"
530 ]
531 },
532 "environments": [
533 "production",
534 "test",
535 "my-environment"
536 ],
537 "_environmentSettings": {
538 "key": {
539 "startDate": 4,
540 "stopDate": 5,
541 "enabledPeriods": [
542 {
543 "startDate": 9,
544 "stopDate": 9
545 },
546 {
547 "startDate": 9,
548 "stopDate": 9
549 }
550 ]
551 }
552 }
553 }
554 ]
555 },
556 "key": "key",
557 "name": "name",
558 "tags": [
559 "tags",
560 "tags"
561 ],
562 "variations": [
563 {
564 "_id": "_id",
565 "description": "description",
566 "name": "name",
567 "value": {}
568 },
569 {
570 "_id": "_id",
571 "description": "description",
572 "name": "name",
573 "value": {}
574 }
575 ],
576 "_version": 6,
577 "defaults": {
578 "onVariation": 6,
579 "offVariation": 1
580 }
581}
Perform a partial update to an AI Config's targeting. The request body must be a valid semantic patch. ### Using semantic patches on an AI Config To make a semantic patch request, you must append `domain-model=launchdarkly.semanticpatch` to your `Content-Type` header. To learn more, read [Updates using semantic patch](https://launchdarkly.com/docs/api#updates-using-semantic-patch). The body of a semantic patch request for updating an AI Config's targeting takes the following properties: * `comment` (string): (Optional) A description of the update. * `environmentKey` (string): The key of the LaunchDarkly environment. * `instructions` (array): (Required) A list of actions the update should perform. Each action in the list must be an object with a `kind` property that indicates the instruction. If the action requires parameters, you must include those parameters as additional fields in the object. The body of a single semantic patch can contain many different instructions. ### Instructions Semantic patch requests support the following `kind` instructions for updating AI Configs. <details> <summary>Click to expand instructions for <strong>working with targeting and variations</strong> for AI Configs</summary> #### addClauses Adds the given clauses to the rule indicated by `ruleId`. ##### Parameters - `ruleId`: ID of a rule in the AI Config. - `clauses`: Array of clause objects, with `contextKind` (string), `attribute` (string), `op` (string), `negate` (boolean), and `values` (array of strings, numbers, or dates) properties. The `contextKind`, `attribute`, and `values` are case sensitive. The `op` must be lower-case. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "addClauses", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29", "clauses": [{ "contextKind": "user", "attribute": "country", "op": "in", "negate": false, "values": ["USA", "Canada"] }] }] } ``` #### addRule Adds a new targeting rule to the AI Config. The rule may contain `clauses` and serve the variation that `variationId` indicates, or serve a percentage rollout that `rolloutWeights`, `rolloutBucketBy`, and `rolloutContextKind` indicate. If you set `beforeRuleId`, this adds the new rule before the indicated rule. Otherwise, adds the new rule to the end of the list. ##### Parameters - `clauses`: Array of clause objects, with `contextKind` (string), `attribute` (string), `op` (string), `negate` (boolean), and `values` (array of strings, numbers, or dates) properties. The `contextKind`, `attribute`, and `values` are case sensitive. The `op` must be lower-case. - `beforeRuleId`: (Optional) ID of a rule. - Either - `variationId`: ID of a variation. or - `rolloutWeights`: (Optional) Map of `variationId` to weight, in thousandths of a percent (0-100000). - `rolloutBucketBy`: (Optional) Context attribute available in the specified `rolloutContextKind`. - `rolloutContextKind`: (Optional) Context kind, defaults to `user` Here's an example that uses a `variationId`: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "addRule", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00", "clauses": [{ "contextKind": "organization", "attribute": "located_in", "op": "in", "negate": false, "values": ["Sweden", "Norway"] }] }] } ``` Here's an example that uses a percentage rollout: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "addRule", "clauses": [{ "contextKind": "organization", "attribute": "located_in", "op": "in", "negate": false, "values": ["Sweden", "Norway"] }], "rolloutContextKind": "organization", "rolloutWeights": { "2f43f67c-3e4e-4945-a18a-26559378ca00": 15000, // serve 15% this variation "e5830889-1ec5-4b0c-9cc9-c48790090c43": 85000 // serve 85% this variation } }] } ``` #### addTargets Adds context keys to the individual context targets for the context kind that `contextKind` specifies and the variation that `variationId` specifies. Returns an error if this causes the AI Config to target the same context key in multiple variations. ##### Parameters - `values`: List of context keys. - `contextKind`: (Optional) Context kind to target, defaults to `user` - `variationId`: ID of a variation. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "addTargets", "values": ["context-key-123abc", "context-key-456def"], "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" }] } ``` #### addValuesToClause Adds `values` to the values of the clause that `ruleId` and `clauseId` indicate. Does not update the context kind, attribute, or operator. ##### Parameters - `ruleId`: ID of a rule in the AI Config. - `clauseId`: ID of a clause in that rule. - `values`: Array of strings, case sensitive. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "addValuesToClause", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29", "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed", "values": ["beta_testers"] }] } ``` #### clearTargets Removes all individual targets from the variation that `variationId` specifies. This includes both user and non-user targets. ##### Parameters - `variationId`: ID of a variation. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [ { "kind": "clearTargets", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" } ] } ``` #### removeClauses Removes the clauses specified by `clauseIds` from the rule indicated by `ruleId`. ##### Parameters - `ruleId`: ID of a rule. - `clauseIds`: Array of IDs of clauses in the rule. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "removeClauses", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29", "clauseIds": ["10a58772-3121-400f-846b-b8a04e8944ed", "36a461dc-235e-4b08-97b9-73ce9365873e"] }] } ``` #### removeRule Removes the targeting rule specified by `ruleId`. Does nothing if the rule does not exist. ##### Parameters - `ruleId`: ID of a rule. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [ { "kind": "removeRule", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29" } ] } ``` #### removeTargets Removes context keys from the individual context targets for the context kind that `contextKind` specifies and the variation that `variationId` specifies. Does nothing if the flag does not target the context keys. ##### Parameters - `values`: List of context keys. - `contextKind`: (Optional) Context kind to target, defaults to `user` - `variationId`: ID of a variation. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "removeTargets", "values": ["context-key-123abc", "context-key-456def"], "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" }] } ``` #### removeValuesFromClause Removes `values` from the values of the clause indicated by `ruleId` and `clauseId`. Does not update the context kind, attribute, or operator. ##### Parameters - `ruleId`: ID of a rule. - `clauseId`: ID of a clause in that rule. - `values`: Array of strings, case sensitive. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "removeValuesFromClause", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29", "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed", "values": ["beta_testers"] }] } ``` #### reorderRules Rearranges the rules to match the order given in `ruleIds`. Returns an error if `ruleIds` does not match the current set of rules on the AI Config. ##### Parameters - `ruleIds`: Array of IDs of all rules. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "reorderRules", "ruleIds": ["a902ef4a-2faf-4eaf-88e1-ecc356708a29", "63c238d1-835d-435e-8f21-c8d5e40b2a3d"] }] } ``` #### replaceRules Removes all targeting rules for the AI Config and replaces them with the list you provide. ##### Parameters - `rules`: A list of rules. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [ { "kind": "replaceRules", "rules": [ { "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00", "description": "My new rule", "clauses": [ { "contextKind": "user", "attribute": "segmentMatch", "op": "segmentMatch", "values": ["test"] } ] } ] } ] } ``` #### replaceTargets Removes all existing targeting and replaces it with the list of targets you provide. ##### Parameters - `targets`: A list of context targeting. Each item in the list includes an optional `contextKind` that defaults to `user`, a required `variationId`, and a required list of `values`. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [ { "kind": "replaceTargets", "targets": [ { "contextKind": "user", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00", "values": ["user-key-123abc"] }, { "contextKind": "device", "variationId": "e5830889-1ec5-4b0c-9cc9-c48790090c43", "values": ["device-key-456def"] } ] } ] } ``` #### updateClause Replaces the clause indicated by `ruleId` and `clauseId` with `clause`. ##### Parameters - `ruleId`: ID of a rule. - `clauseId`: ID of a clause in that rule. - `clause`: New `clause` object, with `contextKind` (string), `attribute` (string), `op` (string), `negate` (boolean), and `values` (array of strings, numbers, or dates) properties. The `contextKind`, `attribute`, and `values` are case sensitive. The `op` must be lower-case. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "updateClause", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29", "clauseId": "10c7462a-2062-45ba-a8bb-dfb3de0f8af5", "clause": { "contextKind": "user", "attribute": "country", "op": "in", "negate": false, "values": ["Mexico", "Canada"] } }] } ``` #### updateDefaultVariation Updates the default on or off variation of the AI Config. ##### Parameters - `onVariationValue`: (Optional) The value of the variation of the new on variation. - `offVariationValue`: (Optional) The value of the variation of the new off variation Here's an example: ```json { "instructions": [ { "kind": "updateDefaultVariation", "OnVariationValue": true, "OffVariationValue": false } ] } ``` #### updateFallthroughVariationOrRollout Updates the default or "fallthrough" rule for the AI Config, which the AI Config serves when a context matches none of the targeting rules. The rule can serve either the variation that `variationId` indicates, or a percentage rollout that `rolloutWeights` and `rolloutBucketBy` indicate. ##### Parameters - `variationId`: ID of a variation. or - `rolloutWeights`: Map of `variationId` to weight, in thousandths of a percent (0-100000). - `rolloutBucketBy`: (Optional) Context attribute available in the specified `rolloutContextKind`. - `rolloutContextKind`: (Optional) Context kind, defaults to `user` Here's an example that uses a `variationId`: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "updateFallthroughVariationOrRollout", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" }] } ``` Here's an example that uses a percentage rollout: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "updateFallthroughVariationOrRollout", "rolloutContextKind": "user", "rolloutWeights": { "2f43f67c-3e4e-4945-a18a-26559378ca00": 15000, // serve 15% this variation "e5830889-1ec5-4b0c-9cc9-c48790090c43": 85000 // serve 85% this variation } }] } ``` #### updateOffVariation Updates the default off variation to `variationId`. The AI Config serves the default off variation when the AI Config's targeting is **Off**. ##### Parameters - `variationId`: ID of a variation. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [ { "kind": "updateOffVariation", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" } ] } ``` #### updateRuleDescription Updates the description of the targeting rule. ##### Parameters - `description`: The new human-readable description for this rule. - `ruleId`: The ID of the rule. You can retrieve this by making a GET request for the AI Config. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "updateRuleDescription", "description": "New rule description", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29" }] } ``` #### updateRuleTrackEvents Updates whether or not LaunchDarkly tracks events for the AI Config associated with this rule. ##### Parameters - `ruleId`: The ID of the rule. You can retrieve this by making a GET request for the AI Config. - `trackEvents`: Whether or not events are tracked. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "updateRuleTrackEvents", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29", "trackEvents": true }] } ``` #### updateRuleVariationOrRollout Updates what `ruleId` serves when its clauses evaluate to true. The rule can serve either the variation that `variationId` indicates, or a percent rollout that `rolloutWeights` and `rolloutBucketBy` indicate. ##### Parameters - `ruleId`: ID of a rule. - `variationId`: ID of a variation. or - `rolloutWeights`: Map of `variationId` to weight, in thousandths of a percent (0-100000). - `rolloutBucketBy`: (Optional) Context attribute available in the specified `rolloutContextKind`. - `rolloutContextKind`: (Optional) Context kind, defaults to `user` Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [{ "kind": "updateRuleVariationOrRollout", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" }] } ``` #### updateTrackEvents Updates whether or not LaunchDarkly tracks events for the AI Config, for all rules. ##### Parameters - `trackEvents`: Whether or not events are tracked. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [ { "kind": "updateTrackEvents", "trackEvents": true } ] } ``` #### updateTrackEventsFallthrough Updates whether or not LaunchDarkly tracks events for the AI Config, for the default rule. ##### Parameters - `trackEvents`: Whether or not events are tracked. Here's an example: ```json { "environmentKey": "environment-key-123abc", "instructions": [ { "kind": "updateTrackEventsFallthrough", "trackEvents": true } ] } ``` </details>
Was this page helpful?
Previous

Update AI Config variation

Next
Built with

Perform a partial update to an AI Config’s targeting. The request body must be a valid semantic patch.

Using semantic patches on an AI Config

To make a semantic patch request, you must append domain-model=launchdarkly.semanticpatch to your Content-Type header. To learn more, read Updates using semantic patch.

The body of a semantic patch request for updating an AI Config’s targeting takes the following properties:

  • comment (string): (Optional) A description of the update.
  • environmentKey (string): The key of the LaunchDarkly environment.
  • instructions (array): (Required) A list of actions the update should perform. Each action in the list must be an object with a kind property that indicates the instruction. If the action requires parameters, you must include those parameters as additional fields in the object. The body of a single semantic patch can contain many different instructions.

Instructions

Semantic patch requests support the following kind instructions for updating AI Configs.

Click to expand instructions for working with targeting and variations for AI Configs

addClauses

Adds the given clauses to the rule indicated by ruleId.

Parameters
  • ruleId: ID of a rule in the AI Config.
  • clauses: Array of clause objects, with contextKind (string), attribute (string), op (string), negate (boolean), and values (array of strings, numbers, or dates) properties. The contextKind, attribute, and values are case sensitive. The op must be lower-case.

Here’s an example:

1{
2 "environmentKey": "environment-key-123abc",
3 "instructions": [{
4 "kind": "addClauses",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauses": [{
7 "contextKind": "user",
8 "attribute": "country",
9 "op": "in",
10 "negate": false,
11 "values": ["USA", "Canada"]
12 }]
13 }]
14}

addRule

Adds a new targeting rule to the AI Config. The rule may contain clauses and serve the variation that variationId indicates, or serve a percentage rollout that rolloutWeights, rolloutBucketBy, and rolloutContextKind indicate.

If you set beforeRuleId, this adds the new rule before the indicated rule. Otherwise, adds the new rule to the end of the list.

Parameters
  • clauses: Array of clause objects, with contextKind (string), attribute (string), op (string), negate (boolean), and values (array of strings, numbers, or dates) properties. The contextKind, attribute, and values are case sensitive. The op must be lower-case.
  • beforeRuleId: (Optional) ID of a rule.
  • Either
  • variationId: ID of a variation.

or

  • rolloutWeights: (Optional) Map of variationId to weight, in thousandths of a percent (0-100000).
  • rolloutBucketBy: (Optional) Context attribute available in the specified rolloutContextKind.
  • rolloutContextKind: (Optional) Context kind, defaults to user

Here’s an example that uses a variationId:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "addRule",
5 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00",
6 "clauses": [{
7 "contextKind": "organization",
8 "attribute": "located_in",
9 "op": "in",
10 "negate": false,
11 "values": ["Sweden", "Norway"]
12 }]
13}]
14}

Here’s an example that uses a percentage rollout:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "addRule",
5 "clauses": [{
6 "contextKind": "organization",
7 "attribute": "located_in",
8 "op": "in",
9 "negate": false,
10 "values": ["Sweden", "Norway"]
11 }],
12 "rolloutContextKind": "organization",
13 "rolloutWeights": {
14 "2f43f67c-3e4e-4945-a18a-26559378ca00": 15000, // serve 15% this variation
15 "e5830889-1ec5-4b0c-9cc9-c48790090c43": 85000 // serve 85% this variation
16 }
17}]
18}

addTargets

Adds context keys to the individual context targets for the context kind that contextKind specifies and the variation that variationId specifies. Returns an error if this causes the AI Config to target the same context key in multiple variations.

Parameters
  • values: List of context keys.
  • contextKind: (Optional) Context kind to target, defaults to user
  • variationId: ID of a variation.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "addTargets",
5 "values": ["context-key-123abc", "context-key-456def"],
6 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00"
7}]
8}

addValuesToClause

Adds values to the values of the clause that ruleId and clauseId indicate. Does not update the context kind, attribute, or operator.

Parameters
  • ruleId: ID of a rule in the AI Config.
  • clauseId: ID of a clause in that rule.
  • values: Array of strings, case sensitive.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "addValuesToClause",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
7 "values": ["beta_testers"]
8}]
9}

clearTargets

Removes all individual targets from the variation that variationId specifies. This includes both user and non-user targets.

Parameters
  • variationId: ID of a variation.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "clearTargets", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" } ]
4}

removeClauses

Removes the clauses specified by clauseIds from the rule indicated by ruleId.

Parameters
  • ruleId: ID of a rule.
  • clauseIds: Array of IDs of clauses in the rule.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "removeClauses",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauseIds": ["10a58772-3121-400f-846b-b8a04e8944ed", "36a461dc-235e-4b08-97b9-73ce9365873e"]
7}]
8}

removeRule

Removes the targeting rule specified by ruleId. Does nothing if the rule does not exist.

Parameters
  • ruleId: ID of a rule.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "removeRule", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29" } ]
4}

removeTargets

Removes context keys from the individual context targets for the context kind that contextKind specifies and the variation that variationId specifies. Does nothing if the flag does not target the context keys.

Parameters
  • values: List of context keys.
  • contextKind: (Optional) Context kind to target, defaults to user
  • variationId: ID of a variation.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "removeTargets",
5 "values": ["context-key-123abc", "context-key-456def"],
6 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00"
7}]
8}

removeValuesFromClause

Removes values from the values of the clause indicated by ruleId and clauseId. Does not update the context kind, attribute, or operator.

Parameters
  • ruleId: ID of a rule.
  • clauseId: ID of a clause in that rule.
  • values: Array of strings, case sensitive.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "removeValuesFromClause",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
7 "values": ["beta_testers"]
8}]
9}

reorderRules

Rearranges the rules to match the order given in ruleIds. Returns an error if ruleIds does not match the current set of rules on the AI Config.

Parameters
  • ruleIds: Array of IDs of all rules.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "reorderRules",
5 "ruleIds": ["a902ef4a-2faf-4eaf-88e1-ecc356708a29", "63c238d1-835d-435e-8f21-c8d5e40b2a3d"]
6}]
7}

replaceRules

Removes all targeting rules for the AI Config and replaces them with the list you provide.

Parameters
  • rules: A list of rules.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [
4 {
5 "kind": "replaceRules",
6 "rules": [
7 {
8 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00",
9 "description": "My new rule",
10 "clauses": [
11 {
12 "contextKind": "user",
13 "attribute": "segmentMatch",
14 "op": "segmentMatch",
15 "values": ["test"]
16 }
17 ]
18 }
19 ]
20 }
21]
22}

replaceTargets

Removes all existing targeting and replaces it with the list of targets you provide.

Parameters
  • targets: A list of context targeting. Each item in the list includes an optional contextKind that defaults to user, a required variationId, and a required list of values.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [
4 {
5 "kind": "replaceTargets",
6 "targets": [
7 {
8 "contextKind": "user",
9 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00",
10 "values": ["user-key-123abc"]
11 },
12 {
13 "contextKind": "device",
14 "variationId": "e5830889-1ec5-4b0c-9cc9-c48790090c43",
15 "values": ["device-key-456def"]
16 }
17 ]
18 }
19]
20}

updateClause

Replaces the clause indicated by ruleId and clauseId with clause.

Parameters
  • ruleId: ID of a rule.
  • clauseId: ID of a clause in that rule.
  • clause: New clause object, with contextKind (string), attribute (string), op (string), negate (boolean), and values (array of strings, numbers, or dates) properties. The contextKind, attribute, and values are case sensitive. The op must be lower-case.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateClause",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauseId": "10c7462a-2062-45ba-a8bb-dfb3de0f8af5",
7 "clause": {
8 "contextKind": "user",
9 "attribute": "country",
10 "op": "in",
11 "negate": false,
12 "values": ["Mexico", "Canada"]
13 }
14}]
15}

updateDefaultVariation

Updates the default on or off variation of the AI Config.

Parameters
  • onVariationValue: (Optional) The value of the variation of the new on variation.
  • offVariationValue: (Optional) The value of the variation of the new off variation

Here’s an example:

1{
2"instructions": [ { "kind": "updateDefaultVariation", "OnVariationValue": true, "OffVariationValue": false } ]
3}

updateFallthroughVariationOrRollout

Updates the default or “fallthrough” rule for the AI Config, which the AI Config serves when a context matches none of the targeting rules. The rule can serve either the variation that variationId indicates, or a percentage rollout that rolloutWeights and rolloutBucketBy indicate.

Parameters
  • variationId: ID of a variation.

or

  • rolloutWeights: Map of variationId to weight, in thousandths of a percent (0-100000).
  • rolloutBucketBy: (Optional) Context attribute available in the specified rolloutContextKind.
  • rolloutContextKind: (Optional) Context kind, defaults to user

Here’s an example that uses a variationId:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateFallthroughVariationOrRollout",
5 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00"
6}]
7}

Here’s an example that uses a percentage rollout:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateFallthroughVariationOrRollout",
5 "rolloutContextKind": "user",
6 "rolloutWeights": {
7 "2f43f67c-3e4e-4945-a18a-26559378ca00": 15000, // serve 15% this variation
8 "e5830889-1ec5-4b0c-9cc9-c48790090c43": 85000 // serve 85% this variation
9 }
10}]
11}

updateOffVariation

Updates the default off variation to variationId. The AI Config serves the default off variation when the AI Config’s targeting is Off.

Parameters
  • variationId: ID of a variation.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "updateOffVariation", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" } ]
4}

updateRuleDescription

Updates the description of the targeting rule.

Parameters
  • description: The new human-readable description for this rule.
  • ruleId: The ID of the rule. You can retrieve this by making a GET request for the AI Config.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateRuleDescription",
5 "description": "New rule description",
6 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29"
7}]
8}

updateRuleTrackEvents

Updates whether or not LaunchDarkly tracks events for the AI Config associated with this rule.

Parameters
  • ruleId: The ID of the rule. You can retrieve this by making a GET request for the AI Config.
  • trackEvents: Whether or not events are tracked.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateRuleTrackEvents",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "trackEvents": true
7}]
8}

updateRuleVariationOrRollout

Updates what ruleId serves when its clauses evaluate to true. The rule can serve either the variation that variationId indicates, or a percent rollout that rolloutWeights and rolloutBucketBy indicate.

Parameters
  • ruleId: ID of a rule.
  • variationId: ID of a variation.

or

  • rolloutWeights: Map of variationId to weight, in thousandths of a percent (0-100000).
  • rolloutBucketBy: (Optional) Context attribute available in the specified rolloutContextKind.
  • rolloutContextKind: (Optional) Context kind, defaults to user

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateRuleVariationOrRollout",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00"
7}]
8}

updateTrackEvents

Updates whether or not LaunchDarkly tracks events for the AI Config, for all rules.

Parameters
  • trackEvents: Whether or not events are tracked.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "updateTrackEvents", "trackEvents": true } ]
4}

updateTrackEventsFallthrough

Updates whether or not LaunchDarkly tracks events for the AI Config, for the default rule.

Parameters
  • trackEvents: Whether or not events are tracked.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "updateTrackEventsFallthrough", "trackEvents": true } ]
4}

Authentication

Authorizationstring
API Key authentication via header

Path parameters

projectKeystringRequired
configKeystringRequired

Request

AI Config targeting semantic patch instructions
environmentKeystringRequired
instructionslist of maps from strings to anyRequired
commentstringOptional

Response

AI Config targeting updated
createdAtlong
Unix timestamp in milliseconds
environmentsmap from strings to objects
experimentsobject
keystring
namestring
tagslist of strings
variationslist of objects
_versioninteger
defaultsobject

Errors

400
Bad Request Error
403
Forbidden Error
404
Not Found Error
500
Internal Server Error