# Update AI tool

PATCH https://app.launchdarkly.com/api/v2/projects/{projectKey}/ai-tools/{toolKey}
Content-Type: application/json

Edit an existing AI tool.

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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/ai-tools/{toolKey}:
    patch:
      operationId: patch-ai-tool
      summary: Update AI tool
      description: Edit an existing AI tool.
      tags:
        - subpackage_aiConfigs
      parameters:
        - name: projectKey
          in: path
          required: true
          schema:
            type: string
        - name: toolKey
          in: path
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: AI tool updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AITool'
        '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 tool object to update
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AIToolPatch'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    AiToolPatchSchema:
      type: object
      properties: {}
      description: JSON Schema defining the tool's parameters for LLM consumption
      title: AiToolPatchSchema
    AiToolPatchCustomParameters:
      type: object
      properties: {}
      description: >-
        Custom metadata and configuration for application-level use (not sent to
        LLM)
      title: AiToolPatchCustomParameters
    AIToolPatch:
      type: object
      properties:
        maintainerId:
          type: string
        maintainerTeamKey:
          type: string
        description:
          type: string
        schema:
          $ref: '#/components/schemas/AiToolPatchSchema'
          description: JSON Schema defining the tool's parameters for LLM consumption
        customParameters:
          $ref: '#/components/schemas/AiToolPatchCustomParameters'
          description: >-
            Custom metadata and configuration for application-level use (not
            sent to LLM)
      title: AIToolPatch
    ActionSpecifier:
      type: string
      title: ActionSpecifier
    AiConfigsAccessDeniedReasonEffect:
      type: string
      enum:
        - allow
        - deny
      description: Whether this statement should allow or deny actions on the resources.
      title: AiConfigsAccessDeniedReasonEffect
    AiConfigsAccessDeniedReason:
      type: object
      properties:
        resources:
          type: array
          items:
            type: string
          description: Resource specifier strings
        notResources:
          type: array
          items:
            type: string
          description: >-
            Targeted resources are the resources NOT in this list. The
            <code>resources</code> and <code>notActions</code> fields must be
            empty to use this field.
        actions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: Actions to perform on a resource
        notActions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: >-
            Targeted actions are the actions NOT in this list. The
            <code>actions</code> and <code>notResources</code> fields must be
            empty to use this field.
        effect:
          $ref: '#/components/schemas/AiConfigsAccessDeniedReasonEffect'
          description: >-
            Whether this statement should allow or deny actions on the
            resources.
        role_name:
          type: string
      required:
        - effect
      title: AiConfigsAccessDeniedReason
    AiConfigsAccessDenied:
      type: object
      properties:
        action:
          type: string
        reason:
          $ref: '#/components/schemas/AiConfigsAccessDeniedReason'
      required:
        - action
        - reason
      title: AiConfigsAccessDenied
    AiConfigsAccessAllowedReasonEffect:
      type: string
      enum:
        - allow
        - deny
      description: Whether this statement should allow or deny actions on the resources.
      title: AiConfigsAccessAllowedReasonEffect
    AiConfigsAccessAllowedReason:
      type: object
      properties:
        resources:
          type: array
          items:
            type: string
          description: Resource specifier strings
        notResources:
          type: array
          items:
            type: string
          description: >-
            Targeted resources are the resources NOT in this list. The
            <code>resources</code> and <code>notActions</code> fields must be
            empty to use this field.
        actions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: Actions to perform on a resource
        notActions:
          type: array
          items:
            $ref: '#/components/schemas/ActionSpecifier'
          description: >-
            Targeted actions are the actions NOT in this list. The
            <code>actions</code> and <code>notResources</code> fields must be
            empty to use this field.
        effect:
          $ref: '#/components/schemas/AiConfigsAccessAllowedReasonEffect'
          description: >-
            Whether this statement should allow or deny actions on the
            resources.
        role_name:
          type: string
      required:
        - effect
      title: AiConfigsAccessAllowedReason
    AiConfigsAccessAllowedRep:
      type: object
      properties:
        action:
          type: string
        reason:
          $ref: '#/components/schemas/AiConfigsAccessAllowedReason'
      required:
        - action
        - reason
      title: AiConfigsAccessAllowedRep
    AiConfigsAccess:
      type: object
      properties:
        denied:
          type: array
          items:
            $ref: '#/components/schemas/AiConfigsAccessDenied'
        allowed:
          type: array
          items:
            $ref: '#/components/schemas/AiConfigsAccessAllowedRep'
      required:
        - denied
        - allowed
      title: AiConfigsAccess
    CoreLink:
      type: object
      properties:
        href:
          type: string
        type:
          type: string
      required:
        - href
        - type
      title: CoreLink
    ParentAndSelfLinks:
      type: object
      properties:
        self:
          $ref: '#/components/schemas/CoreLink'
        parent:
          $ref: '#/components/schemas/CoreLink'
      required:
        - self
        - parent
      description: The location and content type of related resources
      title: ParentAndSelfLinks
    MaintainerMember:
      type: object
      properties:
        _id:
          type: string
        email:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        role:
          type: string
      required:
        - _id
        - email
        - role
      title: MaintainerMember
    AiConfigsMaintainerTeam:
      type: object
      properties:
        key:
          type: string
        name:
          type: string
      required:
        - key
        - name
      title: AiConfigsMaintainerTeam
    AIConfig__maintainer:
      oneOf:
        - $ref: '#/components/schemas/MaintainerMember'
        - $ref: '#/components/schemas/AiConfigsMaintainerTeam'
      title: AIConfig__maintainer
    AiToolSchema:
      type: object
      properties: {}
      description: JSON Schema defining the tool's parameters for LLM consumption
      title: AiToolSchema
    AiToolCustomParameters:
      type: object
      properties: {}
      description: >-
        Custom metadata and configuration for application-level use (not sent to
        LLM)
      title: AiToolCustomParameters
    AITool:
      type: object
      properties:
        key:
          type: string
        _access:
          $ref: '#/components/schemas/AiConfigsAccess'
        _links:
          $ref: '#/components/schemas/ParentAndSelfLinks'
        _maintainer:
          $ref: '#/components/schemas/AIConfig__maintainer'
        description:
          type: string
        schema:
          $ref: '#/components/schemas/AiToolSchema'
          description: JSON Schema defining the tool's parameters for LLM consumption
        customParameters:
          $ref: '#/components/schemas/AiToolCustomParameters'
          description: >-
            Custom metadata and configuration for application-level use (not
            sent to LLM)
        version:
          type: integer
        createdAt:
          type: integer
          format: int64
      required:
        - key
        - schema
        - version
        - createdAt
      title: AITool
    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-tools/toolKey"

payload = {
    "maintainerId": "507f1f77bcf86cd799439011",
    "maintainerTeamKey": "example-team-key",
    "description": "description",
    "schema": "{}",
    "customParameters": "{}"
}
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-tools/toolKey';
const options = {
  method: 'PATCH',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"maintainerId":"507f1f77bcf86cd799439011","maintainerTeamKey":"example-team-key","description":"description","schema":"{}","customParameters":"{}"}'
};

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-tools/toolKey"

	payload := strings.NewReader("{\n  \"maintainerId\": \"507f1f77bcf86cd799439011\",\n  \"maintainerTeamKey\": \"example-team-key\",\n  \"description\": \"description\",\n  \"schema\": \"{}\",\n  \"customParameters\": \"{}\"\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-tools/toolKey")

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  \"maintainerId\": \"507f1f77bcf86cd799439011\",\n  \"maintainerTeamKey\": \"example-team-key\",\n  \"description\": \"description\",\n  \"schema\": \"{}\",\n  \"customParameters\": \"{}\"\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-tools/toolKey")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"maintainerId\": \"507f1f77bcf86cd799439011\",\n  \"maintainerTeamKey\": \"example-team-key\",\n  \"description\": \"description\",\n  \"schema\": \"{}\",\n  \"customParameters\": \"{}\"\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-tools/toolKey', [
  'body' => '{
  "maintainerId": "507f1f77bcf86cd799439011",
  "maintainerTeamKey": "example-team-key",
  "description": "description",
  "schema": "{}",
  "customParameters": "{}"
}',
  '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-tools/toolKey");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"maintainerId\": \"507f1f77bcf86cd799439011\",\n  \"maintainerTeamKey\": \"example-team-key\",\n  \"description\": \"description\",\n  \"schema\": \"{}\",\n  \"customParameters\": \"{}\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "maintainerId": "507f1f77bcf86cd799439011",
  "maintainerTeamKey": "example-team-key",
  "description": "description",
  "schema": "{}",
  "customParameters": "{}"
] 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-tools/toolKey")! 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()
```