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

# Update a provider key

PATCH https://api.runtype.com/v1/provider-keys/{id}
Content-Type: application/json

Updates a provider key or a supported organization-owned connection returned by create/list. For migrated organization model providers, isDefault=true explicitly selects organization BYOK authority; rotation and non-default metadata changes do not change custody policy.

Reference: https://docs.runtype.com/api-reference/runtype-api/provider-keys/update-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

### Path parameters

- `id` (string, required) — Provider key or organization connection ID

### Body (application/json)

This endpoint expects an object.

- `apiKey` (string, optional)
- `isActive` (boolean, optional)
- `isDefault` (boolean, optional)
- `name` (string, optional)
- `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

### 200

Provider key updated

- `providerKey` (V1ProviderKeysIdPatchResponsesContentApplicationJsonSchemaProviderKey, 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.

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

### 404 Not Found Error

Not found

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

### 409 Conflict Error

Legacy ID replacement during mixed-version rollout

- `code` (enum, required)
  - Allowed values: `ORGANIZATION_CONNECTION_MIGRATED`
- `error` (string, required)
- `replacementId` (string, required)

### 422 Unprocessable Entity Error

Mutation would leave organization credential selection ambiguous

- `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

### V1ProviderKeysIdPatchResponsesContentApplicationJsonSchemaProviderKey

- `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
{
  "isActive": true,
  "isDefault": true,
  "name": "Updated Key Name"
}
```

**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 Update Provider Key
import requests

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

payload = {
    "isActive": True,
    "isDefault": True,
    "name": "Updated Key Name"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Update Provider Key
const url = 'https://api.runtype.com/v1/provider-keys/id';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"isActive":true,"isDefault":true,"name":"Updated Key Name"}'
};

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

```go Update Provider Key
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"isActive\": true,\n  \"isDefault\": true,\n  \"name\": \"Updated Key Name\"\n}")

	req, _ := http.NewRequest("PATCH", 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 Update Provider Key
require 'uri'
require 'net/http'

url = URI("https://api.runtype.com/v1/provider-keys/id")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"isActive\": true,\n  \"isDefault\": true,\n  \"name\": \"Updated Key Name\"\n}"

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

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

HttpResponse<String> response = Unirest.patch("https://api.runtype.com/v1/provider-keys/id")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"isActive\": true,\n  \"isDefault\": true,\n  \"name\": \"Updated Key Name\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.runtype.com/v1/provider-keys/id', [
  'body' => '{
  "isActive": true,
  "isDefault": true,
  "name": "Updated Key Name"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Update Provider Key
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/provider-keys/id");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"isActive\": true,\n  \"isDefault\": true,\n  \"name\": \"Updated Key Name\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Update Provider Key
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "isActive": true,
  "isDefault": true,
  "name": "Updated Key Name"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/provider-keys/id")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
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()
```