> ## 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.

# Create a key

> Issues a key on the instance. The key's value is in this response only. Every field is optional; a key without `models` may use every model the instance serves. The instance must be `ready`; otherwise the request answers `409`.



## OpenAPI

````yaml /openapi/source/external/agent-gateway/agent-gateway.json post /agent_gateways/{instance_id}/keys
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}/keys:
    post:
      tags:
        - Agent Gateway Keys
      summary: Create a key
      description: >-
        Issues a key on the instance. The key's value is in this response only.
        Every field is optional; a key without `models` may use every model the
        instance serves. The instance must be `ready`; otherwise the request
        answers `409`.
      operationId: CreateAgentGatewayKey
      parameters:
        - name: instance_id
          in: path
          required: true
          description: The Agent Gateway's `id`.
          schema:
            type: string
            format: uuid
          example: ecffdf4b-93ea-4a7b-8295-51dfd2077996
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentGatewayKeyCreate'
            examples:
              team_key:
                summary: A key in a team, with a budget and rate limits
                value:
                  name: support-agent
                  team_id: 0b6c5d4e-3f2a-4b1c-9d8e-7f6a5b4c3d2e
                  models:
                    - GLM-5.3-Flash
                  max_budget: 20
                  budget_resets_every: 30d
                  requests_per_minute: 60
                  max_parallel_requests: 4
      responses:
        '201':
          description: The key, with its value
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentGatewayCreatedKeyResponse'
              example:
                data:
                  id: >-
                    5f1c3a0e9b7d4c2a8e6f0b1d3c5a7e9f2b4d6c8a0e1f3a5c7e9b1d3f5a7c9e0b
                  name: support-agent
                  team_id: 0b6c5d4e-3f2a-4b1c-9d8e-7f6a5b4c3d2e
                  models:
                    - GLM-5.3-Flash
                  max_budget: 20
                  budget_resets_every: 30d
                  budget_resets_at: '2026-11-20T19:40:00Z'
                  spend: 0
                  expires_at: null
                  created_at: '2026-10-21T19:40:00Z'
                  blocked: false
                  requests_per_minute: 60
                  tokens_per_minute: null
                  max_parallel_requests: 4
                  key: sk-EXAMPLE-KEY-VALUE
        '400':
          description: The team does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10013'
                    title: Missing association
                    detail: One of the associated fields does not exist.
                    source:
                      pointer: /team_id
                    meta:
                      url: https://developers.telnyx.com/docs/overview/errors/10013
        '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
        '409':
          description: The instance is not `ready`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '99901'
                    title: Instance not ready
                    detail: The instance is not ready; its engine is not running.
        '422':
          description: Invalid request body
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10033'
                    title: Value outside of range
                    detail: Input should be greater than or equal to 0
                    source:
                      pointer: /max_budget
                    meta:
                      url: https://developers.telnyx.com/docs/overview/errors/10033
        '502':
          description: The instance's engine did not answer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '99903'
                    title: Engine unavailable
                    detail: The instance's engine did not answer; try again shortly.
components:
  schemas:
    AgentGatewayKeyCreate:
      type: object
      additionalProperties: false
      properties:
        name:
          anyOf:
            - type: string
              minLength: 1
              maxLength: 100
            - type: 'null'
          description: A label for people, unique on the instance.
        models:
          anyOf:
            - type: array
              items:
                type: string
                minLength: 1
                maxLength: 200
              maxItems: 100
            - type: 'null'
          description: The models the key may use. Leave it out to allow every model.
        max_budget:
          anyOf:
            - type: number
              minimum: 0
            - type: 'null'
          description: The most the key may spend, in USD.
        budget_resets_every:
          anyOf:
            - type: string
              pattern: ^[1-9][0-9]{0,6}[smhd]$
              examples:
                - 30d
            - type: 'null'
          description: >-
            How often the spend resets: a number and a unit, `s`, `m`, `h`, or
            `d`.
        expires_in:
          anyOf:
            - type: string
              pattern: ^[1-9][0-9]{0,6}[smhd]$
              examples:
                - 30d
            - type: 'null'
          description: >-
            How long until the key stops working: a number and a unit, `s`, `m`,
            `h`, or `d`.
        team_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          description: >-
            A team on the instance. The key shares the team's model list,
            budget, and rate limits.
        requests_per_minute:
          anyOf:
            - type: integer
              minimum: 1
              maximum: 2147483647
            - type: 'null'
          description: The most requests the key may make per minute.
        tokens_per_minute:
          anyOf:
            - type: integer
              minimum: 1
              maximum: 2147483647
            - type: 'null'
          description: The most tokens the key may use per minute.
        max_parallel_requests:
          anyOf:
            - type: integer
              minimum: 1
              maximum: 2147483647
            - type: 'null'
          description: The most requests the key may have in flight at once.
    AgentGatewayCreatedKeyResponse:
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/AgentGatewayCreatedKey'
    TelnyxErrors:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/TelnyxError'
    AgentGatewayCreatedKey:
      type: object
      description: 'A key that was just issued: the only response that carries its value.'
      required:
        - id
        - name
        - team_id
        - models
        - max_budget
        - budget_resets_every
        - budget_resets_at
        - spend
        - expires_at
        - created_at
        - blocked
        - requests_per_minute
        - tokens_per_minute
        - max_parallel_requests
        - key
      properties:
        id:
          type: string
          description: >-
            Identifies the key. It is a 64-character hash the instance stores in
            place of the key's value.
        name:
          anyOf:
            - type: string
            - type: 'null'
          description: A label for people; `null` when none was given.
        team_id:
          anyOf:
            - type: string
            - type: 'null'
          description: The team the key belongs to, if any.
        models:
          type: array
          items:
            type: string
          description: >-
            The models the key may use. Empty means every model the instance
            serves.
        max_budget:
          anyOf:
            - type: number
            - type: 'null'
          description: The most the key may spend, in USD, until its budget resets.
        budget_resets_every:
          anyOf:
            - type: string
            - type: 'null'
          description: How often the key's spend resets, such as `30d`.
        budget_resets_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          description: When the key's spend next resets.
        spend:
          type: number
          description: What the key has spent since its budget last reset, in USD.
        expires_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          description: When the key stops working; `null` when it does not expire.
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          description: When the key was issued.
        blocked:
          type: boolean
          description: Whether the instance refuses the key.
        requests_per_minute:
          anyOf:
            - type: integer
            - type: 'null'
          description: The most requests the key may make per minute.
        tokens_per_minute:
          anyOf:
            - type: integer
            - type: 'null'
          description: The most tokens the key may use per minute.
        max_parallel_requests:
          anyOf:
            - type: integer
            - type: 'null'
          description: The most requests the key may have in flight at once.
        key:
          type: string
          description: >-
            The key's value, sent as `Authorization: Bearer <key>` to the
            instance. Shown only in this response.
    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
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Telnyx API key

````