Skip to Content

Get behavior counts by dimension

POSThttps://api.respan.ai/api/pulses/behaviors/grouped/

Splits the spans where one behavior fired by a span field, such as model or customer. The signals panel uses it for its “By model” and “By customer” splits.

Servers

https://api.respan.ai: Respan API Server

Authentication

RespanApiKey

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.

HTTP scheme: bearer; format: Respan API key.

HTTP
Authorization: Bearer $RESPAN_API_KEY

Request body

A request body is required.

application/json

Field Type Requirement Description and constraints
$ object Required body
Reference: #/components/schemas/BehaviorBreakdownRequest
behavior string Required in parent
Behavior key: a built-in behavior’s name (for example refusal) or a custom behavior’s id.
Example: "instruction_miss"
group_by string Required in parent
Span field to split by. status is the span status, such as success or failed.
Allowed: "customer_identifier", "deployment_name", "environment", "model", "prompt_id", "prompt_name", "provider_id", "status"
Example: "model"
start_time string 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.
Format: date-time
Example: "2026-09-24T00:00:00Z"
end_time string 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.
Format: date-time
Example: "2026-10-01T00:00:00Z"
environment string Optional
Only count spans from this environment, such as prod or test. Omit it to include every environment.
Example: "prod"
limit integer Optional
Maximum groups to return. Values above 100 are capped at 100.
Default: 100
Minimum: 1
Maximum: 100
Example: 10

OpenAPI request schema

{
  "$ref": "#/components/schemas/BehaviorBreakdownRequest"
}
Example
JSON
{ "behavior": "instruction_miss", "group_by": "model", "start_time": "2026-09-24T00:00:00Z", "end_time": "2026-10-01T00:00:00Z", "limit": 10 }

Responses

200

Fired counts per group.

application/json

Field Type Requirement Description and constraints
$ object Body
Reference: #/components/schemas/BehaviorBreakdown
behavior string Required in parent
Behavior key: a built-in behavior’s name (for example refusal) or a custom behavior’s id.
Example: "instruction_miss"
group_by string Required in parent
Allowed: "customer_identifier", "deployment_name", "environment", "model", "prompt_id", "prompt_name", "provider_id", "status"
Example: "model"
groups array<object> Required in parent
Groups ordered by fired_spans, highest first. Empty when the behavior is turned off.
groups[] object Array item
Reference: #/components/schemas/BehaviorBreakdownGroup
groups[].group_value string Required in parent
Value of the group_by field. Spans with no value are grouped under an empty string.
Example: "gpt-4o-mini"
groups[].fired_spans integer Required in parent
Spans with this value where the behavior fired.
Example: 61

OpenAPI response schema

{
  "$ref": "#/components/schemas/BehaviorBreakdown"
}
Example
JSON
{ "behavior": "instruction_miss", "group_by": "model", "groups": [ { "group_value": "gpt-4o-mini", "fired_spans": 61 }, { "group_value": "claude-sonnet-4-5", "fired_spans": 38 } ] }

400

behavior is missing or group_by is not supported.

application/json

Field Type Requirement Description and constraints
$ object Body
-
error string Required in parent
-

OpenAPI response schema

{
  "type": "object",
  "required": [
    "error"
  ],
  "properties": {
    "error": {
      "type": "string"
    }
  }
}
Example
JSON
{ "error": "'behavior' is required" }

403

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.

application/json

Field Type Requirement Description and constraints
$ object Body
-
detail string Required in parent
-

OpenAPI response schema

{
  "type": "object",
  "required": [
    "detail"
  ],
  "properties": {
    "detail": {
      "type": "string"
    }
  }
}
Missing or invalid API key
JSON
{ "detail": "Your API key is invalid or expired, please check your API key in the platform settings." }
Key lacks the permission
JSON
{ "detail": "This API key does not have the 'logs:read' permission." }
Behaviors are off for the organization
JSON
{ "detail": "Span Behaviors is not enabled for this organization." }

429

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

application/json

Field Type Requirement Description and constraints
$ object Body
-
detail string Required in parent
-

OpenAPI response schema

{
  "type": "object",
  "required": [
    "detail"
  ],
  "properties": {
    "detail": {
      "type": "string"
    }
  }
}
Example
JSON
{ "detail": "Request was throttled." }

OpenAPI source

The operation and referenced components below retain the complete OpenAPI definitions, including constraints and examples.

OpenAPI operation

{
  "summary": "Get behavior counts by dimension",
  "operationId": "getBehaviorBreakdown",
  "tags": [
    "Behaviors"
  ],
  "description": "Splits the spans where one behavior fired by a span field, such as model or customer. The signals panel uses it for its \"By model\" and \"By customer\" splits.",
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/BehaviorBreakdownRequest"
        },
        "example": {
          "behavior": "instruction_miss",
          "group_by": "model",
          "start_time": "2026-09-24T00:00:00Z",
          "end_time": "2026-10-01T00:00:00Z",
          "limit": 10
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "Fired counts per group.",
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/BehaviorBreakdown"
          },
          "example": {
            "behavior": "instruction_miss",
            "group_by": "model",
            "groups": [
              {
                "group_value": "gpt-4o-mini",
                "fired_spans": 61
              },
              {
                "group_value": "claude-sonnet-4-5",
                "fired_spans": 38
              }
            ]
          }
        }
      }
    },
    "400": {
      "description": "`behavior` is missing or `group_by` is not supported.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "error"
            ],
            "properties": {
              "error": {
                "type": "string"
              }
            }
          },
          "example": {
            "error": "'behavior' is required"
          }
        }
      }
    },
    "403": {
      "description": "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.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "detail"
            ],
            "properties": {
              "detail": {
                "type": "string"
              }
            }
          },
          "examples": {
            "invalidKey": {
              "summary": "Missing or invalid API key",
              "value": {
                "detail": "Your API key is invalid or expired, please check your API key in the platform settings."
              }
            },
            "missingPermission": {
              "summary": "Key lacks the permission",
              "value": {
                "detail": "This API key does not have the 'logs:read' permission."
              }
            },
            "behaviorsOff": {
              "summary": "Behaviors are off for the organization",
              "value": {
                "detail": "Span Behaviors is not enabled for this organization."
              }
            }
          }
        }
      }
    },
    "429": {
      "description": "Rate limited. This endpoint allows 60 requests per minute per organization.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "detail"
            ],
            "properties": {
              "detail": {
                "type": "string"
              }
            }
          },
          "example": {
            "detail": "Request was throttled."
          }
        }
      }
    }
  },
  "security": [
    {
      "RespanApiKey": []
    }
  ]
}

OpenAPI path metadata

{}

Referenced OpenAPI components

{
  "schemas": {
    "BehaviorBreakdown": {
      "type": "object",
      "required": [
        "behavior",
        "group_by",
        "groups"
      ],
      "properties": {
        "behavior": {
          "type": "string",
          "description": "Behavior key: a built-in behavior's name (for example `refusal`) or a custom behavior's `id`.",
          "example": "instruction_miss"
        },
        "group_by": {
          "type": "string",
          "enum": [
            "customer_identifier",
            "deployment_name",
            "environment",
            "model",
            "prompt_id",
            "prompt_name",
            "provider_id",
            "status"
          ],
          "example": "model"
        },
        "groups": {
          "type": "array",
          "description": "Groups ordered by `fired_spans`, highest first. Empty when the behavior is turned off.",
          "items": {
            "$ref": "#/components/schemas/BehaviorBreakdownGroup"
          }
        }
      }
    },
    "BehaviorBreakdownGroup": {
      "type": "object",
      "required": [
        "group_value",
        "fired_spans"
      ],
      "properties": {
        "group_value": {
          "type": "string",
          "description": "Value of the `group_by` field. Spans with no value are grouped under an empty string.",
          "example": "gpt-4o-mini"
        },
        "fired_spans": {
          "type": "integer",
          "description": "Spans with this value where the behavior fired.",
          "example": 61
        }
      }
    },
    "BehaviorBreakdownRequest": {
      "type": "object",
      "required": [
        "behavior",
        "group_by"
      ],
      "properties": {
        "behavior": {
          "type": "string",
          "description": "Behavior key: a built-in behavior's name (for example `refusal`) or a custom behavior's `id`.",
          "example": "instruction_miss"
        },
        "group_by": {
          "type": "string",
          "enum": [
            "customer_identifier",
            "deployment_name",
            "environment",
            "model",
            "prompt_id",
            "prompt_name",
            "provider_id",
            "status"
          ],
          "description": "Span field to split by. `status` is the span status, such as `success` or `failed`.",
          "example": "model"
        },
        "start_time": {
          "type": "string",
          "format": "date-time",
          "description": "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.",
          "example": "2026-09-24T00:00:00Z"
        },
        "end_time": {
          "type": "string",
          "format": "date-time",
          "description": "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.",
          "example": "2026-10-01T00:00:00Z"
        },
        "environment": {
          "type": "string",
          "description": "Only count spans from this environment, such as `prod` or `test`. Omit it to include every environment.",
          "example": "prod"
        },
        "limit": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 100,
          "description": "Maximum groups to return. Values above 100 are capped at 100.",
          "example": 10
        }
      }
    }
  },
  "securitySchemes": {
    "RespanApiKey": {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "Respan API key",
      "description": "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.",
      "x-fern-bearer": {
        "name": "respanApiKey",
        "env": "RESPAN_API_KEY"
      }
    }
  }
}