Skip to content

Commit cf46052

Browse files
Yun-Kimgithub-actions[bot]
authored andcommitted
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 --> (cherry picked from commit 1714b7e)
1 parent 466bc54 commit cf46052

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
@@ -193,11 +193,6 @@ def patched_client_init(openai, pin, func, instance, args, kwargs):
193193
func(*args, **kwargs)
194194
integration = openai._datadog_integration
195195
integration._client = instance
196-
api_key = kwargs.get("api_key")
197-
if api_key is None:
198-
api_key = instance.api_key
199-
if api_key is not None:
200-
integration.user_api_key = api_key
201196
return
202197

203198

ddtrace/llmobs/_integrations/openai.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,7 @@ def __init__(self, integration_config, openai):
4444
# object that is strongly linked with configuration.
4545
super().__init__(integration_config)
4646
self._openai = openai
47-
self._user_api_key = None
4847
self._client = None
49-
if self._openai.api_key is not None:
50-
self.user_api_key = self._openai.api_key
51-
52-
@property
53-
def user_api_key(self) -> Optional[str]:
54-
"""Get a representation of the user API key for tagging."""
55-
return self._user_api_key
56-
57-
@user_api_key.setter
58-
def user_api_key(self, value: str) -> None:
59-
# Match the API key representation that OpenAI uses in their UI.
60-
self._user_api_key = "sk-...%s" % value[-4:]
6148

6249
def trace(self, pin: Pin, operation_id: str, submit_to_llmobs: bool = False, **kwargs: Dict[str, Any]) -> Span:
6350
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)