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.
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const AgentGatewayCreatedKey = await client.agentGateways.keys.create('instance_id', {
name: 'name',
});
console.log(AgentGatewayCreatedKey.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_created_key = client.agent_gateways.keys.create(
instance_id="instance_id",
name="name",
)
print(agent_gateway_created_key.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"),
)
key, err := client.AgentGateways.Keys.New(
context.TODO(),
"instance_id",
telnyx.AgentGatewayKeyNewParams{
Name: telnyx.String("name"),
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", key.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.keys.KeyCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
KeyCreateParams params = KeyCreateParams.builder()
.name("name")
.build();
var response = client.agentGateways().keys().create("instance_id", params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
agent_gateway_created_key = telnyx.agent_gateways.keys.create("instance_id", name: "name")
puts(agent_gateway_created_key)<?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_created_key = $client->agentGateways->keys->create(
'instance_id',
name: 'name',
);
var_dump($agent_gateway_created_key);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx agent-gateways:keys create \
--api-key 'My API Key' \
--instance-id ecffdf4b-93ea-4a7b-8295-51dfd2077996 \
--name namecurl --request POST \
--url https://api.telnyx.com/v2/agent_gateways/{instance_id}/keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"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
}
'{
"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"
}
}{
"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"
}
}
]
}{
"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": "99901",
"title": "Instance not ready",
"detail": "The instance is not ready; its engine is not running."
}
]
}{
"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"
}
}
]
}{
"errors": [
{
"code": "99903",
"title": "Engine unavailable",
"detail": "The instance's engine did not answer; try again shortly."
}
]
}Authorizations
Telnyx API key
Path Parameters
The Agent Gateway's id.
Body
A label for people, unique on the instance.
1 - 100The models the key may use. Leave it out to allow every model.
1001 - 200The most the key may spend, in USD.
x >= 0How often the spend resets: a number and a unit, s, m, h, or d.
^[1-9][0-9]{0,6}[smhd]$"30d"
How long until the key stops working: a number and a unit, s, m, h, or d.
^[1-9][0-9]{0,6}[smhd]$"30d"
A team on the instance. The key shares the team's model list, budget, and rate limits.
The most requests the key may make per minute.
1 <= x <= 2147483647The most tokens the key may use per minute.
1 <= x <= 2147483647The most requests the key may have in flight at once.
1 <= x <= 2147483647Response
The key, with its value
A key that was just issued: the only response that carries its value.
Show child attributes
Show child attributes
Was this page helpful?
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const AgentGatewayCreatedKey = await client.agentGateways.keys.create('instance_id', {
name: 'name',
});
console.log(AgentGatewayCreatedKey.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_created_key = client.agent_gateways.keys.create(
instance_id="instance_id",
name="name",
)
print(agent_gateway_created_key.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"),
)
key, err := client.AgentGateways.Keys.New(
context.TODO(),
"instance_id",
telnyx.AgentGatewayKeyNewParams{
Name: telnyx.String("name"),
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", key.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.keys.KeyCreateParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
KeyCreateParams params = KeyCreateParams.builder()
.name("name")
.build();
var response = client.agentGateways().keys().create("instance_id", params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
agent_gateway_created_key = telnyx.agent_gateways.keys.create("instance_id", name: "name")
puts(agent_gateway_created_key)<?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_created_key = $client->agentGateways->keys->create(
'instance_id',
name: 'name',
);
var_dump($agent_gateway_created_key);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx agent-gateways:keys create \
--api-key 'My API Key' \
--instance-id ecffdf4b-93ea-4a7b-8295-51dfd2077996 \
--name namecurl --request POST \
--url https://api.telnyx.com/v2/agent_gateways/{instance_id}/keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"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
}
'{
"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"
}
}{
"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"
}
}
]
}{
"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": "99901",
"title": "Instance not ready",
"detail": "The instance is not ready; its engine is not running."
}
]
}{
"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"
}
}
]
}{
"errors": [
{
"code": "99903",
"title": "Engine unavailable",
"detail": "The instance's engine did not answer; try again shortly."
}
]
}