# Update AI Config variation

PATCH https://app.launchdarkly.com/api/v2/projects/{projectKey}/ai-configs/{configKey}/variations/{variationKey}
Content-Type: application/json

Edit an existing variation of an AI Config. This creates a new version of the variation.

The request body must be a JSON object of the fields to update. The values you include replace the existing values for the fields.

Here's an example:
```
  {
    "messages": [
      {
        "role": "system",
        "content": "The new message"
      }
    ]
  }
```


Reference: https://launchdarkly.com/docs/api/ai-configs/patch-ai-config-variation

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/ai-configs/{configKey}/variations/{variationKey}:
    patch:
      operationId: patch-ai-config-variation
      summary: Update AI Config variation
      description: >
        Edit an existing variation of an AI Config. This creates a new version
        of the variation.


        The request body must be a JSON object of the fields to update. The
        values you include replace the existing values for the fields.


        Here's an example:

        ```
          {
            "messages": [
              {
                "role": "system",
                "content": "The new message"
              }
            ]
          }
        ```
      tags:
        - subpackage_aiConfigs
      parameters:
        - name: projectKey
          in: path
          required: true
          schema:
            type: string
        - name: configKey
          in: path
          required: true
          schema:
            type: string
        - name: variationKey
          in: path
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: AI Config variation updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AIConfigVariation'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      requestBody:
        description: AI Config variation object to update
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AIConfigVariationPatch'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    Message:
      type: object
      properties:
        content:
          type: string
        role:
          type: string
      required:
        - content
        - role
      title: Message
    AiConfigVariationPatchModel:
      type: object
      properties: {}
      title: AiConfigVariationPatchModel
    VariationToolPost:
      type: object
      properties:
        key:
          type: string
          description: The key of the tool to use.
        version:
          type: integer
          description: The version of the tool.
      required:
        - key
        - version
      title: VariationToolPost
    JudgeAttachment:
      type: object
      properties:
        judgeConfigKey:
          type: string
          description: Key of the judge AI Config
        samplingRate:
          type: number
          format: double
          description: Sampling rate for this judge attachment (0.0 to 1.0)
      required:
        - judgeConfigKey
        - samplingRate
      title: JudgeAttachment
    JudgeConfiguration:
      type: object
      properties:
        judges:
          type: array
          items:
            $ref: '#/components/schemas/JudgeAttachment'
          description: >
            List of judges for this variation. When updating, this replaces all
            existing judge attachments, and if empty, removes all judge
            attachments.
      title: JudgeConfiguration
    AIConfigVariationPatch:
      type: object
      properties:
        comment:
          type: string
          description: Human-readable description of what this patch changes
        description:
          type: string
          description: Description for agent when AI Config is in agent mode.
        instructions:
          type: string
          description: Instructions for agent when AI Config is in agent mode.
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        model:
          $ref: '#/components/schemas/AiConfigVariationPatchModel'
        modelConfigKey:
          type: string
        name:
          type: string
        published:
          type: boolean
        state:
          type: string
          description: One of 'archived', 'published'
        tools:
          type: array
          items:
            $ref: '#/components/schemas/VariationToolPost'
          description: >-
            List of tools to use for this variation. The latest version of the
            tool will be used.
        toolKeys:
          type: array
          items:
            type: string
          description: >-
            List of tool keys to use for this variation. The latest version of
            the tool will be used.
        judgeConfiguration:
          $ref: '#/components/schemas/JudgeConfiguration'
      title: AIConfigVariationPatch
    CoreLink:
      type: object
      properties:
        href:
          type: string
        type:
          type: string
      required:
        - href
        - type
      title: CoreLink
    ParentLink:
      type: object
      properties:
        parent:
          $ref: '#/components/schemas/CoreLink'
      required:
        - parent
      title: ParentLink
    AiConfigVariationModel:
      type: object
      properties: {}
      title: AiConfigVariationModel
    VariationTool:
      type: object
      properties:
        key:
          type: string
          description: The key of the tool to use.
        version:
          type: integer
          description: The version of the tool.
        customParameters:
          type: object
          additionalProperties:
            description: Any type
          description: Custom metadata and configuration for application-level use
      required:
        - key
        - version
      title: VariationTool
    AIConfigVariation:
      type: object
      properties:
        _links:
          $ref: '#/components/schemas/ParentLink'
        color:
          type: string
        comment:
          type: string
        description:
          type: string
          description: >-
            Returns the description for the agent. This is only returned for
            agent variations.
        instructions:
          type: string
          description: >-
            Returns the instructions for the agent. This is only returned for
            agent variations.
        key:
          type: string
        _id:
          type: string
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        model:
          $ref: '#/components/schemas/AiConfigVariationModel'
        modelConfigKey:
          type: string
        name:
          type: string
        createdAt:
          type: integer
          format: int64
        version:
          type: integer
        state:
          type: string
        _archivedAt:
          type: integer
          format: int64
        _publishedAt:
          type: integer
          format: int64
        tools:
          type: array
          items:
            $ref: '#/components/schemas/VariationTool'
        judgeConfiguration:
          $ref: '#/components/schemas/JudgeConfiguration'
        judgingConfigKeys:
          type: array
          items:
            type: string
      required:
        - key
        - _id
        - model
        - name
        - createdAt
        - version
      title: AIConfigVariation
    Error:
      type: object
      properties:
        message:
          type: string
        code:
          type: string
      required:
        - message
        - code
      title: Error
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

```

## SDK Code Examples

```python
import requests

url = "https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/variations/variationKey"

payload = {
    "comment": "comment",
    "description": "description",
    "instructions": "instructions",
    "messages": [
        {
            "content": "content",
            "role": "role"
        },
        {
            "content": "content",
            "role": "role"
        }
    ],
    "model": "{}",
    "modelConfigKey": "modelConfigKey",
    "name": "name",
    "published": True,
    "state": "state",
    "tools": [
        {
            "key": "key",
            "version": 0
        },
        {
            "key": "key",
            "version": 0
        }
    ],
    "toolKeys": ["toolKeys", "toolKeys"],
    "judgeConfiguration": { "judges": [
            {
                "judgeConfigKey": "judgeConfigKey",
                "samplingRate": 0.7061401
            },
            {
                "judgeConfigKey": "judgeConfigKey",
                "samplingRate": 0.7061401
            }
        ] }
}
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.patch(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/variations/variationKey';
const options = {
  method: 'PATCH',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"comment":"comment","description":"description","instructions":"instructions","messages":[{"content":"content","role":"role"},{"content":"content","role":"role"}],"model":"{}","modelConfigKey":"modelConfigKey","name":"name","published":true,"state":"state","tools":[{"key":"key","version":0},{"key":"key","version":0}],"toolKeys":["toolKeys","toolKeys"],"judgeConfiguration":{"judges":[{"judgeConfigKey":"judgeConfigKey","samplingRate":0.7061401},{"judgeConfigKey":"judgeConfigKey","samplingRate":0.7061401}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/variations/variationKey"

	payload := strings.NewReader("{\n  \"comment\": \"comment\",\n  \"description\": \"description\",\n  \"instructions\": \"instructions\",\n  \"messages\": [\n    {\n      \"content\": \"content\",\n      \"role\": \"role\"\n    },\n    {\n      \"content\": \"content\",\n      \"role\": \"role\"\n    }\n  ],\n  \"model\": \"{}\",\n  \"modelConfigKey\": \"modelConfigKey\",\n  \"name\": \"name\",\n  \"published\": true,\n  \"state\": \"state\",\n  \"tools\": [\n    {\n      \"key\": \"key\",\n      \"version\": 0\n    },\n    {\n      \"key\": \"key\",\n      \"version\": 0\n    }\n  ],\n  \"toolKeys\": [\n    \"toolKeys\",\n    \"toolKeys\"\n  ],\n  \"judgeConfiguration\": {\n    \"judges\": [\n      {\n        \"judgeConfigKey\": \"judgeConfigKey\",\n        \"samplingRate\": 0.7061401\n      },\n      {\n        \"judgeConfigKey\": \"judgeConfigKey\",\n        \"samplingRate\": 0.7061401\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("Authorization", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/variations/variationKey")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"comment\": \"comment\",\n  \"description\": \"description\",\n  \"instructions\": \"instructions\",\n  \"messages\": [\n    {\n      \"content\": \"content\",\n      \"role\": \"role\"\n    },\n    {\n      \"content\": \"content\",\n      \"role\": \"role\"\n    }\n  ],\n  \"model\": \"{}\",\n  \"modelConfigKey\": \"modelConfigKey\",\n  \"name\": \"name\",\n  \"published\": true,\n  \"state\": \"state\",\n  \"tools\": [\n    {\n      \"key\": \"key\",\n      \"version\": 0\n    },\n    {\n      \"key\": \"key\",\n      \"version\": 0\n    }\n  ],\n  \"toolKeys\": [\n    \"toolKeys\",\n    \"toolKeys\"\n  ],\n  \"judgeConfiguration\": {\n    \"judges\": [\n      {\n        \"judgeConfigKey\": \"judgeConfigKey\",\n        \"samplingRate\": 0.7061401\n      },\n      {\n        \"judgeConfigKey\": \"judgeConfigKey\",\n        \"samplingRate\": 0.7061401\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/variations/variationKey")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"comment\": \"comment\",\n  \"description\": \"description\",\n  \"instructions\": \"instructions\",\n  \"messages\": [\n    {\n      \"content\": \"content\",\n      \"role\": \"role\"\n    },\n    {\n      \"content\": \"content\",\n      \"role\": \"role\"\n    }\n  ],\n  \"model\": \"{}\",\n  \"modelConfigKey\": \"modelConfigKey\",\n  \"name\": \"name\",\n  \"published\": true,\n  \"state\": \"state\",\n  \"tools\": [\n    {\n      \"key\": \"key\",\n      \"version\": 0\n    },\n    {\n      \"key\": \"key\",\n      \"version\": 0\n    }\n  ],\n  \"toolKeys\": [\n    \"toolKeys\",\n    \"toolKeys\"\n  ],\n  \"judgeConfiguration\": {\n    \"judges\": [\n      {\n        \"judgeConfigKey\": \"judgeConfigKey\",\n        \"samplingRate\": 0.7061401\n      },\n      {\n        \"judgeConfigKey\": \"judgeConfigKey\",\n        \"samplingRate\": 0.7061401\n      }\n    ]\n  }\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/variations/variationKey', [
  'body' => '{
  "comment": "comment",
  "description": "description",
  "instructions": "instructions",
  "messages": [
    {
      "content": "content",
      "role": "role"
    },
    {
      "content": "content",
      "role": "role"
    }
  ],
  "model": "{}",
  "modelConfigKey": "modelConfigKey",
  "name": "name",
  "published": true,
  "state": "state",
  "tools": [
    {
      "key": "key",
      "version": 0
    },
    {
      "key": "key",
      "version": 0
    }
  ],
  "toolKeys": [
    "toolKeys",
    "toolKeys"
  ],
  "judgeConfiguration": {
    "judges": [
      {
        "judgeConfigKey": "judgeConfigKey",
        "samplingRate": 0.7061401
      },
      {
        "judgeConfigKey": "judgeConfigKey",
        "samplingRate": 0.7061401
      }
    ]
  }
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/variations/variationKey");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"comment\": \"comment\",\n  \"description\": \"description\",\n  \"instructions\": \"instructions\",\n  \"messages\": [\n    {\n      \"content\": \"content\",\n      \"role\": \"role\"\n    },\n    {\n      \"content\": \"content\",\n      \"role\": \"role\"\n    }\n  ],\n  \"model\": \"{}\",\n  \"modelConfigKey\": \"modelConfigKey\",\n  \"name\": \"name\",\n  \"published\": true,\n  \"state\": \"state\",\n  \"tools\": [\n    {\n      \"key\": \"key\",\n      \"version\": 0\n    },\n    {\n      \"key\": \"key\",\n      \"version\": 0\n    }\n  ],\n  \"toolKeys\": [\n    \"toolKeys\",\n    \"toolKeys\"\n  ],\n  \"judgeConfiguration\": {\n    \"judges\": [\n      {\n        \"judgeConfigKey\": \"judgeConfigKey\",\n        \"samplingRate\": 0.7061401\n      },\n      {\n        \"judgeConfigKey\": \"judgeConfigKey\",\n        \"samplingRate\": 0.7061401\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "comment": "comment",
  "description": "description",
  "instructions": "instructions",
  "messages": [
    [
      "content": "content",
      "role": "role"
    ],
    [
      "content": "content",
      "role": "role"
    ]
  ],
  "model": "{}",
  "modelConfigKey": "modelConfigKey",
  "name": "name",
  "published": true,
  "state": "state",
  "tools": [
    [
      "key": "key",
      "version": 0
    ],
    [
      "key": "key",
      "version": 0
    ]
  ],
  "toolKeys": ["toolKeys", "toolKeys"],
  "judgeConfiguration": ["judges": [
      [
        "judgeConfigKey": "judgeConfigKey",
        "samplingRate": 0.7061401
      ],
      [
        "judgeConfigKey": "judgeConfigKey",
        "samplingRate": 0.7061401
      ]
    ]]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/variations/variationKey")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```