# Call Metric Resource

A **Call Metric** is an object representing

* a set of quantitative measurements and
* meta data

related to the quality of a voice call.

Using the **Call Metrics Resource**, you can [read a list of Call Metrics for a specified voice call](#read-multiple-call-metric-resources).

> \[!WARNING]
>
> [Voice Insights Advanced Features](/docs/voice/voice-insights/advanced-features) must be active to use this API Resource.

> \[!NOTE]
>
> Metrics are typically available via the API within 90 seconds of call completion.

## Call Metric properties

The following table details the properties of a single Call Metric sample instance.

```json
{"type":"object","refName":"insights.v1.call.metric","modelName":"insights_v1_call_metric","properties":{"timestamp":{"type":"string","nullable":true,"description":"Timestamp of metric sample. Samples are taken every 10 seconds and contain the metrics for the previous 10 seconds."},"call_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^CA[0-9a-fA-F]{32}$","nullable":true,"description":"The unique SID identifier of the Call."},"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","nullable":true,"description":"The unique SID identifier of the Account."},"edge":{"type":"string","nullable":true,"description":"The Twilio media edge this Metric was captured on. One of `unknown_edge`, `carrier_edge`, `sip_edge`, `sdk_edge` or `client_edge`.","enum":["unknown_edge","carrier_edge","sip_edge","sdk_edge","client_edge"],"refName":"metric_enum_twilio_edge","modelName":"metric_enum_twilio_edge"},"direction":{"type":"string","nullable":true,"description":"The Direction of the media stream from the perspective of the Twilio media edge. One of `unknown`, `inbound`, `outbound` or `both`.","enum":["unknown","inbound","outbound","both"],"refName":"metric_enum_stream_direction","modelName":"metric_enum_stream_direction"},"carrier_edge":{"nullable":true,"description":"Contains metrics and properties for the Twilio media gateway of a PSTN call."},"sip_edge":{"nullable":true,"description":"Contains metrics and properties for the Twilio media gateway of a SIP Interface or Trunking call."},"sdk_edge":{"nullable":true,"description":"Contains metrics and properties for the SDK sensor library for Client calls."},"client_edge":{"nullable":true,"description":"Contains metrics and properties for the Twilio media gateway of a Client call."}}}
```

### Edge Metrics and properties

Metric samples from these edges contain the following properties:

| **Property** | **Description**                                                                                                                                                                            |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `codec`      | RTP profile number of the detected codec                                                                                                                                                   |
| `codec_name` | Name of the detected codec                                                                                                                                                                 |
| `cumulative` | Cumulative jitter (max/avg), packets lost, and packet count for the stream received at this edge                                                                                           |
| `interval`   | `sdk_edge`: audio in/out, jitter, packet loss, rtt, and packet loss percentage for the sampling interval. \_All other edge\_s: packets received, packets lost, and packet loss percentage. |
| `metadata`   | Twilio media region of the selected edge, Twilio and endpoint IP media IP addresses                                                                                                        |

## Read multiple Call Metric resources

`GET https://insights.twilio.com/v1/Voice/{CallSid}/Metrics`

Use this action to retrieve a list of Call Metrics for the specified voice call.

You can use the optional `edge` parameter to filter the list by media edge. See [Understanding Twilio Media Edges](/docs/voice/voice-insights/api/call/understanding-edges) for more information.

If no `edge` parameter is provided, the resulting list will depend on the call type:

| **Call Type**        | **Default Edge** | **Additional Edge** |
| -------------------- | ---------------- | ------------------- |
| Carrier              | `carrier_edge`   | N/A                 |
| SIP                  | `sip_edge`       | N/A                 |
| Client               | `sdk_edge`       | `client_edge`       |
| Trunking Originating | `carrier_edge`   | `sip_edge`          |
| Trunking Terminating | `sip_edge`       | `carrier_edge`      |

### Path parameters

```json
[{"name":"CallSid","in":"path","description":"The unique SID identifier of the Call.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^CA[0-9a-fA-F]{32}$"},"required":true}]
```

### Query parameters

```json
[{"name":"Edge","in":"query","description":"The Edge of this Metric. One of `unknown_edge`, `carrier_edge`, `sip_edge`, `sdk_edge` or `client_edge`.","schema":{"type":"string","enum":["unknown_edge","carrier_edge","sip_edge","sdk_edge","client_edge"],"refName":"metric_enum_twilio_edge","modelName":"metric_enum_twilio_edge"},"examples":{"readFull":{"value":"sdk_edge"}}},{"name":"Direction","in":"query","description":"The Direction of this Metric. One of `unknown`, `inbound`, `outbound` or `both`.","schema":{"type":"string","enum":["unknown","inbound","outbound","both"],"refName":"metric_enum_stream_direction","modelName":"metric_enum_stream_direction"},"examples":{"readFull":{"value":"both"}}},{"name":"PageSize","in":"query","description":"How many resources to return in each list page. The default is 50, and the maximum is 1000.","schema":{"type":"integer","format":"int64","minimum":1,"maximum":1000}},{"name":"Page","in":"query","description":"The page index. This value is simply for client state.","schema":{"type":"integer","minimum":0}},{"name":"PageToken","in":"query","description":"The page token. This is provided by the API.","schema":{"type":"string"}}]
```

Read multiple Call Metrics for a Call

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function listMetric() {
  const metrics = await client.insights.v1
    .calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    .metrics.list({ limit: 20 });

  metrics.forEach((m) => console.log(m.timestamp));
}

listMetric();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

metrics = client.insights.v1.calls(
    "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
).metrics.list(limit=20)

for record in metrics:
    print(record.timestamp)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Insights.V1.Call;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var metrics = await MetricResource.ReadAsync(
            pathCallSid: "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", limit: 20);

        foreach (var record in metrics) {
            Console.WriteLine(record.Timestamp);
        }
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.insights.v1.call.Metric;
import com.twilio.base.ResourceSet;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        ResourceSet<Metric> metrics = Metric.reader("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").limit(20).read();

        for (Metric record : metrics) {
            System.out.println(record.getTimestamp());
        }
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	insights "github.com/twilio/twilio-go/rest/insights/v1"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &insights.ListMetricParams{}
	params.SetLimit(20)

	resp, err := client.InsightsV1.ListMetric("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		for record := range resp {
			if resp[record].Timestamp != nil {
				fmt.Println(*resp[record].Timestamp)
			} else {
				fmt.Println(resp[record].Timestamp)
			}
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$metrics = $twilio->insights->v1
    ->calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    ->metrics->read([], 20);

foreach ($metrics as $record) {
    print $record->timestamp;
}
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

metrics = @client
          .insights
          .v1
          .calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
          .metrics
          .list(limit: 20)

metrics.each do |record|
   puts record.timestamp
end
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:insights:v1:voice:metrics:list \
   --call-sid CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

```bash
curl -X GET "https://insights.twilio.com/v1/Voice/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Metrics?PageSize=20" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "meta": {
    "page": 10,
    "page_size": 5,
    "first_page_url": "https://insights.twilio.com/v1/Voice/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Metrics?Direction=both&Edge=sdk_edge&PageSize=5&Page=0",
    "previous_page_url": "https://insights.twilio.com/v1/Voice/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Metrics?Direction=both&Edge=sdk_edge&PageSize=5&Page=9&PageToken=PT10",
    "next_page_url": null,
    "key": "metrics",
    "url": "https://insights.twilio.com/v1/Voice/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Metrics?Direction=both&Edge=sdk_edge&PageSize=5&Page=10"
  },
  "metrics": [
    {
      "timestamp": "2019-10-07T22:32:06Z",
      "call_sid": "CA7569efe0253644fa4a88aa97beca3310",
      "account_sid": "AC998c10b68cbfda9f67277f7d8f4439c9",
      "edge": "sdk_edge",
      "direction": "both",
      "sdk_edge": {
        "interval": {
          "packets_received": 50,
          "packets_lost": 0,
          "audio_in": {
            "value": 81
          },
          "audio_out": {
            "value": 5237
          },
          "jitter": {
            "value": 9
          },
          "mos": {
            "value": 4.39
          },
          "rtt": {
            "value": 81
          }
        },
        "cumulative": {
          "bytes_received": 547788,
          "bytes_sent": 329425,
          "packets_received": 3900,
          "packets_lost": 0,
          "packets_sent": 3934
        }
      },
      "client_edge": null,
      "carrier_edge": null,
      "sip_edge": null
    }
  ]
}
```

Read multiple Call Metrics for a Call filtered by Media Edge

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function listMetric() {
  const metrics = await client.insights.v1
    .calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    .metrics.list({
      edge: "sdk_edge",
      limit: 20,
    });

  metrics.forEach((m) => console.log(m.timestamp));
}

listMetric();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

metrics = client.insights.v1.calls(
    "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
).metrics.list(edge="sdk_edge", limit=20)

for record in metrics:
    print(record.timestamp)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Insights.V1.Call;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var metrics = await MetricResource.ReadAsync(
            pathCallSid: "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            edge: MetricResource.TwilioEdgeEnum.SdkEdge,
            limit: 20);

        foreach (var record in metrics) {
            Console.WriteLine(record.Timestamp);
        }
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.insights.v1.call.Metric;
import com.twilio.base.ResourceSet;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        ResourceSet<Metric> metrics =
            Metric.reader("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").setEdge(Metric.TwilioEdge.SDK_EDGE).limit(20).read();

        for (Metric record : metrics) {
            System.out.println(record.getTimestamp());
        }
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	insights "github.com/twilio/twilio-go/rest/insights/v1"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &insights.ListMetricParams{}
	params.SetEdge("sdk_edge")
	params.SetLimit(20)

	resp, err := client.InsightsV1.ListMetric("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		for record := range resp {
			if resp[record].Timestamp != nil {
				fmt.Println(*resp[record].Timestamp)
			} else {
				fmt.Println(resp[record].Timestamp)
			}
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$metrics = $twilio->insights->v1
    ->calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    ->metrics->read(["edge" => "sdk_edge"], 20);

foreach ($metrics as $record) {
    print $record->timestamp;
}
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

metrics = @client
          .insights
          .v1
          .calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
          .metrics
          .list(
            edge: 'sdk_edge',
            limit: 20
          )

metrics.each do |record|
   puts record.timestamp
end
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:insights:v1:voice:metrics:list \
   --call-sid CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
   --edge sdk_edge
```

```bash
curl -X GET "https://insights.twilio.com/v1/Voice/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Metrics?Edge=sdk_edge&PageSize=20" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "meta": {
    "page": 0,
    "page_size": 50,
    "first_page_url": "https://insights.twilio.com/v1/Voice/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Metrics?PageSize=50&Page=0",
    "previous_page_url": null,
    "next_page_url": null,
    "key": "metrics",
    "url": "https://insights.twilio.com/v1/Voice/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Metrics?PageSize=50&Page=0"
  },
  "metrics": [
    {
      "timestamp": "2019-10-07T22:32:06Z",
      "call_sid": "CA7569efe0253644fa4a88aa97beca3310",
      "account_sid": "AC998c10b68cbfda9f67277f7d8f4439c9",
      "edge": "sdk_edge",
      "direction": "both",
      "sdk_edge": {
        "interval": {
          "packets_received": 50,
          "packets_lost": 0,
          "audio_in": {
            "value": 81
          },
          "audio_out": {
            "value": 5237
          },
          "jitter": {
            "value": 9
          },
          "mos": {
            "value": 4.39
          },
          "rtt": {
            "value": 81
          }
        },
        "cumulative": {
          "bytes_received": 547788,
          "bytes_sent": 329425,
          "packets_received": 3900,
          "packets_lost": 0,
          "packets_sent": 3934
        }
      },
      "client_edge": null,
      "carrier_edge": null,
      "sip_edge": null
    }
  ]
}
```
