> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a policy

> Changes a policy, which publishes a new version of it. A field left out stays as it is; `guardrails` and `pipeline` are replaced whole, and `model: null` removes the condition.



## OpenAPI

````yaml /openapi/source/external/agent-gateway/agent-gateway.json patch /agent_gateways/{instance_id}/policies/{name}
openapi: 3.1.0
info:
  version: 1.0.0
  title: Telnyx API
  x-latency-category: interactive
  x-endpoint-cost: light
  description: >-
    Agent Gateway authenticates, authorizes, and audits the requests agents send
    to models, tools, and other agents. Each gateway runs as a dedicated
    instance on the account's
    [*Network*](https://developers.telnyx.com/docs/network/overview). This API
    creates, lists, and deletes instances, and manages the keys, teams, spend
    logs, MCP servers, APIs, tool permissions, and guardrails on them. Each
    instance serves an OpenAI-compatible API at its `gateway_url`.
servers:
  - url: https://api.telnyx.com/v2
    description: Telnyx API v2
security:
  - bearerAuth: []
tags:
  - name: Agent Gateways
    description: Create, list, retrieve, and delete Agent Gateway instances.
  - name: Agent Gateway Keys
    description: Keys on an instance.
  - name: Agent Gateway Teams
    description: 'Teams on an instance: shared model lists, budgets, and rate limits.'
  - name: Agent Gateway Spend Logs
    description: The requests an instance served, with their cost.
  - name: Agent Gateway MCP Servers
    description: MCP servers on an instance, served to agents at one MCP endpoint.
  - name: Agent Gateway APIs
    description: REST APIs on an instance, served to agents as tools.
  - name: Agent Gateway Tool Permissions
    description: The MCP servers and tools a key or team may use.
  - name: Agent Gateway Guardrails
    description: Checks an instance runs on model and tool requests.
  - name: Agent Gateway Policies
    description: Named sets of guardrails an instance applies to requests.
  - name: Agent Gateway Policy Attachments
    description: Where an instance applies each policy.
paths:
  /agent_gateways/{instance_id}/policies/{name}:
    patch:
      tags:
        - Agent Gateway Policies
      summary: Update a policy
      description: >-
        Changes a policy, which publishes a new version of it. A field left out
        stays as it is; `guardrails` and `pipeline` are replaced whole, and
        `model: null` removes the condition.
      operationId: UpdateAgentGatewayPolicy
      parameters:
        - name: instance_id
          in: path
          required: true
          description: The Agent Gateway's `id`.
          schema:
            type: string
            format: uuid
          example: 32ce035d-3165-4031-b1a7-a7c0c259590a
        - name: name
          in: path
          required: true
          description: The policy's `name`.
          schema:
            type: string
          example: strict
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentGatewayPolicyUpdate'
            example:
              description: Baseline plus a word check
      responses:
        '200':
          description: The updated policy
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentGatewayPolicyResponse'
              example:
                data:
                  name: strict
                  description: Baseline plus a word check
                  base: baseline
                  guardrails:
                    add:
                      - no-forbidden
                    remove: []
                  model: GLM-5.3.*
                  pipeline: null
                  created_at: '2026-11-02T12:58:55.140000Z'
                  updated_at: '2026-11-02T12:58:55.178000Z'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                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
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                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
        '422':
          description: A field the update cannot change
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10027'
                    title: Unprocessable Entity
                    detail: Extra inputs are not permitted
                    meta:
                      url: https://developers.telnyx.com/docs/overview/errors/10027
                    source:
                      pointer: /name
      x-codeSamples:
        - lang: JavaScript
          source: >-
            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.update('instance_id', 'name', {
              description: 'description',
            });


            console.log(AgentGatewayPolicy.data);
        - lang: Python
          source: |
            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.update(
                instance_id="instance_id",
                name="name",
                description="description",
            )
            print(agent_gateway_policy.data)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tpolicy, err := client.AgentGateways.Policies.Update(\n\t\tcontext.TODO(),\n\t\t\"instance_id\",\n\t\t\"name\",\n\t\ttelnyx.AgentGatewayPolicyUpdateParams{\n\t\t\tDescription: telnyx.String(\"description\"),\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", policy.Data)\n}\n"
        - lang: Java
          source: >-
            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.PolicyUpdateParams;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    PolicyUpdateParams params = PolicyUpdateParams.builder()
                        .description("description")
                        .build();
                    var response = client.agentGateways().policies().update("instance_id", "name", params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            agent_gateway_policy =
            telnyx.agent_gateways.policies.update("instance_id", "name",
            description: "description")


            puts(agent_gateway_policy)
        - lang: PHP
          source: >-
            <?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->update(
                'instance_id',
                'name',
                description: 'description',
              );

              var_dump($agent_gateway_policy);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx agent-gateways:policies update \
              --api-key 'My API Key' \
              --instance-id 32ce035d-3165-4031-b1a7-a7c0c259590a \
              --name strict \
              --description description
components:
  schemas:
    AgentGatewayPolicyUpdate:
      type: object
      description: >-
        A field left out stays as it is. `guardrails` and `pipeline` are
        replaced whole, and `model: null` removes the condition. The name cannot
        change.
      properties:
        description:
          anyOf:
            - type: string
            - type: 'null'
          description: What the policy is for.
        base:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            A policy this one builds on, by name. The policy starts with the
            base's guardrails.
        guardrails:
          $ref: '#/components/schemas/AgentGatewayPolicyGuardrails'
        model:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            A condition on the model, by name or regular expression. The
            policy's guardrails run only on requests for a matching model.
            `null` matches every model.
        pipeline:
          anyOf:
            - $ref: '#/components/schemas/AgentGatewayPolicyPipeline'
            - type: 'null'
          description: Ordered steps, in place of the guardrails running independently.
    AgentGatewayPolicyResponse:
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/AgentGatewayPolicy'
    TelnyxErrors:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/TelnyxError'
    AgentGatewayPolicyGuardrails:
      type: object
      description: >-
        The guardrails a policy adds to its base's, and the ones it removes from
        them, by name.
      properties:
        add:
          type: array
          items:
            type: string
          default: []
          description: Guardrails the policy runs in addition to its base's.
        remove:
          type: array
          items:
            type: string
          default: []
          description: Guardrails from its base that the policy does not run.
    AgentGatewayPolicyPipeline:
      type: object
      description: >-
        Ordered steps that run in place of the policy's guardrails running
        independently.
      required:
        - hook
        - steps
      properties:
        hook:
          type: string
          enum:
            - before_request
            - after_request
          description: >-
            `before_request` runs the steps on the request, and `after_request`
            on the model's response.
        steps:
          type: array
          items:
            $ref: '#/components/schemas/AgentGatewayPolicyStep'
    AgentGatewayPolicy:
      type: object
      description: A named set of guardrails.
      required:
        - name
        - description
        - base
        - guardrails
        - model
        - pipeline
        - created_at
        - updated_at
      properties:
        name:
          type: string
          pattern: ^[A-Za-z0-9_.-]{1,100}$
          description: >-
            A name, unique on the instance. A request names the policy in its
            `policies` field.
        description:
          anyOf:
            - type: string
            - type: 'null'
          description: What the policy is for.
        base:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            A policy this one builds on, by name. The policy starts with the
            base's guardrails.
        guardrails:
          $ref: '#/components/schemas/AgentGatewayPolicyGuardrails'
        model:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            A condition on the model, by name or regular expression. The
            policy's guardrails run only on requests for a matching model.
            `null` matches every model.
        pipeline:
          anyOf:
            - $ref: '#/components/schemas/AgentGatewayPolicyPipeline'
            - type: 'null'
          description: Ordered steps, in place of the guardrails running independently.
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          description: >-
            When the policy's current version was created. An update creates a
            new version.
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          description: When the policy last changed.
    TelnyxError:
      type: object
      properties:
        code:
          type: string
        title:
          type: string
        detail:
          type: string
        source:
          type: object
          properties:
            pointer:
              type: string
            parameter:
              type: string
        meta:
          type: object
          properties:
            url:
              type: string
    AgentGatewayPolicyStep:
      type: object
      description: >-
        One pipeline step: a guardrail, and what happens when it passes, fails,
        or errors.
      required:
        - guardrail
      properties:
        guardrail:
          type: string
          pattern: ^[A-Za-z0-9_.-]{1,100}$
          description: A guardrail on the instance, by name.
        on_pass:
          type: string
          enum:
            - next
            - allow
            - block
            - respond
          default: allow
          description: >-
            What happens when the guardrail passes. `next` goes on to the next
            step, `allow` allows the request, `block` blocks it, and `respond`
            answers with `message`.
        on_fail:
          type: string
          enum:
            - next
            - allow
            - block
            - respond
          default: block
          description: What happens when the guardrail fails.
        on_error:
          anyOf:
            - type: string
              enum:
                - next
                - allow
                - block
                - respond
            - type: 'null'
          description: >-
            What happens when the guardrail errors. Left out, the same as
            `on_fail`.
        message:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            The response that replaces the model's when an outcome is `respond`.
            Required with `respond`.
        pass_data:
          type: boolean
          default: false
          description: >-
            `true` hands the step's modified request, such as masked text, to
            the next step.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Telnyx API key

````