Create a policy
Creates a named set of guardrails. It applies from the next request on, to the requests that name it in policies and to those its attachments match.
POST
/
agent_gateways
/
{instance_id}
/
policies
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const AgentGatewayPolicy = await client.agentGateways.policies.create('instance_id', {
name: 'name',
});
console.log(AgentGatewayPolicy.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
agent_gateway_policy = client.agent_gateways.policies.create(
instance_id="instance_id",
name="name",
)
print(agent_gateway_policy.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
policy, err := client.AgentGateways.Policies.New(
context.TODO(),
"instance_id",
telnyx.AgentGatewayPolicyNewParams{
Name: "name",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", policy.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.agentGateways.policies.PolicyCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
PolicyCreateParams params = PolicyCreateParams.builder()
.name("name")
.build();
var response = client.agentGateways().policies().create("instance_id", params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
agent_gateway_policy = telnyx.agent_gateways.policies.create("instance_id", name: "name")
puts(agent_gateway_policy)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$agent_gateway_policy = $client->agentGateways->policies->create(
'instance_id',
name: 'name',
);
var_dump($agent_gateway_policy);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx agent-gateways:policies create \
--api-key 'My API Key' \
--instance-id 32ce035d-3165-4031-b1a7-a7c0c259590a \
--name namecurl --request POST \
--url https://api.telnyx.com/v2/agent_gateways/{instance_id}/policies \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "baseline",
"description": "Mask personal data",
"guardrails": {
"add": [
"mask-pii"
]
}
}
'{
"data": {
"name": "baseline",
"description": "Mask personal data",
"base": null,
"guardrails": {
"add": [
"mask-pii"
],
"remove": []
},
"model": null,
"pipeline": null,
"created_at": "2026-11-02T12:58:53.995000Z",
"updated_at": "2026-11-02T12:58:53.995000Z"
}
}{
"errors": [
{
"code": "10013",
"title": "Missing association",
"detail": "One of the associated fields does not exist.",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10013"
},
"source": {
"pointer": "/base"
}
}
]
}{
"errors": [
{
"code": "10009",
"title": "Authentication failed",
"detail": "The required authentication headers were either invalid or not included in the request.",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10009"
}
}
]
}{
"errors": [
{
"code": "10005",
"title": "Resource not found",
"detail": "The requested resource or URL could not be found.",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10005"
}
}
]
}{
"errors": [
{
"code": "10027",
"title": "Unprocessable Entity",
"detail": "String should match pattern '^[A-Za-z0-9_.-]{1,100}$'",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10027"
},
"source": {
"pointer": "/name"
}
}
]
}Body
application/json
Was this page helpful?
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const AgentGatewayPolicy = await client.agentGateways.policies.create('instance_id', {
name: 'name',
});
console.log(AgentGatewayPolicy.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
agent_gateway_policy = client.agent_gateways.policies.create(
instance_id="instance_id",
name="name",
)
print(agent_gateway_policy.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
policy, err := client.AgentGateways.Policies.New(
context.TODO(),
"instance_id",
telnyx.AgentGatewayPolicyNewParams{
Name: "name",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", policy.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.agentGateways.policies.PolicyCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
PolicyCreateParams params = PolicyCreateParams.builder()
.name("name")
.build();
var response = client.agentGateways().policies().create("instance_id", params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
agent_gateway_policy = telnyx.agent_gateways.policies.create("instance_id", name: "name")
puts(agent_gateway_policy)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$agent_gateway_policy = $client->agentGateways->policies->create(
'instance_id',
name: 'name',
);
var_dump($agent_gateway_policy);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx agent-gateways:policies create \
--api-key 'My API Key' \
--instance-id 32ce035d-3165-4031-b1a7-a7c0c259590a \
--name namecurl --request POST \
--url https://api.telnyx.com/v2/agent_gateways/{instance_id}/policies \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "baseline",
"description": "Mask personal data",
"guardrails": {
"add": [
"mask-pii"
]
}
}
'{
"data": {
"name": "baseline",
"description": "Mask personal data",
"base": null,
"guardrails": {
"add": [
"mask-pii"
],
"remove": []
},
"model": null,
"pipeline": null,
"created_at": "2026-11-02T12:58:53.995000Z",
"updated_at": "2026-11-02T12:58:53.995000Z"
}
}{
"errors": [
{
"code": "10013",
"title": "Missing association",
"detail": "One of the associated fields does not exist.",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10013"
},
"source": {
"pointer": "/base"
}
}
]
}{
"errors": [
{
"code": "10009",
"title": "Authentication failed",
"detail": "The required authentication headers were either invalid or not included in the request.",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10009"
}
}
]
}{
"errors": [
{
"code": "10005",
"title": "Resource not found",
"detail": "The requested resource or URL could not be found.",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10005"
}
}
]
}{
"errors": [
{
"code": "10027",
"title": "Unprocessable Entity",
"detail": "String should match pattern '^[A-Za-z0-9_.-]{1,100}$'",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10027"
},
"source": {
"pointer": "/name"
}
}
]
}