/ai/token/add
POST https://api.sitehost.nz/1.5/ai/token/add.json
Creates a new AI token. The token value is only returned in this response and cannot be retrieved again, so store it securely.
Form Parameters
| Parameter | Type | Required | Description |
| client_id | integer | Yes | The ID for the client.Example: 1 |
| label | string | Yes | A label for the token, up to 255 characters.Example: Production app |
| capabilities[0] | string | Yes | The capabilities the token can use. Valid options are inference (/v1/chat/completions), embedding (/v1/embeddings) and rerank (/v1/rerank). At least one is required. This parameter accepts one or more values in the format of capabilities[0]=x, capabilities[1]=y.Example: inference |
| params[allowed_ips][0] | string | The IPv4 or IPv6 addresses or CIDR ranges allowed to use the token, up to 255 entries. If omitted, the token can be used from any address. This parameter accepts one or more values in the format of params[allowed_ips][0]=x, params[allowed_ips][1]=y.Example: 203.0.113.0/24 | |
| params[requests_per_minute] | integer | The maximum number of requests per minute. Use 0 for no limit, which is also the default.Example: 60 | |
| params[cost_limit_hourly] | number | The maximum spend per hour in NZD (excl. GST), to at most 2 decimal places. Use 0 for no limit, which is also the default.Example: 5.00 | |
| params[cost_limit_daily] | number | The maximum spend per day in NZD (excl. GST), to at most 2 decimal places. Use 0 for no limit, which is also the default.Example: 50.00 | |
| params[cost_limit_monthly] | number | The maximum spend per month in NZD (excl. GST), to at most 2 decimal places. Use 0 for no limit, which is also the default.Example: 500.00 |
Code Samples
JavaScript PHP Rails Pythonvar xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "https://api.sitehost.nz/1.5/ai/token/add.json", false);
var data = new FormData();
data.append("apikey", "your_key_here");
data.append("client_id", 1);
data.append("label", "Production app");
data.append("capabilities[0]", "inference");
data.append("params[allowed_ips][0]", "203.0.113.0\/24");
data.append("params[requests_per_minute]", 60);
data.append("params[cost_limit_hourly]", "5.00");
data.append("params[cost_limit_daily]", "50.00");
data.append("params[cost_limit_monthly]", "500.00");
xmlHttp.send(data);
var response = xmlHttp.responseText;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sitehost.nz/1.5/ai/token/add.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$body = array(
'apikey' => 'your_key_here',
'client_id' => 1,
'label' => 'Production app',
'capabilities[0]' => 'inference',
'params[allowed_ips][0]' => '203.0.113.0/24',
'params[requests_per_minute]' => 60,
'params[cost_limit_hourly]' => '5.00',
'params[cost_limit_daily]' => '50.00',
'params[cost_limit_monthly]' => '500.00',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
require 'net/http'
require 'uri'
uri = URI.parse("https://api.sitehost.nz/1.5/ai/token/add.json")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
body = {"apikey" => "your_key_here",
"client_id" => 1,
"label" => "Production app",
"capabilities[0]" => "inference",
"params[allowed_ips][0]" => "203.0.113.0/24",
"params[requests_per_minute]" => 60,
"params[cost_limit_hourly]" => "5.00",
"params[cost_limit_daily]" => "50.00",
"params[cost_limit_monthly]" => "500.00",
}
request.set_form_data(body)
response = http.request(request)
import requests
from collections import OrderedDict
uri = 'https://api.sitehost.nz/1.5/ai/token/add.json'
# We need ordered dictionary because parameters have to be in the right order.
# Refer to Developer Notes for more information.
body = OrderedDict()
body['apikey'] = 'your_key_here'
body['client_id'] = 1
body['label'] = 'Production app'
body['capabilities[0]'] = 'inference'
body['params[allowed_ips][0]'] = '203.0.113.0/24'
body['params[requests_per_minute]'] = 60
body['params[cost_limit_hourly]'] = '5.00'
body['params[cost_limit_daily]'] = '50.00'
body['params[cost_limit_monthly]'] = '500.00'
response = requests.post(uri, data=body)
Response
200:application/json
{
"return": {
"key_id": "3f6c2a9e-8b14-4d7a-9c5e-1a2b3c4d5e6f",
"label": "Production app",
"token": "a1b2c3d4e5f60718293a4b5c6d7e8f90"
},
"msg": "Successful",
"status": true
}
"return": {
"key_id": "3f6c2a9e-8b14-4d7a-9c5e-1a2b3c4d5e6f",
"label": "Production app",
"token": "a1b2c3d4e5f60718293a4b5c6d7e8f90"
},
"msg": "Successful",
"status": true
}