Attach a policy
Applies a policy to every request, or to the requests for the models named. It applies from the next request on.
POST
/
agent_gateways
/
{instance_id}
/
policy_attachments
JavaScript
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const AgentGatewayPolicyAttachment = await client.agentGateways.policyAttachments.create('instance_id', {
policy: 'policy',
});
console.log(AgentGatewayPolicyAttachment.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_attachment = client.agent_gateways.policy_attachments.create(
instance_id="instance_id",
policy="policy",
)
print(agent_gateway_policy_attachment.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"),
)
policyAttachment, err := client.AgentGateways.PolicyAttachments.New(
context.TODO(),
"instance_id",
telnyx.AgentGatewayPolicyAttachmentNewParams{
Policy: "policy",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", policyAttachment.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.policyAttachments.PolicyAttachmentCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
PolicyAttachmentCreateParams params = PolicyAttachmentCreateParams.builder()
.policy("policy")
.build();
var response = client.agentGateways().policyAttachments().create("instance_id", params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
agent_gateway_policy_attachment = telnyx.agent_gateways.policy_attachments.create("instance_id", policy: "policy")
puts(agent_gateway_policy_attachment)<?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_attachment = $client->agentGateways->policyAttachments->create(
'instance_id',
policy: 'policy',
);
var_dump($agent_gateway_policy_attachment);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx agent-gateways:policy-attachments create \
--api-key 'My API Key' \
--instance-id 32ce035d-3165-4031-b1a7-a7c0c259590a \
--policy policycurl --request POST \
--url https://api.telnyx.com/v2/agent_gateways/{instance_id}/policy_attachments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"policy": "strict",
"models": [
"GLM-5.3*"
],
"priority": 10
}
'{
"data": {
"id": "3394712f-2ad5-428a-8a3d-7a08d4b2906d",
"policy": "strict",
"models": [
"GLM-5.3*"
],
"priority": 10,
"default": false,
"created_at": "2026-11-02T12:58:55.388000Z",
"updated_at": "2026-11-02T12:58:55.388000Z"
}
}{
"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": "/policy"
}
}
]
}{
"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"
}
}
]
}Authorizations
Telnyx API key
Path Parameters
The Agent Gateway's id.
Body
application/json
The policy to apply, by name.
The models whose requests the policy applies to, by name. A name can use * as a wildcard. Empty applies the policy to every request.
An attachment with a priority applies before the others.
true applies the policy only to the requests no other attachment matches.
Response
The attachment
Where an instance applies a policy.
Show child attributes
Show child attributes
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 AgentGatewayPolicyAttachment = await client.agentGateways.policyAttachments.create('instance_id', {
policy: 'policy',
});
console.log(AgentGatewayPolicyAttachment.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_attachment = client.agent_gateways.policy_attachments.create(
instance_id="instance_id",
policy="policy",
)
print(agent_gateway_policy_attachment.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"),
)
policyAttachment, err := client.AgentGateways.PolicyAttachments.New(
context.TODO(),
"instance_id",
telnyx.AgentGatewayPolicyAttachmentNewParams{
Policy: "policy",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", policyAttachment.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.policyAttachments.PolicyAttachmentCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
PolicyAttachmentCreateParams params = PolicyAttachmentCreateParams.builder()
.policy("policy")
.build();
var response = client.agentGateways().policyAttachments().create("instance_id", params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
agent_gateway_policy_attachment = telnyx.agent_gateways.policy_attachments.create("instance_id", policy: "policy")
puts(agent_gateway_policy_attachment)<?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_attachment = $client->agentGateways->policyAttachments->create(
'instance_id',
policy: 'policy',
);
var_dump($agent_gateway_policy_attachment);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx agent-gateways:policy-attachments create \
--api-key 'My API Key' \
--instance-id 32ce035d-3165-4031-b1a7-a7c0c259590a \
--policy policycurl --request POST \
--url https://api.telnyx.com/v2/agent_gateways/{instance_id}/policy_attachments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"policy": "strict",
"models": [
"GLM-5.3*"
],
"priority": 10
}
'{
"data": {
"id": "3394712f-2ad5-428a-8a3d-7a08d4b2906d",
"policy": "strict",
"models": [
"GLM-5.3*"
],
"priority": 10,
"default": false,
"created_at": "2026-11-02T12:58:55.388000Z",
"updated_at": "2026-11-02T12:58:55.388000Z"
}
}{
"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": "/policy"
}
}
]
}{
"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"
}
}
]
}