Skip to content

Commit 1714b7e

Browse files
authored
fix(openai): remove openai API key parsing entirely (#15626)
## Description Closes #15585. This PR removes API key parsing from the openai integration for two reasons: 1. We were not using this anywhere (we used to tag the last 4 digits of the API key similar to how OpenAI formats theirs in UI, but tagging this was removed quite some time ago) 2. This caused errors in use cases involving `azure-identity` that involved API keys as functions (i.e. not directly storing API keys in app/memory), because we always assumed this was a string. <!-- Provide an overview of the change and motivation for the change --> ## Testing <!-- Describe your testing strategy or note what tests are included --> ## Risks <!-- Note any risks associated with this change, or "None" if no risks --> ## Additional Notes <!-- Any other information that would be helpful for reviewers -->
1 parent 53cf907 commit 1714b7e

File tree

3 files changed

+4
-18
lines changed

3 files changed

+4
-18
lines changed

ddtrace/contrib/internal/openai/patch.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ def patched_client_init(openai, pin, func, instance, args, kwargs):
185185
func(*args, **kwargs)
186186
integration = openai._datadog_integration
187187
integration._client = instance
188-
api_key = kwargs.get("api_key")
189-
if api_key is None:
190-
api_key = instance.api_key
191-
if api_key is not None:
192-
integration.user_api_key = api_key
193188
return
194189

195190

ddtrace/llmobs/_integrations/openai.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,7 @@ def __init__(self, integration_config, openai):
5050
# object that is strongly linked with configuration.
5151
super().__init__(integration_config)
5252
self._openai = openai
53-
self._user_api_key = None
5453
self._client = None
55-
if self._openai.api_key is not None:
56-
self.user_api_key = self._openai.api_key
57-
58-
@property
59-
def user_api_key(self) -> Optional[str]:
60-
"""Get a representation of the user API key for tagging."""
61-
return self._user_api_key
62-
63-
@user_api_key.setter
64-
def user_api_key(self, value: str) -> None:
65-
# Match the API key representation that OpenAI uses in their UI.
66-
self._user_api_key = "sk-...%s" % value[-4:]
6754

6855
def trace(self, pin: Pin, operation_id: str, submit_to_llmobs: bool = False, **kwargs: Dict[str, Any]) -> Span:
6956
traced_operations = (
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
openai: Resolves an issue where instantiating an OpenAI client with a non-string API key resulted in parsing issues.

0 commit comments

Comments
 (0)