# Create new agent graph

POST https://app.launchdarkly.com/api/v2/projects/{projectKey}/agent-graphs
Content-Type: application/json

Create a new agent graph within the given project.

Reference: https://launchdarkly.com/docs/api/ai-configs/post-agent-graph

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/agent-graphs:
    post:
      operationId: post-agent-graph
      summary: Create new agent graph
      description: Create a new agent graph within the given project.
      tags:
        - subpackage_aiConfigs
      parameters:
        - name: projectKey
          in: path
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
        - name: LD-API-Version
          in: header
          description: Version of the endpoint.
          required: true
          schema:
            $ref: >-
              #/components/schemas/ApiV2ProjectsProjectKeyAgentGraphsPostParametersLdApiVersion
      responses:
        '201':
          description: Agent graph created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentGraph'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '413':
          description: Payload too large
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      requestBody:
        description: Agent graph object to create
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentGraphPost'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    ApiV2ProjectsProjectKeyAgentGraphsPostParametersLdApiVersion:
      type: string
      enum:
        - beta
      title: ApiV2ProjectsProjectKeyAgentGraphsPostParametersLdApiVersion
    AgentGraphEdgePostHandoff:
      type: object
      properties: {}
      description: The handoff options from the source AI Config to the target AI Config
      title: AgentGraphEdgePostHandoff
    AgentGraphEdgePost:
      type: object
      properties:
        key:
          type: string
          description: A unique key for this edge within the graph
        sourceConfig:
          type: string
          description: The AI Config key that is the source of this edge
        targetConfig:
          type: string
          description: The AI Config key that is the target of this edge
        handoff:
          $ref: '#/components/schemas/AgentGraphEdgePostHandoff'
          description: >-
            The handoff options from the source AI Config to the target AI
            Config
      required:
        - key
        - sourceConfig
        - targetConfig
      description: An edge in an agent graph connecting two AI Configs
      title: AgentGraphEdgePost
    AgentGraphPost:
      type: object
      properties:
        key:
          type: string
          description: A unique key for the agent graph
        name:
          type: string
          description: A human-readable name for the agent graph
        description:
          type: string
          description: A description of the agent graph
        maintainerId:
          type: string
          description: The ID of the member who maintains this agent graph
        maintainerTeamKey:
          type: string
          description: The key of the team that maintains this agent graph
        rootConfigKey:
          type: string
          description: >-
            The AI Config key of the root node. A missing root implies a newly
            created graph with metadata only.
        edges:
          type: array
          items:
            $ref: '#/components/schemas/AgentGraphEdgePost'
          description: >-
            The edges in the graph. If edges or rootConfigKey is present, both
            must be present.
      required:
        - key
        - name
      description: Request body for creating an agent graph
      title: AgentGraphPost
    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
    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
    AgentGraph__maintainer:
      oneOf:
        - $ref: '#/components/schemas/MaintainerMember'
        - $ref: '#/components/schemas/AiConfigsMaintainerTeam'
      title: AgentGraph__maintainer
    AgentGraphEdgeHandoff:
      type: object
      properties: {}
      description: The handoff options from the source AI Config to the target AI Config
      title: AgentGraphEdgeHandoff
    AgentGraphEdge:
      type: object
      properties:
        key:
          type: string
          description: A unique key for this edge within the graph
        sourceConfig:
          type: string
          description: The AI Config key that is the source of this edge
        targetConfig:
          type: string
          description: The AI Config key that is the target of this edge
        handoff:
          $ref: '#/components/schemas/AgentGraphEdgeHandoff'
          description: >-
            The handoff options from the source AI Config to the target AI
            Config
      required:
        - key
        - sourceConfig
        - targetConfig
      description: An edge in an agent graph connecting two AI Configs
      title: AgentGraphEdge
    AgentGraph:
      type: object
      properties:
        _access:
          $ref: '#/components/schemas/AiConfigsAccess'
        key:
          type: string
          description: A unique key for the agent graph
        name:
          type: string
          description: A human-readable name for the agent graph
        description:
          type: string
          description: A description of the agent graph
        _maintainer:
          $ref: '#/components/schemas/AgentGraph__maintainer'
        rootConfigKey:
          type: string
          description: The AI Config key of the root node
        edges:
          type: array
          items:
            $ref: '#/components/schemas/AgentGraphEdge'
          description: The edges in the graph
        createdAt:
          type: integer
          format: int64
        updatedAt:
          type: integer
          format: int64
      required:
        - key
        - name
        - createdAt
        - updatedAt
      description: An agent graph representing a directed graph of AI Configs
      title: AgentGraph
    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/agent-graphs"

payload = {
    "key": "key",
    "name": "name",
    "description": "description",
    "maintainerId": "507f1f77bcf86cd799439011",
    "maintainerTeamKey": "example-team-key",
    "rootConfigKey": "rootConfigKey",
    "edges": [
        {
            "key": "key",
            "sourceConfig": "sourceConfig",
            "targetConfig": "targetConfig",
            "handoff": "{}"
        },
        {
            "key": "key",
            "sourceConfig": "sourceConfig",
            "targetConfig": "targetConfig",
            "handoff": "{}"
        }
    ]
}
headers = {
    "LD-API-Version": "beta",
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/projects/projectKey/agent-graphs';
const options = {
  method: 'POST',
  headers: {
    'LD-API-Version': 'beta',
    Authorization: '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"key":"key","name":"name","description":"description","maintainerId":"507f1f77bcf86cd799439011","maintainerTeamKey":"example-team-key","rootConfigKey":"rootConfigKey","edges":[{"key":"key","sourceConfig":"sourceConfig","targetConfig":"targetConfig","handoff":"{}"},{"key":"key","sourceConfig":"sourceConfig","targetConfig":"targetConfig","handoff":"{}"}]}'
};

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/agent-graphs"

	payload := strings.NewReader("{\n  \"key\": \"key\",\n  \"name\": \"name\",\n  \"description\": \"description\",\n  \"maintainerId\": \"507f1f77bcf86cd799439011\",\n  \"maintainerTeamKey\": \"example-team-key\",\n  \"rootConfigKey\": \"rootConfigKey\",\n  \"edges\": [\n    {\n      \"key\": \"key\",\n      \"sourceConfig\": \"sourceConfig\",\n      \"targetConfig\": \"targetConfig\",\n      \"handoff\": \"{}\"\n    },\n    {\n      \"key\": \"key\",\n      \"sourceConfig\": \"sourceConfig\",\n      \"targetConfig\": \"targetConfig\",\n      \"handoff\": \"{}\"\n    }\n  ]\n}")

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

	req.Header.Add("LD-API-Version", "beta")
	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/agent-graphs")

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

request = Net::HTTP::Post.new(url)
request["LD-API-Version"] = 'beta'
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"key\": \"key\",\n  \"name\": \"name\",\n  \"description\": \"description\",\n  \"maintainerId\": \"507f1f77bcf86cd799439011\",\n  \"maintainerTeamKey\": \"example-team-key\",\n  \"rootConfigKey\": \"rootConfigKey\",\n  \"edges\": [\n    {\n      \"key\": \"key\",\n      \"sourceConfig\": \"sourceConfig\",\n      \"targetConfig\": \"targetConfig\",\n      \"handoff\": \"{}\"\n    },\n    {\n      \"key\": \"key\",\n      \"sourceConfig\": \"sourceConfig\",\n      \"targetConfig\": \"targetConfig\",\n      \"handoff\": \"{}\"\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.post("https://app.launchdarkly.com/api/v2/projects/projectKey/agent-graphs")
  .header("LD-API-Version", "beta")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"key\": \"key\",\n  \"name\": \"name\",\n  \"description\": \"description\",\n  \"maintainerId\": \"507f1f77bcf86cd799439011\",\n  \"maintainerTeamKey\": \"example-team-key\",\n  \"rootConfigKey\": \"rootConfigKey\",\n  \"edges\": [\n    {\n      \"key\": \"key\",\n      \"sourceConfig\": \"sourceConfig\",\n      \"targetConfig\": \"targetConfig\",\n      \"handoff\": \"{}\"\n    },\n    {\n      \"key\": \"key\",\n      \"sourceConfig\": \"sourceConfig\",\n      \"targetConfig\": \"targetConfig\",\n      \"handoff\": \"{}\"\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.launchdarkly.com/api/v2/projects/projectKey/agent-graphs', [
  'body' => '{
  "key": "key",
  "name": "name",
  "description": "description",
  "maintainerId": "507f1f77bcf86cd799439011",
  "maintainerTeamKey": "example-team-key",
  "rootConfigKey": "rootConfigKey",
  "edges": [
    {
      "key": "key",
      "sourceConfig": "sourceConfig",
      "targetConfig": "targetConfig",
      "handoff": "{}"
    },
    {
      "key": "key",
      "sourceConfig": "sourceConfig",
      "targetConfig": "targetConfig",
      "handoff": "{}"
    }
  ]
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
    'LD-API-Version' => 'beta',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/projects/projectKey/agent-graphs");
var request = new RestRequest(Method.POST);
request.AddHeader("LD-API-Version", "beta");
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"key\": \"key\",\n  \"name\": \"name\",\n  \"description\": \"description\",\n  \"maintainerId\": \"507f1f77bcf86cd799439011\",\n  \"maintainerTeamKey\": \"example-team-key\",\n  \"rootConfigKey\": \"rootConfigKey\",\n  \"edges\": [\n    {\n      \"key\": \"key\",\n      \"sourceConfig\": \"sourceConfig\",\n      \"targetConfig\": \"targetConfig\",\n      \"handoff\": \"{}\"\n    },\n    {\n      \"key\": \"key\",\n      \"sourceConfig\": \"sourceConfig\",\n      \"targetConfig\": \"targetConfig\",\n      \"handoff\": \"{}\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "LD-API-Version": "beta",
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "key": "key",
  "name": "name",
  "description": "description",
  "maintainerId": "507f1f77bcf86cd799439011",
  "maintainerTeamKey": "example-team-key",
  "rootConfigKey": "rootConfigKey",
  "edges": [
    [
      "key": "key",
      "sourceConfig": "sourceConfig",
      "targetConfig": "targetConfig",
      "handoff": "{}"
    ],
    [
      "key": "key",
      "sourceConfig": "sourceConfig",
      "targetConfig": "targetConfig",
      "handoff": "{}"
    ]
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/projectKey/agent-graphs")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
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()
```