> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://respan.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/docs/_mcp/server.

# Get behavior signals over time

POST https://api.respan.ai/api/pulses/behaviors/timeseries/
Content-Type: application/json

Returns how many spans fired each behavior per time bucket, or per polarity with `group_by: polarity`. `minute` buckets use exact range edges; larger buckets read the hourly rollup.

Reference: https://respan.ai/docs/apis/behaviors/get-behavior-signals-over-time

## Authentication

- `Authorization` header (bearer token, required) — Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer \<RESPAN\_API\_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan\_params.credential\_override in the request body, not in this authentication field.

## Request

### Body (application/json)

This endpoint expects a BehaviorTimeSeriesRequest.

- `start_time` (datetime, optional) — Start of the range, ISO 8601. A time without an offset is read as UTC. Defaults to 7 days ago, which is also used if the value can't be parsed.
- `end_time` (datetime, optional) — End of the range, ISO 8601. A time without an offset is read as UTC. Defaults to now, which is also used if the value can't be parsed.
- `environment` (string, optional) — Only count spans from this environment, such as `prod` or `test`. Omit it to include every environment.
- `granularity` (enum, optional, default: day) — Bucket size.
  - Allowed values: `minute`, `hour`, `day`, `week`
- `group_by` (enum, optional, default: behavior) — `behavior` returns one series per behavior. `polarity` sums them into one series per polarity.
  - Allowed values: `behavior`, `polarity`
- `behaviors` (list of string, optional) — Only include these behavior keys (built-in names or custom behavior IDs). Omit for every behavior.

## Response

### 200

Fired counts per bucket.

- `granularity` (enum, required)
  - Allowed values: `minute`, `hour`, `day`, `week`
- `group_by` (enum, required)
  - Allowed values: `behavior`, `polarity`
- `series` (list of BehaviorTimeSeriesPoint, required) — Points ordered by `bucket`. A point appears only where the behavior fired, so empty buckets are missing.

## Errors

### 400 Bad Request Error

Invalid `granularity` or `group_by`.

- `error` (string, required)

### 403 Forbidden Error

Forbidden: the API key is missing, invalid or expired; the key doesn't grant `logs:read` (Read access does); behaviors are turned off for the organization.

- `detail` (string, required)

### 429 Too Many Requests Error

Rate limited. This endpoint allows 60 requests per minute per organization.

- `detail` (string, required)

## Types

### BehaviorTimeSeriesPoint

- `bucket` (string, required) — Start of the bucket. A date (`YYYY-MM-DD`) for `week` buckets. UTC, ISO 8601 without a timezone suffix.
- `fired_spans` (integer, required) — Spans where the behavior (or any behavior of the polarity) fired in the bucket.
- `behavior` (string, optional) — Behavior key: a built-in behavior's name (for example `refusal`) or a custom behavior's `id`. Present when `group_by` is `behavior`.
- `polarity` (enum, optional) — Present when `group_by` is `polarity`.
  - Allowed values: `negative`, `positive`, `neutral`

## Examples

**Request**

```json
{
  "start_time": "2026-09-30T00:00:00Z",
  "end_time": "2026-10-01T00:00:00Z",
  "granularity": "hour",
  "group_by": "behavior",
  "behaviors": [
    "refusal",
    "instruction_miss"
  ]
}
```

**Response**

```json
{
  "granularity": "hour",
  "group_by": "behavior",
  "series": [
    {
      "bucket": "2026-09-30T13:00:00",
      "fired_spans": 9,
      "behavior": "instruction_miss"
    },
    {
      "bucket": "2026-09-30T14:00:00",
      "fired_spans": 12,
      "behavior": "instruction_miss"
    },
    {
      "bucket": "2026-09-30T14:00:00",
      "fired_spans": 3,
      "behavior": "refusal"
    }
  ]
}
```

**SDK Code**

```python Behaviors_getBehaviorTimeSeries_example
import requests

url = "https://api.respan.ai/api/pulses/behaviors/timeseries/"

payload = {
    "start_time": "2026-09-30T00:00:00Z",
    "end_time": "2026-10-01T00:00:00Z",
    "granularity": "hour",
    "group_by": "behavior",
    "behaviors": ["refusal", "instruction_miss"]
}
headers = {
    "Authorization": "Bearer <respanApiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Behaviors_getBehaviorTimeSeries_example
const url = 'https://api.respan.ai/api/pulses/behaviors/timeseries/';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <respanApiKey>', 'Content-Type': 'application/json'},
  body: '{"start_time":"2026-09-30T00:00:00Z","end_time":"2026-10-01T00:00:00Z","granularity":"hour","group_by":"behavior","behaviors":["refusal","instruction_miss"]}'
};

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

```go Behaviors_getBehaviorTimeSeries_example
package main

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

func main() {

	url := "https://api.respan.ai/api/pulses/behaviors/timeseries/"

	payload := strings.NewReader("{\n  \"start_time\": \"2026-09-30T00:00:00Z\",\n  \"end_time\": \"2026-10-01T00:00:00Z\",\n  \"granularity\": \"hour\",\n  \"group_by\": \"behavior\",\n  \"behaviors\": [\n    \"refusal\",\n    \"instruction_miss\"\n  ]\n}")

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

	req.Header.Add("Authorization", "Bearer <respanApiKey>")
	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 Behaviors_getBehaviorTimeSeries_example
require 'uri'
require 'net/http'

url = URI("https://api.respan.ai/api/pulses/behaviors/timeseries/")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <respanApiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"start_time\": \"2026-09-30T00:00:00Z\",\n  \"end_time\": \"2026-10-01T00:00:00Z\",\n  \"granularity\": \"hour\",\n  \"group_by\": \"behavior\",\n  \"behaviors\": [\n    \"refusal\",\n    \"instruction_miss\"\n  ]\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.respan.ai/api/pulses/behaviors/timeseries/")
  .header("Authorization", "Bearer <respanApiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"start_time\": \"2026-09-30T00:00:00Z\",\n  \"end_time\": \"2026-10-01T00:00:00Z\",\n  \"granularity\": \"hour\",\n  \"group_by\": \"behavior\",\n  \"behaviors\": [\n    \"refusal\",\n    \"instruction_miss\"\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.respan.ai/api/pulses/behaviors/timeseries/', [
  'body' => '{
  "start_time": "2026-09-30T00:00:00Z",
  "end_time": "2026-10-01T00:00:00Z",
  "granularity": "hour",
  "group_by": "behavior",
  "behaviors": [
    "refusal",
    "instruction_miss"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <respanApiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Behaviors_getBehaviorTimeSeries_example
using RestSharp;

var client = new RestClient("https://api.respan.ai/api/pulses/behaviors/timeseries/");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <respanApiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"start_time\": \"2026-09-30T00:00:00Z\",\n  \"end_time\": \"2026-10-01T00:00:00Z\",\n  \"granularity\": \"hour\",\n  \"group_by\": \"behavior\",\n  \"behaviors\": [\n    \"refusal\",\n    \"instruction_miss\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Behaviors_getBehaviorTimeSeries_example
import Foundation

let headers = [
  "Authorization": "Bearer <respanApiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "start_time": "2026-09-30T00:00:00Z",
  "end_time": "2026-10-01T00:00:00Z",
  "granularity": "hour",
  "group_by": "behavior",
  "behaviors": ["refusal", "instruction_miss"]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/pulses/behaviors/timeseries/")! 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()
```