Policy APIs

A policy is a way to apply a set of rules applied to requests made with a connection. When creating a policy you need to specify the connectionId to apply the policy to.

Policy Model

Property NameTypeDescriptionRequiredDefault
typestringThe type of the policy.YesN/A
actionstringThe action to take when the policy is violated.YesN/A
datastringThe data to use to evaluate the policy.OptionalEmpty

Available Policies and Actions

Below is a table listing each policy name and the available actions that can be taken when the policy is violated. We are continuing to add more policies and actions as we grow and with customers feedback.

Policy NameType (Identifier)Available ActionsDescription
Content FilteringContentFilteringBlock or AuditFilters content based on predefined rules by UsageGuard.
PII DetectionPIIRedact, Block, or AuditDetects and handles Personally Identifiable Information (PII).
Words ListWordListRedact, Block, or AuditFilters content based on a list of specific words.
NSFW DetectionNSFWBlock or AuditDetects Not Safe For Work (NSFW) content.
End User TrackingEndUserIdBlock or AuditTracks and associate requests to end users.
Max Token Per RequestMaxTokensBlock or ModifyLimits the number of tokens per request.
Override System PromptSystemPromptBlock or ModifyOverrides the system prompt with a custom prompt.
Max Prompt CharactersMaxPromptCharactersBlock or ModifyLimits the number of characters in a prompt.

We are continuing to add more policies and actions as we grow and with customers feedback, please check back often.

GET/management/v1/policies

List Available Policies

Example shows how to list all available system-supported policies.

Required headers

  • Name
    Authorization
    Type
    string
    Description

    Bearer token for authentication

Request

GET
/management/v1/policies
curl -X GET https://api.usageguard.com/management/v1/policies \
  -H "Authorization: Bearer {token}"
[
  {
    "type": "ContentFiltering",
    "availableActions": ["Block", "Audit"]
  },
  {
    "type": "SystemPrompt",
    "availableActions": ["Block", "Modify"]
  },
  {
    "type": "MaxPromptCharacters",
    "availableActions": ["Block", "Modify"]
  }
]

POST/management/v1/connections/:connectionId/policies

Create Policy

Example shows how to create a policy to a connection for instance to perform content filtering.

Required headers

  • Name
    Authorization
    Type
    string
    Description

    Bearer token for authentication

Required parameters

  • Name
    connectionId
    Type
    string
    Description

    The ID of the connection to apply the policy to.

Required fields

  • Name
    type
    Type
    string
    Description

    The type of the policy.

  • Name
    action
    Type
    string
    Description

    The action to take when the policy is violated.

Optional fields

  • Name
    data
    Type
    string
    Description

    The CSV string to use to evaluate the policy.

Request

POST
/management/v1/connections/:connectionId/policies
curl -X POST https://api.usageguard.com/management/v1/connections/pb9785sozy/policies \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "ContentFiltering",
    "action": "Block"
  }'
{
  "policyId": "0ymdyfvzrp",
  "updatedOnUtc": "2024-06-27T23:11:24.516947Z"
}

PUT/management/v1/connections/:connectionId/policies/:policyId

Update Policy

Example shows how to update a connection policy.

Required headers

  • Name
    Authorization
    Type
    string
    Description

    Bearer token for authentication

Required parameters

  • Name
    connectionId
    Type
    string
    Description

    The ID of the connection to update.

  • Name
    policyId
    Type
    string
    Description

    The ID of the policy to update.

Required fields

  • Name
    type
    Type
    string
    Description

    The type of the policy.

  • Name
    action
    Type
    string
    Description

    The action to take when the policy is violated.

Optional fields

  • Name
    data
    Type
    string
    Description

    The CSV string to use to evaluate the policy.

Request

PUT
/management/v1/connections/:connectionId/policies/:policyId
curl -X PUT https://api.usageguard.com/management/v1/connections/pb9785sozy/policies/0ymdyfvzrp \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "pii",
    "action": "redact"
  }'
{
  "policyId": "0ymdyfvzrp",
  "updatedOnUtc": "2024-06-27T23:11:24.516947Z"
}

DELETE/management/v1/connections/:connectionId/policies/:policyId

Delete Policy

Example shows how to delete a connection policy.

Required headers

  • Name
    Authorization
    Type
    string
    Description

    Bearer token for authentication

Required parameters

  • Name
    connectionId
    Type
    string
    Description

    The ID of the connection to delete the policy from.

  • Name
    policyId
    Type
    string
    Description

    The ID of the policy to delete.

Request

DELETE
/management/v1/connections/:connectionId/policies/:policyId
curl -X DELETE https://api.usageguard.com/management/v1/connections/pb9785sozy/policies/0ymdyfvzrp \
  -H "Authorization: Bearer {token}"
{}

GET/management/v1/connections/:connectionId/policies/:policyId

Get Policy

Example shows how to get a connection policy.

Required headers

  • Name
    Authorization
    Type
    string
    Description

    Bearer token for authentication

Required parameters

  • Name
    connectionId
    Type
    string
    Description

    The ID of the connection to get the policy from.

  • Name
    policyId
    Type
    string
    Description

    The ID of the policy to get.

Request

GET
/management/v1/connections/:connectionId/policies/:policyId
curl -X GET https://api.usageguard.com/management/v1/connections/pb9785sozy/policies/0ymdyfvzrp \
  -H "Authorization: Bearer {token}"
{
  "policyId": "0ymdyfvzrp",
  "type": "WordList",
  "policyAction": "Block",
  "data": "bannedword1, badword2, offenstiveword3",
  "created": "1721208439"
}

GET/management/v1/connections/:connectionId/policies

List Policies

Example shows how to list all policies for a connection.

Required headers

  • Name
    Authorization
    Type
    string
    Description

    Bearer token for authentication

Request

GET
/management/v1/connections/:connectionId/policies
curl -X GET https://api.usageguard.com/management/v1/connections/pb9785sozy/policies \
  -H "Authorization: Bearer {token}"
[
  {
    "connectionId": "pb9785sozy",
    "policyId": "1a2b3c4d5e",
    "type": "PII",
    "action": "Redact"        
  },
  {
    "connectionId": "pb9785sozy",
    "policyId": "2b3c4d5e6f",
    "type": "ContentFiltering",
    "action": "Block"        
  },
  {
    "connectionId": "pb9785sozy",
    "policyId": "4d5e6f7g8h",
    "type": "WordList",
    "action": "Audit",
    "data": "bannedword1, badword2, offenstiveword3"    
  }     
]

Was this page helpful?