---
title: pydo.genai.update_openai_api_key()
description: Update OpenAI API Key
product: Reference
url: https://docs.digitalocean.com/reference/pydo/reference/genai/update_openai_api_key/
last_updated: "2026-11-06"
---

> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document).

# pydo.genai.update_openai_api_key()

Generated on 6 Nov 2026 from `pydo` version [`v0.45.0`](https://github.com/digitalocean/pydo/releases/tag/v0.45.0)

## Usage

```python
client.genai.update_openai_api_key(
    api_key_uuid="\"123e4567-e89b-12d3-a456-426614174000\"",
    body={
        "api_key": "\"sk-ant-12345678901234567890123456789012\"",
        "api_key_uuid": "\"12345678-1234-1234-1234-123456789012\"",
        "name": "\"Production Key\"",
    },
)
```

Returns `JSON` Raises `HttpResponseError`

## Description

To update an OpenAI API key, send a PUT request to [`/v2/gen-ai/openai/keys/{api_key_uuid}`](https://docs.digitalocean.com/reference/api/reference/agent-platform-api/index.html.md#genai_update_openai_api_key).

## Parameters

`api_key_uuid` string required

API key ID

`api_key` string optional

Example: `"sk-ant-12345678901234567890123456789012"`

OpenAI API key

`api_key_uuid` string optional

Example: `"12345678-1234-1234-1234-123456789012"`

API key ID

`name` string optional

Example: `"Production Key"`

Name of the key

## Request Sample

## Show Request Sample

```python
import os
from pydo import Client

client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))

req = {
  "api_key": "\"sk-ant-12345678901234567890123456789012\"",
  "api_key_uuid": "\"12345678-1234-1234-1234-123456789012\"",
  "name": "\"Production Key\""
}

resp = client.genai.update_openai_api_key(api_key_uuid="\"123e4567-e89b-12d3-a456-426614174000\"", body=req)
```

## Response Example

## Show Response Example

```json
{
  "api_key_info": {
    "created_at": "2023-01-01T00:00:00Z",
    "created_by": "12345",
    "deleted_at": "2023-01-01T00:00:00Z",
    "models": [],
    "name": "example name",
    "updated_at": "2023-01-01T00:00:00Z",
    "uuid": "123e4567-e89b-12d3-a456-426614174000"
  }
}
```

## More Information

See [`/v2/gen-ai/openai/keys/{api_key_uuid}`](https://docs.digitalocean.com/reference/api/reference/agent-platform-api/index.html.md#genai_update_openai_api_key) in the API reference for additional detail on responses, headers, parameters, and more.