# Get AI Config metrics by variation

GET https://app.launchdarkly.com/api/v2/projects/{projectKey}/ai-configs/{configKey}/metrics-by-variation

Retrieve usage metrics for an AI Config by config key, with results split by variation.

Reference: https://launchdarkly.com/docs/api/ai-configs/get-ai-config-metrics-by-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}/metrics-by-variation:
    get:
      operationId: get-ai-config-metrics-by-variation
      summary: Get AI Config metrics by variation
      description: >-
        Retrieve usage metrics for an AI Config by config key, with results
        split by variation.
      tags:
        - subpackage_aiConfigs
      parameters:
        - name: projectKey
          in: path
          required: true
          schema:
            type: string
        - name: configKey
          in: path
          required: true
          schema:
            type: string
        - name: from
          in: query
          description: The starting time, as milliseconds since epoch (inclusive).
          required: true
          schema:
            type: integer
        - name: to
          in: query
          description: >-
            The ending time, as milliseconds since epoch (exclusive). May not be
            more than 100 days after `from`.
          required: true
          schema:
            type: integer
        - name: env
          in: query
          description: >-
            An environment key. Only metrics from this environment will be
            included.
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Metrics computed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricsByVariation'
        '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'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    Metrics:
      type: object
      properties:
        inputTokens:
          type: integer
        outputTokens:
          type: integer
        totalTokens:
          type: integer
        generationCount:
          type: integer
          description: Number of attempted generations
        generationSuccessCount:
          type: integer
          description: Number of successful generations
        generationErrorCount:
          type: integer
          description: Number of generations with errors
        thumbsUp:
          type: integer
        thumbsDown:
          type: integer
        durationMs:
          type: integer
        timeToFirstTokenMs:
          type: integer
        satisfactionRating:
          type: number
          format: double
          description: A value between 0 and 1 representing satisfaction rating
        inputCost:
          type: number
          format: double
          description: Cost of input tokens in USD
        outputCost:
          type: number
          format: double
          description: Cost of output tokens in USD
        judgeAccuracy:
          type: number
          format: double
          description: Average accuracy judge score (0.0-1.0)
        judgeRelevance:
          type: number
          format: double
          description: Average relevance judge score (0.0-1.0)
        judgeToxicity:
          type: number
          format: double
          description: Average toxicity judge score (0.0-1.0)
      title: Metrics
    MetricByVariation:
      type: object
      properties:
        variationKey:
          type: string
        metrics:
          $ref: '#/components/schemas/Metrics'
      title: MetricByVariation
    MetricsByVariation:
      type: array
      items:
        $ref: '#/components/schemas/MetricByVariation'
      title: MetricsByVariation
    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/metrics-by-variation"

querystring = {"from":"1","to":"1","env":"env"}

headers = {"Authorization": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/metrics-by-variation?from=1&to=1&env=env';
const options = {method: 'GET', headers: {Authorization: '<apiKey>'}};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/metrics-by-variation?from=1&to=1&env=env"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Authorization", "<apiKey>")

	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/metrics-by-variation?from=1&to=1&env=env")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = '<apiKey>'

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.get("https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/metrics-by-variation?from=1&to=1&env=env")
  .header("Authorization", "<apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/metrics-by-variation?from=1&to=1&env=env', [
  'headers' => [
    'Authorization' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/metrics-by-variation?from=1&to=1&env=env");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/projectKey/ai-configs/configKey/metrics-by-variation?from=1&to=1&env=env")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

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()
```