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 Name | Type | Description | Required | Default |
---|---|---|---|---|
type | string | The type of the policy. | Yes | N/A |
action | string | The action to take when the policy is violated. | Yes | N/A |
data | string | The data to use to evaluate the policy. | Optional | Empty |
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 Name | Type (Identifier) | Available Actions | Description |
---|---|---|---|
Content Filtering | ContentFiltering | Block or Audit | Filters content based on predefined rules by UsageGuard. |
PII Detection | PII | Redact, Block, or Audit | Detects and handles Personally Identifiable Information (PII). |
Words List | WordList | Redact, Block, or Audit | Filters content based on a list of specific words. |
NSFW Detection | NSFW | Block or Audit | Detects Not Safe For Work (NSFW) content. |
End User Tracking | EndUserId | Block or Audit | Tracks and associate requests to end users. |
Max Token Per Request | MaxTokens | Block or Modify | Limits the number of tokens per request. |
Override System Prompt | SystemPrompt | Block or Modify | Overrides the system prompt with a custom prompt. |
Max Prompt Characters | MaxPromptCharacters | Block or Modify | Limits 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.
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
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"]
}
]
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
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"
}
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
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 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
curl -X DELETE https://api.usageguard.com/management/v1/connections/pb9785sozy/policies/0ymdyfvzrp \
-H "Authorization: Bearer {token}"
{}
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
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"
}
List Policies
Example shows how to list all policies for a connection.
Required headers
- Name
Authorization
- Type
- string
- Description
Bearer token for authentication
Request
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"
}
]