> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.runtype.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.runtype.com/_mcp/server.

# Create a provider key

POST https://api.runtype.com/v1/provider-keys
Content-Type: application/json

Creates a provider credential for the active account. In an organization, Braintrust and migrated model providers (currently OpenAI, Anthropic, Google, xAI, Mixlayer, Vercel AI Gateway, Tinfoil, Amazon Bedrock, Vertex AI, Vertex AI (Claude), and generic-openai) create organization-owned connections and return connection IDs. For OpenAI, Anthropic, Google, and xAI, isDefault=true selects organization BYOK authority; false stores the connection without changing custody. Mixlayer, Vercel AI Gateway, Tinfoil, Amazon Bedrock, Vertex AI, Vertex AI (Claude), and generic-openai creates are always storage-only; use the organization-policy endpoint to select one explicitly. Personal accounts and providers that have not migrated retain provider-key ownership. Requires BYOK entitlement.

Reference: https://docs.runtype.com/api-reference/runtype-api/provider-keys/create-a-provider-key

## Authentication

- `Authorization` header (bearer token, required) — API key or Clerk session token

## Servers

- `https://api.runtype.com` (Production, default)
- `https://api.runtype-staging.com` (Staging)

## Request

### Body (application/json)

This endpoint expects an object.

- `apiKey` (string, required)
- `name` (string, required)
- `provider` (enum, required)
  - Allowed values: `openai`, `anthropic`, `google`, `xai`, `mixlayer`, `vertex`, `vertex-anthropic`, `bedrock`, `weaviate`, `vectorize`, `browser-rendering`, `tinfoil`, `vercel`, `generic-openai`, `braintrust`
- `isDefault` (boolean, optional, default: false)
- `settings` (map from string to any, optional) — Provider-specific settings. For generic-openai: baseUrl, and apiFormat. Wire format of the custom inference endpoint: "chat-completions" (default) posts to \{baseUrl}/chat/completions, "responses" posts to \{baseUrl}/responses.

## Response

### 201

Provider key created

- `providerKey` (V1ProviderKeysPostResponsesContentApplicationJsonSchemaProviderKey, required)

## Errors

### 400 Bad Request Error

Invalid request

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

### 401 Unauthorized Error

Unauthorized

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

### 402 Payment Required Error

Feature not available

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

### 403 Forbidden Error

Forbidden

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

### 500 Internal Server Error

Internal server error

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

## Types

### V1ProviderKeysPostResponsesContentApplicationJsonSchemaProviderKey

- `createdAt` (string, required)
- `id` (string, required)
- `isActive` (boolean, required)
- `isDefault` (boolean, required)
- `keyPreview` (string, required, nullable)
- `lastUsedAt` (string, required, nullable)
- `name` (string, required)
- `provider` (string, required)
- `updatedAt` (string, required)
- `usageCount` (double, required)
- `settings` (map from string to any, optional, nullable)

### ErrorDetailsItems

- `message` (string, required)
- `code` (string, optional) — Stable Runtype validation code (e.g. MISSING_REQUIRED_FIELD, INVALID_ENUM).
- `path` (string, optional) — Dotted JSON path to the offending field.
- `suggestion` (string, optional) — Actionable hint (allowed values, accepted range, …).

## Examples

**Request**

```json
{
  "apiKey": "sk-proj-EXAMPLEKEY1234567890abcdef",
  "name": "Production OpenAI Key",
  "provider": "openai",
  "isDefault": true
}
```

**Response**

```json
{
  "providerKey": {
    "createdAt": "string",
    "id": "string",
    "isActive": true,
    "isDefault": true,
    "keyPreview": "string",
    "lastUsedAt": "string",
    "name": "string",
    "provider": "string",
    "updatedAt": "string",
    "usageCount": 1.1,
    "settings": {}
  }
}
```

**SDK Code**

```python Add Provider Key
import requests

url = "https://api.runtype.com/v1/provider-keys"

payload = {
    "apiKey": "sk-proj-EXAMPLEKEY1234567890abcdef",
    "name": "Production OpenAI Key",
    "provider": "openai",
    "isDefault": True
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Add Provider Key
const url = 'https://api.runtype.com/v1/provider-keys';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"apiKey":"sk-proj-EXAMPLEKEY1234567890abcdef","name":"Production OpenAI Key","provider":"openai","isDefault":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Add Provider Key
package main

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

func main() {

	url := "https://api.runtype.com/v1/provider-keys"

	payload := strings.NewReader("{\n  \"apiKey\": \"sk-proj-EXAMPLEKEY1234567890abcdef\",\n  \"name\": \"Production OpenAI Key\",\n  \"provider\": \"openai\",\n  \"isDefault\": true\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(res)
	fmt.Println(string(body))

}
```

```ruby Add Provider Key
require 'uri'
require 'net/http'

url = URI("https://api.runtype.com/v1/provider-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  \"apiKey\": \"sk-proj-EXAMPLEKEY1234567890abcdef\",\n  \"name\": \"Production OpenAI Key\",\n  \"provider\": \"openai\",\n  \"isDefault\": true\n}"

response = http.request(request)
puts response.read_body
```

```java Add Provider Key
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.runtype.com/v1/provider-keys")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"apiKey\": \"sk-proj-EXAMPLEKEY1234567890abcdef\",\n  \"name\": \"Production OpenAI Key\",\n  \"provider\": \"openai\",\n  \"isDefault\": true\n}")
  .asString();
```

```php Add Provider Key
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.runtype.com/v1/provider-keys', [
  'body' => '{
  "apiKey": "sk-proj-EXAMPLEKEY1234567890abcdef",
  "name": "Production OpenAI Key",
  "provider": "openai",
  "isDefault": true
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Add Provider Key
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/provider-keys");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"apiKey\": \"sk-proj-EXAMPLEKEY1234567890abcdef\",\n  \"name\": \"Production OpenAI Key\",\n  \"provider\": \"openai\",\n  \"isDefault\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Add Provider Key
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "apiKey": "sk-proj-EXAMPLEKEY1234567890abcdef",
  "name": "Production OpenAI Key",
  "provider": "openai",
  "isDefault": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/provider-keys")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```