Skip to Content

Create a custom behavior

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

Creates a behavior from a plain-language definition. New spans are scored against it from then on; past spans are not rescored.

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/CustomBehaviorCreateRequest
description string Required in parent
The plain-language definition span-01 scores each span against. Say what counts and what doesn’t. At least 3 characters after trimming.
Minimum length: 3
Example: "The assistant promises a refund, credit, or compensation that the policy in the system prompt does not allow."
name string or null Optional
Display name. Optional and not unique. Blank is stored as null.
Maximum length: 128
Example: "Refund promise"
polarity string Optional
Whether the behavior firing is good or bad: negative (an Issue), positive (a Win) or neutral (Info). Display metadata only; it does not change how spans are scored. Defaults to neutral.
Default: neutral
polarity (allOf 1) string Schema variant
Whether the behavior firing is good or bad: negative (an Issue), positive (a Win) or neutral (Info). Display metadata only; it does not change how spans are scored.
Reference: #/components/schemas/BehaviorPolarity
Allowed: "negative", "positive", "neutral"
Example: "negative"

OpenAPI request schema

{
  "$ref": "#/components/schemas/CustomBehaviorCreateRequest"
}
Example
JSON
{ "name": "Refund promise", "description": "The assistant promises a refund, credit, or compensation that the policy in the system prompt does not allow.", "polarity": "negative" }

Responses

201

The created behavior.

application/json

Field Type Requirement Description and constraints
$ object Body
Reference: #/components/schemas/CustomBehavior
id string Required in parent
Custom behavior ID. It is also the behavior’s key in analytics, filters and span verdicts.
Example: "6f1c2a9e-3b7d-4c55-9a0e-2d8f4b1c7e93"
name string or null Required in parent
Display name. Optional and not unique; behaviors are identified by id.
Maximum length: 128
Example: "Refund promise"
description string Required in parent
The plain-language definition span-01 scores each span against. Say what counts and what doesn’t. At least 3 characters after trimming.
Example: "The assistant promises a refund, credit, or compensation that the policy in the system prompt does not allow."
polarity string Required in parent
Whether the behavior firing is good or bad: negative (an Issue), positive (a Win) or neutral (Info). Display metadata only; it does not change how spans are scored.
Reference: #/components/schemas/BehaviorPolarity
Allowed: "negative", "positive", "neutral"
Example: "negative"
created_at string Required in parent
Format: date-time
Example: "2026-09-28T17:41:09.512340Z"
updated_at string Required in parent
Format: date-time
Example: "2026-09-28T17:41:09.512340Z"

OpenAPI response schema

{
  "$ref": "#/components/schemas/CustomBehavior"
}
Example
JSON
{ "id": "6f1c2a9e-3b7d-4c55-9a0e-2d8f4b1c7e93", "name": "Refund promise", "description": "The assistant promises a refund, credit, or compensation that the policy in the system prompt does not allow.", "polarity": "negative", "created_at": "2026-09-28T17:41:09.512340Z", "updated_at": "2026-09-28T17:41:09.512340Z" }

400

Validation failed, or the project is on a legacy plan without a tier and already has 50 custom behaviors.

application/json

Field Type Requirement Description and constraints
$ object Body
Additional properties are allowed

OpenAPI response schema

{
  "type": "object",
  "additionalProperties": true
}
Invalid field
JSON
{ "description": [ "Ensure this field has at least 3 characters." ] }
Legacy-plan ceiling
JSON
{ "detail": "A project can have at most 50 custom behaviors; this one has 50, and this request adds 1. Delete unused custom behaviors before adding more." }

403

Forbidden: the API key is missing, invalid or expired; the key doesn’t grant custom_behaviors:create (Write 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 'custom_behaviors:create' permission." }
Behaviors are off for the organization
JSON
{ "detail": "Span Behaviors is not enabled for this organization." }

429

Rate limited. This endpoint allows 30 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": "Create a custom behavior",
  "operationId": "createCustomBehavior",
  "tags": [
    "Behaviors"
  ],
  "description": "Creates a behavior from a plain-language definition. New spans are scored against it from then on; past spans are not rescored.",
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/CustomBehaviorCreateRequest"
        },
        "example": {
          "name": "Refund promise",
          "description": "The assistant promises a refund, credit, or compensation that the policy in the system prompt does not allow.",
          "polarity": "negative"
        }
      }
    }
  },
  "responses": {
    "201": {
      "description": "The created behavior.",
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/CustomBehavior"
          },
          "example": {
            "id": "6f1c2a9e-3b7d-4c55-9a0e-2d8f4b1c7e93",
            "name": "Refund promise",
            "description": "The assistant promises a refund, credit, or compensation that the policy in the system prompt does not allow.",
            "polarity": "negative",
            "created_at": "2026-09-28T17:41:09.512340Z",
            "updated_at": "2026-09-28T17:41:09.512340Z"
          }
        }
      }
    },
    "400": {
      "description": "Validation failed, or the project is on a legacy plan without a tier and already has 50 custom behaviors.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          },
          "examples": {
            "validation": {
              "summary": "Invalid field",
              "value": {
                "description": [
                  "Ensure this field has at least 3 characters."
                ]
              }
            },
            "limitReached": {
              "summary": "Legacy-plan ceiling",
              "value": {
                "detail": "A project can have at most 50 custom behaviors; this one has 50, and this request adds 1. Delete unused custom behaviors before adding more."
              }
            }
          }
        }
      }
    },
    "403": {
      "description": "Forbidden: the API key is missing, invalid or expired; the key doesn't grant `custom_behaviors:create` (Write 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 'custom_behaviors:create' 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 30 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": {
    "BehaviorPolarity": {
      "type": "string",
      "enum": [
        "negative",
        "positive",
        "neutral"
      ],
      "description": "Whether the behavior firing is good or bad: `negative` (an Issue), `positive` (a Win) or `neutral` (Info). Display metadata only; it does not change how spans are scored.",
      "example": "negative"
    },
    "CustomBehavior": {
      "type": "object",
      "required": [
        "id",
        "name",
        "description",
        "polarity",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Custom behavior ID. It is also the behavior's key in analytics, filters and span verdicts.",
          "example": "6f1c2a9e-3b7d-4c55-9a0e-2d8f4b1c7e93"
        },
        "name": {
          "type": "string",
          "nullable": true,
          "maxLength": 128,
          "description": "Display name. Optional and not unique; behaviors are identified by `id`.",
          "example": "Refund promise"
        },
        "description": {
          "type": "string",
          "description": "The plain-language definition span-01 scores each span against. Say what counts and what doesn't. At least 3 characters after trimming.",
          "example": "The assistant promises a refund, credit, or compensation that the policy in the system prompt does not allow."
        },
        "polarity": {
          "$ref": "#/components/schemas/BehaviorPolarity"
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "example": "2026-09-28T17:41:09.512340Z"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time",
          "example": "2026-09-28T17:41:09.512340Z"
        }
      }
    },
    "CustomBehaviorCreateRequest": {
      "type": "object",
      "required": [
        "description"
      ],
      "properties": {
        "description": {
          "type": "string",
          "minLength": 3,
          "description": "The plain-language definition span-01 scores each span against. Say what counts and what doesn't. At least 3 characters after trimming.",
          "example": "The assistant promises a refund, credit, or compensation that the policy in the system prompt does not allow."
        },
        "name": {
          "type": "string",
          "nullable": true,
          "maxLength": 128,
          "description": "Display name. Optional and not unique. Blank is stored as `null`.",
          "example": "Refund promise"
        },
        "polarity": {
          "allOf": [
            {
              "$ref": "#/components/schemas/BehaviorPolarity"
            }
          ],
          "default": "neutral",
          "description": "Whether the behavior firing is good or bad: `negative` (an Issue), `positive` (a Win) or `neutral` (Info). Display metadata only; it does not change how spans are scored. Defaults to `neutral`."
        }
      }
    }
  },
  "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"
      }
    }
  }
}