Skip to main content
POST
/
v1
/
api_keys
cURL
curl --request POST \
--url https://api.baseten.co/v1/api_keys \
--header "Authorization: Bearer $BASETEN_API_KEY" \
--data '{
  "name": "my-api-key",
  "type": "PERSONAL"
}'
import requests
import os
API_KEY = os.environ.get("BASETEN_API_KEY", "<YOUR_API_KEY>")
url = "https://api.baseten.co/v1/api_keys"

headers = {"Authorization": f"Bearer {API_KEY}"}

response = requests.request(
"POST",
url,
headers=headers,
json={'name': 'my-api-key', 'type': 'PERSONAL'}
)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: 'my-api-key', model_ids: ['aaaaaaaa']})
};

fetch('https://api.baseten.co/v1/api_keys', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.baseten.co/v1/api_keys",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'my-api-key',
'model_ids' => [
'aaaaaaaa'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.baseten.co/v1/api_keys"

payload := strings.NewReader("{\n \"name\": \"my-api-key\",\n \"model_ids\": [\n \"aaaaaaaa\"\n ]\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.baseten.co/v1/api_keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"my-api-key\",\n \"model_ids\": [\n \"aaaaaaaa\"\n ]\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.baseten.co/v1/api_keys")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"my-api-key\",\n \"model_ids\": [\n \"aaaaaaaa\"\n ]\n}"

response = http.request(request)
puts response.read_body
{
  "api_key": "<string>"
}

Authorizations

Authorization
string
header
required

Send Authorization: Bearer <api_key>. The legacy Authorization: Api-Key <api_key> scheme is also accepted.

Body

application/json

Request to create an API key.

type
enum<string>
required

Type of the API key.

Available options:
PERSONAL,
WORKSPACE_MANAGE_ALL,
WORKSPACE_EXPORT_METRICS,
WORKSPACE_INVOKE
Examples:

"PERSONAL"

"WORKSPACE_EXPORT_METRICS"

"WORKSPACE_INVOKE"

"WORKSPACE_MANAGE_ALL"

name
string | null

Optional name for the API key

Example:

"my-api-key"

model_ids
string[] | null

List of model IDs to scope the API key to, only present if type is 'WORKSPACE_EXPORT_METRICS' or 'WORKSPACE_INVOKE'

Example:
["aaaaaaaa"]

Response

200 - application/json

Represents an API key.

api_key
string
required

The API key string