Commit c484e0ca

Stainless Bot <107565488+stainless-bot@users.noreply.github.com>
2024-01-18 01:25:14
chore: lazy load raw resource class properties (#1087)
1 parent d5abe79
src/openai/resources/audio/audio.py
@@ -78,27 +78,67 @@ class AsyncAudio(AsyncAPIResource):
 
 class AudioWithRawResponse:
     def __init__(self, audio: Audio) -> None:
-        self.transcriptions = TranscriptionsWithRawResponse(audio.transcriptions)
-        self.translations = TranslationsWithRawResponse(audio.translations)
-        self.speech = SpeechWithRawResponse(audio.speech)
+        self._audio = audio
+
+    @cached_property
+    def transcriptions(self) -> TranscriptionsWithRawResponse:
+        return TranscriptionsWithRawResponse(self._audio.transcriptions)
+
+    @cached_property
+    def translations(self) -> TranslationsWithRawResponse:
+        return TranslationsWithRawResponse(self._audio.translations)
+
+    @cached_property
+    def speech(self) -> SpeechWithRawResponse:
+        return SpeechWithRawResponse(self._audio.speech)
 
 
 class AsyncAudioWithRawResponse:
     def __init__(self, audio: AsyncAudio) -> None:
-        self.transcriptions = AsyncTranscriptionsWithRawResponse(audio.transcriptions)
-        self.translations = AsyncTranslationsWithRawResponse(audio.translations)
-        self.speech = AsyncSpeechWithRawResponse(audio.speech)
+        self._audio = audio
+
+    @cached_property
+    def transcriptions(self) -> AsyncTranscriptionsWithRawResponse:
+        return AsyncTranscriptionsWithRawResponse(self._audio.transcriptions)
+
+    @cached_property
+    def translations(self) -> AsyncTranslationsWithRawResponse:
+        return AsyncTranslationsWithRawResponse(self._audio.translations)
+
+    @cached_property
+    def speech(self) -> AsyncSpeechWithRawResponse:
+        return AsyncSpeechWithRawResponse(self._audio.speech)
 
 
 class AudioWithStreamingResponse:
     def __init__(self, audio: Audio) -> None:
-        self.transcriptions = TranscriptionsWithStreamingResponse(audio.transcriptions)
-        self.translations = TranslationsWithStreamingResponse(audio.translations)
-        self.speech = SpeechWithStreamingResponse(audio.speech)
+        self._audio = audio
+
+    @cached_property
+    def transcriptions(self) -> TranscriptionsWithStreamingResponse:
+        return TranscriptionsWithStreamingResponse(self._audio.transcriptions)
+
+    @cached_property
+    def translations(self) -> TranslationsWithStreamingResponse:
+        return TranslationsWithStreamingResponse(self._audio.translations)
+
+    @cached_property
+    def speech(self) -> SpeechWithStreamingResponse:
+        return SpeechWithStreamingResponse(self._audio.speech)
 
 
 class AsyncAudioWithStreamingResponse:
     def __init__(self, audio: AsyncAudio) -> None:
-        self.transcriptions = AsyncTranscriptionsWithStreamingResponse(audio.transcriptions)
-        self.translations = AsyncTranslationsWithStreamingResponse(audio.translations)
-        self.speech = AsyncSpeechWithStreamingResponse(audio.speech)
+        self._audio = audio
+
+    @cached_property
+    def transcriptions(self) -> AsyncTranscriptionsWithStreamingResponse:
+        return AsyncTranscriptionsWithStreamingResponse(self._audio.transcriptions)
+
+    @cached_property
+    def translations(self) -> AsyncTranslationsWithStreamingResponse:
+        return AsyncTranslationsWithStreamingResponse(self._audio.translations)
+
+    @cached_property
+    def speech(self) -> AsyncSpeechWithStreamingResponse:
+        return AsyncSpeechWithStreamingResponse(self._audio.speech)
src/openai/resources/audio/speech.py
@@ -170,6 +170,8 @@ class AsyncSpeech(AsyncAPIResource):
 
 class SpeechWithRawResponse:
     def __init__(self, speech: Speech) -> None:
+        self._speech = speech
+
         self.create = _legacy_response.to_raw_response_wrapper(
             speech.create,
         )
@@ -177,6 +179,8 @@ class SpeechWithRawResponse:
 
 class AsyncSpeechWithRawResponse:
     def __init__(self, speech: AsyncSpeech) -> None:
+        self._speech = speech
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             speech.create,
         )
@@ -184,6 +188,8 @@ class AsyncSpeechWithRawResponse:
 
 class SpeechWithStreamingResponse:
     def __init__(self, speech: Speech) -> None:
+        self._speech = speech
+
         self.create = to_custom_streamed_response_wrapper(
             speech.create,
             StreamedBinaryAPIResponse,
@@ -192,6 +198,8 @@ class SpeechWithStreamingResponse:
 
 class AsyncSpeechWithStreamingResponse:
     def __init__(self, speech: AsyncSpeech) -> None:
+        self._speech = speech
+
         self.create = async_to_custom_streamed_response_wrapper(
             speech.create,
             AsyncStreamedBinaryAPIResponse,
src/openai/resources/audio/transcriptions.py
@@ -199,6 +199,8 @@ class AsyncTranscriptions(AsyncAPIResource):
 
 class TranscriptionsWithRawResponse:
     def __init__(self, transcriptions: Transcriptions) -> None:
+        self._transcriptions = transcriptions
+
         self.create = _legacy_response.to_raw_response_wrapper(
             transcriptions.create,
         )
@@ -206,6 +208,8 @@ class TranscriptionsWithRawResponse:
 
 class AsyncTranscriptionsWithRawResponse:
     def __init__(self, transcriptions: AsyncTranscriptions) -> None:
+        self._transcriptions = transcriptions
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             transcriptions.create,
         )
@@ -213,6 +217,8 @@ class AsyncTranscriptionsWithRawResponse:
 
 class TranscriptionsWithStreamingResponse:
     def __init__(self, transcriptions: Transcriptions) -> None:
+        self._transcriptions = transcriptions
+
         self.create = to_streamed_response_wrapper(
             transcriptions.create,
         )
@@ -220,6 +226,8 @@ class TranscriptionsWithStreamingResponse:
 
 class AsyncTranscriptionsWithStreamingResponse:
     def __init__(self, transcriptions: AsyncTranscriptions) -> None:
+        self._transcriptions = transcriptions
+
         self.create = async_to_streamed_response_wrapper(
             transcriptions.create,
         )
src/openai/resources/audio/translations.py
@@ -185,6 +185,8 @@ class AsyncTranslations(AsyncAPIResource):
 
 class TranslationsWithRawResponse:
     def __init__(self, translations: Translations) -> None:
+        self._translations = translations
+
         self.create = _legacy_response.to_raw_response_wrapper(
             translations.create,
         )
@@ -192,6 +194,8 @@ class TranslationsWithRawResponse:
 
 class AsyncTranslationsWithRawResponse:
     def __init__(self, translations: AsyncTranslations) -> None:
+        self._translations = translations
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             translations.create,
         )
@@ -199,6 +203,8 @@ class AsyncTranslationsWithRawResponse:
 
 class TranslationsWithStreamingResponse:
     def __init__(self, translations: Translations) -> None:
+        self._translations = translations
+
         self.create = to_streamed_response_wrapper(
             translations.create,
         )
@@ -206,6 +212,8 @@ class TranslationsWithStreamingResponse:
 
 class AsyncTranslationsWithStreamingResponse:
     def __init__(self, translations: AsyncTranslations) -> None:
+        self._translations = translations
+
         self.create = async_to_streamed_response_wrapper(
             translations.create,
         )
src/openai/resources/beta/assistants/assistants.py
@@ -645,7 +645,7 @@ class AsyncAssistants(AsyncAPIResource):
 
 class AssistantsWithRawResponse:
     def __init__(self, assistants: Assistants) -> None:
-        self.files = FilesWithRawResponse(assistants.files)
+        self._assistants = assistants
 
         self.create = _legacy_response.to_raw_response_wrapper(
             assistants.create,
@@ -663,10 +663,14 @@ class AssistantsWithRawResponse:
             assistants.delete,
         )
 
+    @cached_property
+    def files(self) -> FilesWithRawResponse:
+        return FilesWithRawResponse(self._assistants.files)
+
 
 class AsyncAssistantsWithRawResponse:
     def __init__(self, assistants: AsyncAssistants) -> None:
-        self.files = AsyncFilesWithRawResponse(assistants.files)
+        self._assistants = assistants
 
         self.create = _legacy_response.async_to_raw_response_wrapper(
             assistants.create,
@@ -684,10 +688,14 @@ class AsyncAssistantsWithRawResponse:
             assistants.delete,
         )
 
+    @cached_property
+    def files(self) -> AsyncFilesWithRawResponse:
+        return AsyncFilesWithRawResponse(self._assistants.files)
+
 
 class AssistantsWithStreamingResponse:
     def __init__(self, assistants: Assistants) -> None:
-        self.files = FilesWithStreamingResponse(assistants.files)
+        self._assistants = assistants
 
         self.create = to_streamed_response_wrapper(
             assistants.create,
@@ -705,10 +713,14 @@ class AssistantsWithStreamingResponse:
             assistants.delete,
         )
 
+    @cached_property
+    def files(self) -> FilesWithStreamingResponse:
+        return FilesWithStreamingResponse(self._assistants.files)
+
 
 class AsyncAssistantsWithStreamingResponse:
     def __init__(self, assistants: AsyncAssistants) -> None:
-        self.files = AsyncFilesWithStreamingResponse(assistants.files)
+        self._assistants = assistants
 
         self.create = async_to_streamed_response_wrapper(
             assistants.create,
@@ -725,3 +737,7 @@ class AsyncAssistantsWithStreamingResponse:
         self.delete = async_to_streamed_response_wrapper(
             assistants.delete,
         )
+
+    @cached_property
+    def files(self) -> AsyncFilesWithStreamingResponse:
+        return AsyncFilesWithStreamingResponse(self._assistants.files)
src/openai/resources/beta/assistants/files.py
@@ -410,6 +410,8 @@ class AsyncFiles(AsyncAPIResource):
 
 class FilesWithRawResponse:
     def __init__(self, files: Files) -> None:
+        self._files = files
+
         self.create = _legacy_response.to_raw_response_wrapper(
             files.create,
         )
@@ -426,6 +428,8 @@ class FilesWithRawResponse:
 
 class AsyncFilesWithRawResponse:
     def __init__(self, files: AsyncFiles) -> None:
+        self._files = files
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             files.create,
         )
@@ -442,6 +446,8 @@ class AsyncFilesWithRawResponse:
 
 class FilesWithStreamingResponse:
     def __init__(self, files: Files) -> None:
+        self._files = files
+
         self.create = to_streamed_response_wrapper(
             files.create,
         )
@@ -458,6 +464,8 @@ class FilesWithStreamingResponse:
 
 class AsyncFilesWithStreamingResponse:
     def __init__(self, files: AsyncFiles) -> None:
+        self._files = files
+
         self.create = async_to_streamed_response_wrapper(
             files.create,
         )
src/openai/resources/beta/threads/messages/files.py
@@ -266,6 +266,8 @@ class AsyncFiles(AsyncAPIResource):
 
 class FilesWithRawResponse:
     def __init__(self, files: Files) -> None:
+        self._files = files
+
         self.retrieve = _legacy_response.to_raw_response_wrapper(
             files.retrieve,
         )
@@ -276,6 +278,8 @@ class FilesWithRawResponse:
 
 class AsyncFilesWithRawResponse:
     def __init__(self, files: AsyncFiles) -> None:
+        self._files = files
+
         self.retrieve = _legacy_response.async_to_raw_response_wrapper(
             files.retrieve,
         )
@@ -286,6 +290,8 @@ class AsyncFilesWithRawResponse:
 
 class FilesWithStreamingResponse:
     def __init__(self, files: Files) -> None:
+        self._files = files
+
         self.retrieve = to_streamed_response_wrapper(
             files.retrieve,
         )
@@ -296,6 +302,8 @@ class FilesWithStreamingResponse:
 
 class AsyncFilesWithStreamingResponse:
     def __init__(self, files: AsyncFiles) -> None:
+        self._files = files
+
         self.retrieve = async_to_streamed_response_wrapper(
             files.retrieve,
         )
src/openai/resources/beta/threads/messages/messages.py
@@ -481,7 +481,7 @@ class AsyncMessages(AsyncAPIResource):
 
 class MessagesWithRawResponse:
     def __init__(self, messages: Messages) -> None:
-        self.files = FilesWithRawResponse(messages.files)
+        self._messages = messages
 
         self.create = _legacy_response.to_raw_response_wrapper(
             messages.create,
@@ -496,10 +496,14 @@ class MessagesWithRawResponse:
             messages.list,
         )
 
+    @cached_property
+    def files(self) -> FilesWithRawResponse:
+        return FilesWithRawResponse(self._messages.files)
+
 
 class AsyncMessagesWithRawResponse:
     def __init__(self, messages: AsyncMessages) -> None:
-        self.files = AsyncFilesWithRawResponse(messages.files)
+        self._messages = messages
 
         self.create = _legacy_response.async_to_raw_response_wrapper(
             messages.create,
@@ -514,10 +518,14 @@ class AsyncMessagesWithRawResponse:
             messages.list,
         )
 
+    @cached_property
+    def files(self) -> AsyncFilesWithRawResponse:
+        return AsyncFilesWithRawResponse(self._messages.files)
+
 
 class MessagesWithStreamingResponse:
     def __init__(self, messages: Messages) -> None:
-        self.files = FilesWithStreamingResponse(messages.files)
+        self._messages = messages
 
         self.create = to_streamed_response_wrapper(
             messages.create,
@@ -532,10 +540,14 @@ class MessagesWithStreamingResponse:
             messages.list,
         )
 
+    @cached_property
+    def files(self) -> FilesWithStreamingResponse:
+        return FilesWithStreamingResponse(self._messages.files)
+
 
 class AsyncMessagesWithStreamingResponse:
     def __init__(self, messages: AsyncMessages) -> None:
-        self.files = AsyncFilesWithStreamingResponse(messages.files)
+        self._messages = messages
 
         self.create = async_to_streamed_response_wrapper(
             messages.create,
@@ -549,3 +561,7 @@ class AsyncMessagesWithStreamingResponse:
         self.list = async_to_streamed_response_wrapper(
             messages.list,
         )
+
+    @cached_property
+    def files(self) -> AsyncFilesWithStreamingResponse:
+        return AsyncFilesWithStreamingResponse(self._messages.files)
src/openai/resources/beta/threads/runs/runs.py
@@ -681,7 +681,7 @@ class AsyncRuns(AsyncAPIResource):
 
 class RunsWithRawResponse:
     def __init__(self, runs: Runs) -> None:
-        self.steps = StepsWithRawResponse(runs.steps)
+        self._runs = runs
 
         self.create = _legacy_response.to_raw_response_wrapper(
             runs.create,
@@ -702,10 +702,14 @@ class RunsWithRawResponse:
             runs.submit_tool_outputs,
         )
 
+    @cached_property
+    def steps(self) -> StepsWithRawResponse:
+        return StepsWithRawResponse(self._runs.steps)
+
 
 class AsyncRunsWithRawResponse:
     def __init__(self, runs: AsyncRuns) -> None:
-        self.steps = AsyncStepsWithRawResponse(runs.steps)
+        self._runs = runs
 
         self.create = _legacy_response.async_to_raw_response_wrapper(
             runs.create,
@@ -726,10 +730,14 @@ class AsyncRunsWithRawResponse:
             runs.submit_tool_outputs,
         )
 
+    @cached_property
+    def steps(self) -> AsyncStepsWithRawResponse:
+        return AsyncStepsWithRawResponse(self._runs.steps)
+
 
 class RunsWithStreamingResponse:
     def __init__(self, runs: Runs) -> None:
-        self.steps = StepsWithStreamingResponse(runs.steps)
+        self._runs = runs
 
         self.create = to_streamed_response_wrapper(
             runs.create,
@@ -750,10 +758,14 @@ class RunsWithStreamingResponse:
             runs.submit_tool_outputs,
         )
 
+    @cached_property
+    def steps(self) -> StepsWithStreamingResponse:
+        return StepsWithStreamingResponse(self._runs.steps)
+
 
 class AsyncRunsWithStreamingResponse:
     def __init__(self, runs: AsyncRuns) -> None:
-        self.steps = AsyncStepsWithStreamingResponse(runs.steps)
+        self._runs = runs
 
         self.create = async_to_streamed_response_wrapper(
             runs.create,
@@ -773,3 +785,7 @@ class AsyncRunsWithStreamingResponse:
         self.submit_tool_outputs = async_to_streamed_response_wrapper(
             runs.submit_tool_outputs,
         )
+
+    @cached_property
+    def steps(self) -> AsyncStepsWithStreamingResponse:
+        return AsyncStepsWithStreamingResponse(self._runs.steps)
src/openai/resources/beta/threads/runs/steps.py
@@ -264,6 +264,8 @@ class AsyncSteps(AsyncAPIResource):
 
 class StepsWithRawResponse:
     def __init__(self, steps: Steps) -> None:
+        self._steps = steps
+
         self.retrieve = _legacy_response.to_raw_response_wrapper(
             steps.retrieve,
         )
@@ -274,6 +276,8 @@ class StepsWithRawResponse:
 
 class AsyncStepsWithRawResponse:
     def __init__(self, steps: AsyncSteps) -> None:
+        self._steps = steps
+
         self.retrieve = _legacy_response.async_to_raw_response_wrapper(
             steps.retrieve,
         )
@@ -284,6 +288,8 @@ class AsyncStepsWithRawResponse:
 
 class StepsWithStreamingResponse:
     def __init__(self, steps: Steps) -> None:
+        self._steps = steps
+
         self.retrieve = to_streamed_response_wrapper(
             steps.retrieve,
         )
@@ -294,6 +300,8 @@ class StepsWithStreamingResponse:
 
 class AsyncStepsWithStreamingResponse:
     def __init__(self, steps: AsyncSteps) -> None:
+        self._steps = steps
+
         self.retrieve = async_to_streamed_response_wrapper(
             steps.retrieve,
         )
src/openai/resources/beta/threads/threads.py
@@ -537,8 +537,7 @@ class AsyncThreads(AsyncAPIResource):
 
 class ThreadsWithRawResponse:
     def __init__(self, threads: Threads) -> None:
-        self.runs = RunsWithRawResponse(threads.runs)
-        self.messages = MessagesWithRawResponse(threads.messages)
+        self._threads = threads
 
         self.create = _legacy_response.to_raw_response_wrapper(
             threads.create,
@@ -556,11 +555,18 @@ class ThreadsWithRawResponse:
             threads.create_and_run,
         )
 
+    @cached_property
+    def runs(self) -> RunsWithRawResponse:
+        return RunsWithRawResponse(self._threads.runs)
+
+    @cached_property
+    def messages(self) -> MessagesWithRawResponse:
+        return MessagesWithRawResponse(self._threads.messages)
+
 
 class AsyncThreadsWithRawResponse:
     def __init__(self, threads: AsyncThreads) -> None:
-        self.runs = AsyncRunsWithRawResponse(threads.runs)
-        self.messages = AsyncMessagesWithRawResponse(threads.messages)
+        self._threads = threads
 
         self.create = _legacy_response.async_to_raw_response_wrapper(
             threads.create,
@@ -578,11 +584,18 @@ class AsyncThreadsWithRawResponse:
             threads.create_and_run,
         )
 
+    @cached_property
+    def runs(self) -> AsyncRunsWithRawResponse:
+        return AsyncRunsWithRawResponse(self._threads.runs)
+
+    @cached_property
+    def messages(self) -> AsyncMessagesWithRawResponse:
+        return AsyncMessagesWithRawResponse(self._threads.messages)
+
 
 class ThreadsWithStreamingResponse:
     def __init__(self, threads: Threads) -> None:
-        self.runs = RunsWithStreamingResponse(threads.runs)
-        self.messages = MessagesWithStreamingResponse(threads.messages)
+        self._threads = threads
 
         self.create = to_streamed_response_wrapper(
             threads.create,
@@ -600,11 +613,18 @@ class ThreadsWithStreamingResponse:
             threads.create_and_run,
         )
 
+    @cached_property
+    def runs(self) -> RunsWithStreamingResponse:
+        return RunsWithStreamingResponse(self._threads.runs)
+
+    @cached_property
+    def messages(self) -> MessagesWithStreamingResponse:
+        return MessagesWithStreamingResponse(self._threads.messages)
+
 
 class AsyncThreadsWithStreamingResponse:
     def __init__(self, threads: AsyncThreads) -> None:
-        self.runs = AsyncRunsWithStreamingResponse(threads.runs)
-        self.messages = AsyncMessagesWithStreamingResponse(threads.messages)
+        self._threads = threads
 
         self.create = async_to_streamed_response_wrapper(
             threads.create,
@@ -621,3 +641,11 @@ class AsyncThreadsWithStreamingResponse:
         self.create_and_run = async_to_streamed_response_wrapper(
             threads.create_and_run,
         )
+
+    @cached_property
+    def runs(self) -> AsyncRunsWithStreamingResponse:
+        return AsyncRunsWithStreamingResponse(self._threads.runs)
+
+    @cached_property
+    def messages(self) -> AsyncMessagesWithStreamingResponse:
+        return AsyncMessagesWithStreamingResponse(self._threads.messages)
src/openai/resources/beta/beta.py
@@ -64,23 +64,51 @@ class AsyncBeta(AsyncAPIResource):
 
 class BetaWithRawResponse:
     def __init__(self, beta: Beta) -> None:
-        self.assistants = AssistantsWithRawResponse(beta.assistants)
-        self.threads = ThreadsWithRawResponse(beta.threads)
+        self._beta = beta
+
+    @cached_property
+    def assistants(self) -> AssistantsWithRawResponse:
+        return AssistantsWithRawResponse(self._beta.assistants)
+
+    @cached_property
+    def threads(self) -> ThreadsWithRawResponse:
+        return ThreadsWithRawResponse(self._beta.threads)
 
 
 class AsyncBetaWithRawResponse:
     def __init__(self, beta: AsyncBeta) -> None:
-        self.assistants = AsyncAssistantsWithRawResponse(beta.assistants)
-        self.threads = AsyncThreadsWithRawResponse(beta.threads)
+        self._beta = beta
+
+    @cached_property
+    def assistants(self) -> AsyncAssistantsWithRawResponse:
+        return AsyncAssistantsWithRawResponse(self._beta.assistants)
+
+    @cached_property
+    def threads(self) -> AsyncThreadsWithRawResponse:
+        return AsyncThreadsWithRawResponse(self._beta.threads)
 
 
 class BetaWithStreamingResponse:
     def __init__(self, beta: Beta) -> None:
-        self.assistants = AssistantsWithStreamingResponse(beta.assistants)
-        self.threads = ThreadsWithStreamingResponse(beta.threads)
+        self._beta = beta
+
+    @cached_property
+    def assistants(self) -> AssistantsWithStreamingResponse:
+        return AssistantsWithStreamingResponse(self._beta.assistants)
+
+    @cached_property
+    def threads(self) -> ThreadsWithStreamingResponse:
+        return ThreadsWithStreamingResponse(self._beta.threads)
 
 
 class AsyncBetaWithStreamingResponse:
     def __init__(self, beta: AsyncBeta) -> None:
-        self.assistants = AsyncAssistantsWithStreamingResponse(beta.assistants)
-        self.threads = AsyncThreadsWithStreamingResponse(beta.threads)
+        self._beta = beta
+
+    @cached_property
+    def assistants(self) -> AsyncAssistantsWithStreamingResponse:
+        return AsyncAssistantsWithStreamingResponse(self._beta.assistants)
+
+    @cached_property
+    def threads(self) -> AsyncThreadsWithStreamingResponse:
+        return AsyncThreadsWithStreamingResponse(self._beta.threads)
src/openai/resources/chat/chat.py
@@ -46,19 +46,35 @@ class AsyncChat(AsyncAPIResource):
 
 class ChatWithRawResponse:
     def __init__(self, chat: Chat) -> None:
-        self.completions = CompletionsWithRawResponse(chat.completions)
+        self._chat = chat
+
+    @cached_property
+    def completions(self) -> CompletionsWithRawResponse:
+        return CompletionsWithRawResponse(self._chat.completions)
 
 
 class AsyncChatWithRawResponse:
     def __init__(self, chat: AsyncChat) -> None:
-        self.completions = AsyncCompletionsWithRawResponse(chat.completions)
+        self._chat = chat
+
+    @cached_property
+    def completions(self) -> AsyncCompletionsWithRawResponse:
+        return AsyncCompletionsWithRawResponse(self._chat.completions)
 
 
 class ChatWithStreamingResponse:
     def __init__(self, chat: Chat) -> None:
-        self.completions = CompletionsWithStreamingResponse(chat.completions)
+        self._chat = chat
+
+    @cached_property
+    def completions(self) -> CompletionsWithStreamingResponse:
+        return CompletionsWithStreamingResponse(self._chat.completions)
 
 
 class AsyncChatWithStreamingResponse:
     def __init__(self, chat: AsyncChat) -> None:
-        self.completions = AsyncCompletionsWithStreamingResponse(chat.completions)
+        self._chat = chat
+
+    @cached_property
+    def completions(self) -> AsyncCompletionsWithStreamingResponse:
+        return AsyncCompletionsWithStreamingResponse(self._chat.completions)
src/openai/resources/chat/completions.py
@@ -1335,6 +1335,8 @@ class AsyncCompletions(AsyncAPIResource):
 
 class CompletionsWithRawResponse:
     def __init__(self, completions: Completions) -> None:
+        self._completions = completions
+
         self.create = _legacy_response.to_raw_response_wrapper(
             completions.create,
         )
@@ -1342,6 +1344,8 @@ class CompletionsWithRawResponse:
 
 class AsyncCompletionsWithRawResponse:
     def __init__(self, completions: AsyncCompletions) -> None:
+        self._completions = completions
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             completions.create,
         )
@@ -1349,6 +1353,8 @@ class AsyncCompletionsWithRawResponse:
 
 class CompletionsWithStreamingResponse:
     def __init__(self, completions: Completions) -> None:
+        self._completions = completions
+
         self.create = to_streamed_response_wrapper(
             completions.create,
         )
@@ -1356,6 +1362,8 @@ class CompletionsWithStreamingResponse:
 
 class AsyncCompletionsWithStreamingResponse:
     def __init__(self, completions: AsyncCompletions) -> None:
+        self._completions = completions
+
         self.create = async_to_streamed_response_wrapper(
             completions.create,
         )
src/openai/resources/fine_tuning/fine_tuning.py
@@ -46,19 +46,35 @@ class AsyncFineTuning(AsyncAPIResource):
 
 class FineTuningWithRawResponse:
     def __init__(self, fine_tuning: FineTuning) -> None:
-        self.jobs = JobsWithRawResponse(fine_tuning.jobs)
+        self._fine_tuning = fine_tuning
+
+    @cached_property
+    def jobs(self) -> JobsWithRawResponse:
+        return JobsWithRawResponse(self._fine_tuning.jobs)
 
 
 class AsyncFineTuningWithRawResponse:
     def __init__(self, fine_tuning: AsyncFineTuning) -> None:
-        self.jobs = AsyncJobsWithRawResponse(fine_tuning.jobs)
+        self._fine_tuning = fine_tuning
+
+    @cached_property
+    def jobs(self) -> AsyncJobsWithRawResponse:
+        return AsyncJobsWithRawResponse(self._fine_tuning.jobs)
 
 
 class FineTuningWithStreamingResponse:
     def __init__(self, fine_tuning: FineTuning) -> None:
-        self.jobs = JobsWithStreamingResponse(fine_tuning.jobs)
+        self._fine_tuning = fine_tuning
+
+    @cached_property
+    def jobs(self) -> JobsWithStreamingResponse:
+        return JobsWithStreamingResponse(self._fine_tuning.jobs)
 
 
 class AsyncFineTuningWithStreamingResponse:
     def __init__(self, fine_tuning: AsyncFineTuning) -> None:
-        self.jobs = AsyncJobsWithStreamingResponse(fine_tuning.jobs)
+        self._fine_tuning = fine_tuning
+
+    @cached_property
+    def jobs(self) -> AsyncJobsWithStreamingResponse:
+        return AsyncJobsWithStreamingResponse(self._fine_tuning.jobs)
src/openai/resources/fine_tuning/jobs.py
@@ -553,6 +553,8 @@ class AsyncJobs(AsyncAPIResource):
 
 class JobsWithRawResponse:
     def __init__(self, jobs: Jobs) -> None:
+        self._jobs = jobs
+
         self.create = _legacy_response.to_raw_response_wrapper(
             jobs.create,
         )
@@ -572,6 +574,8 @@ class JobsWithRawResponse:
 
 class AsyncJobsWithRawResponse:
     def __init__(self, jobs: AsyncJobs) -> None:
+        self._jobs = jobs
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             jobs.create,
         )
@@ -591,6 +595,8 @@ class AsyncJobsWithRawResponse:
 
 class JobsWithStreamingResponse:
     def __init__(self, jobs: Jobs) -> None:
+        self._jobs = jobs
+
         self.create = to_streamed_response_wrapper(
             jobs.create,
         )
@@ -610,6 +616,8 @@ class JobsWithStreamingResponse:
 
 class AsyncJobsWithStreamingResponse:
     def __init__(self, jobs: AsyncJobs) -> None:
+        self._jobs = jobs
+
         self.create = async_to_streamed_response_wrapper(
             jobs.create,
         )
src/openai/resources/completions.py
@@ -1052,6 +1052,8 @@ class AsyncCompletions(AsyncAPIResource):
 
 class CompletionsWithRawResponse:
     def __init__(self, completions: Completions) -> None:
+        self._completions = completions
+
         self.create = _legacy_response.to_raw_response_wrapper(
             completions.create,
         )
@@ -1059,6 +1061,8 @@ class CompletionsWithRawResponse:
 
 class AsyncCompletionsWithRawResponse:
     def __init__(self, completions: AsyncCompletions) -> None:
+        self._completions = completions
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             completions.create,
         )
@@ -1066,6 +1070,8 @@ class AsyncCompletionsWithRawResponse:
 
 class CompletionsWithStreamingResponse:
     def __init__(self, completions: Completions) -> None:
+        self._completions = completions
+
         self.create = to_streamed_response_wrapper(
             completions.create,
         )
@@ -1073,6 +1079,8 @@ class CompletionsWithStreamingResponse:
 
 class AsyncCompletionsWithStreamingResponse:
     def __init__(self, completions: AsyncCompletions) -> None:
+        self._completions = completions
+
         self.create = async_to_streamed_response_wrapper(
             completions.create,
         )
src/openai/resources/embeddings.py
@@ -217,6 +217,8 @@ class AsyncEmbeddings(AsyncAPIResource):
 
 class EmbeddingsWithRawResponse:
     def __init__(self, embeddings: Embeddings) -> None:
+        self._embeddings = embeddings
+
         self.create = _legacy_response.to_raw_response_wrapper(
             embeddings.create,
         )
@@ -224,6 +226,8 @@ class EmbeddingsWithRawResponse:
 
 class AsyncEmbeddingsWithRawResponse:
     def __init__(self, embeddings: AsyncEmbeddings) -> None:
+        self._embeddings = embeddings
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             embeddings.create,
         )
@@ -231,6 +235,8 @@ class AsyncEmbeddingsWithRawResponse:
 
 class EmbeddingsWithStreamingResponse:
     def __init__(self, embeddings: Embeddings) -> None:
+        self._embeddings = embeddings
+
         self.create = to_streamed_response_wrapper(
             embeddings.create,
         )
@@ -238,6 +244,8 @@ class EmbeddingsWithStreamingResponse:
 
 class AsyncEmbeddingsWithStreamingResponse:
     def __init__(self, embeddings: AsyncEmbeddings) -> None:
+        self._embeddings = embeddings
+
         self.create = async_to_streamed_response_wrapper(
             embeddings.create,
         )
src/openai/resources/files.py
@@ -580,6 +580,8 @@ class AsyncFiles(AsyncAPIResource):
 
 class FilesWithRawResponse:
     def __init__(self, files: Files) -> None:
+        self._files = files
+
         self.create = _legacy_response.to_raw_response_wrapper(
             files.create,
         )
@@ -604,6 +606,8 @@ class FilesWithRawResponse:
 
 class AsyncFilesWithRawResponse:
     def __init__(self, files: AsyncFiles) -> None:
+        self._files = files
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             files.create,
         )
@@ -628,6 +632,8 @@ class AsyncFilesWithRawResponse:
 
 class FilesWithStreamingResponse:
     def __init__(self, files: Files) -> None:
+        self._files = files
+
         self.create = to_streamed_response_wrapper(
             files.create,
         )
@@ -653,6 +659,8 @@ class FilesWithStreamingResponse:
 
 class AsyncFilesWithStreamingResponse:
     def __init__(self, files: AsyncFiles) -> None:
+        self._files = files
+
         self.create = async_to_streamed_response_wrapper(
             files.create,
         )
src/openai/resources/images.py
@@ -518,6 +518,8 @@ class AsyncImages(AsyncAPIResource):
 
 class ImagesWithRawResponse:
     def __init__(self, images: Images) -> None:
+        self._images = images
+
         self.create_variation = _legacy_response.to_raw_response_wrapper(
             images.create_variation,
         )
@@ -531,6 +533,8 @@ class ImagesWithRawResponse:
 
 class AsyncImagesWithRawResponse:
     def __init__(self, images: AsyncImages) -> None:
+        self._images = images
+
         self.create_variation = _legacy_response.async_to_raw_response_wrapper(
             images.create_variation,
         )
@@ -544,6 +548,8 @@ class AsyncImagesWithRawResponse:
 
 class ImagesWithStreamingResponse:
     def __init__(self, images: Images) -> None:
+        self._images = images
+
         self.create_variation = to_streamed_response_wrapper(
             images.create_variation,
         )
@@ -557,6 +563,8 @@ class ImagesWithStreamingResponse:
 
 class AsyncImagesWithStreamingResponse:
     def __init__(self, images: AsyncImages) -> None:
+        self._images = images
+
         self.create_variation = async_to_streamed_response_wrapper(
             images.create_variation,
         )
src/openai/resources/models.py
@@ -225,6 +225,8 @@ class AsyncModels(AsyncAPIResource):
 
 class ModelsWithRawResponse:
     def __init__(self, models: Models) -> None:
+        self._models = models
+
         self.retrieve = _legacy_response.to_raw_response_wrapper(
             models.retrieve,
         )
@@ -238,6 +240,8 @@ class ModelsWithRawResponse:
 
 class AsyncModelsWithRawResponse:
     def __init__(self, models: AsyncModels) -> None:
+        self._models = models
+
         self.retrieve = _legacy_response.async_to_raw_response_wrapper(
             models.retrieve,
         )
@@ -251,6 +255,8 @@ class AsyncModelsWithRawResponse:
 
 class ModelsWithStreamingResponse:
     def __init__(self, models: Models) -> None:
+        self._models = models
+
         self.retrieve = to_streamed_response_wrapper(
             models.retrieve,
         )
@@ -264,6 +270,8 @@ class ModelsWithStreamingResponse:
 
 class AsyncModelsWithStreamingResponse:
     def __init__(self, models: AsyncModels) -> None:
+        self._models = models
+
         self.retrieve = async_to_streamed_response_wrapper(
             models.retrieve,
         )
src/openai/resources/moderations.py
@@ -143,6 +143,8 @@ class AsyncModerations(AsyncAPIResource):
 
 class ModerationsWithRawResponse:
     def __init__(self, moderations: Moderations) -> None:
+        self._moderations = moderations
+
         self.create = _legacy_response.to_raw_response_wrapper(
             moderations.create,
         )
@@ -150,6 +152,8 @@ class ModerationsWithRawResponse:
 
 class AsyncModerationsWithRawResponse:
     def __init__(self, moderations: AsyncModerations) -> None:
+        self._moderations = moderations
+
         self.create = _legacy_response.async_to_raw_response_wrapper(
             moderations.create,
         )
@@ -157,6 +161,8 @@ class AsyncModerationsWithRawResponse:
 
 class ModerationsWithStreamingResponse:
     def __init__(self, moderations: Moderations) -> None:
+        self._moderations = moderations
+
         self.create = to_streamed_response_wrapper(
             moderations.create,
         )
@@ -164,6 +170,8 @@ class ModerationsWithStreamingResponse:
 
 class AsyncModerationsWithStreamingResponse:
     def __init__(self, moderations: AsyncModerations) -> None:
+        self._moderations = moderations
+
         self.create = async_to_streamed_response_wrapper(
             moderations.create,
         )