chub-dev 0.1.0 → 0.1.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +55 -0
  2. package/bin/chub-mcp +2 -0
  3. package/dist/airtable/docs/database/javascript/DOC.md +1437 -0
  4. package/dist/airtable/docs/database/python/DOC.md +1735 -0
  5. package/dist/amplitude/docs/analytics/javascript/DOC.md +1282 -0
  6. package/dist/amplitude/docs/analytics/python/DOC.md +1199 -0
  7. package/dist/anthropic/docs/claude-api/javascript/DOC.md +503 -0
  8. package/dist/anthropic/docs/claude-api/python/DOC.md +389 -0
  9. package/dist/asana/docs/tasks/DOC.md +1396 -0
  10. package/dist/assemblyai/docs/transcription/DOC.md +1043 -0
  11. package/dist/atlassian/docs/confluence/javascript/DOC.md +1347 -0
  12. package/dist/atlassian/docs/confluence/python/DOC.md +1604 -0
  13. package/dist/auth0/docs/identity/javascript/DOC.md +968 -0
  14. package/dist/auth0/docs/identity/python/DOC.md +1199 -0
  15. package/dist/aws/docs/s3/javascript/DOC.md +1773 -0
  16. package/dist/aws/docs/s3/python/DOC.md +1807 -0
  17. package/dist/binance/docs/trading/javascript/DOC.md +1315 -0
  18. package/dist/binance/docs/trading/python/DOC.md +1454 -0
  19. package/dist/braintree/docs/gateway/javascript/DOC.md +1278 -0
  20. package/dist/braintree/docs/gateway/python/DOC.md +1179 -0
  21. package/dist/chromadb/docs/embeddings-db/javascript/DOC.md +1263 -0
  22. package/dist/chromadb/docs/embeddings-db/python/DOC.md +1707 -0
  23. package/dist/clerk/docs/auth/javascript/DOC.md +1220 -0
  24. package/dist/clerk/docs/auth/python/DOC.md +274 -0
  25. package/dist/cloudflare/docs/workers/javascript/DOC.md +918 -0
  26. package/dist/cloudflare/docs/workers/python/DOC.md +994 -0
  27. package/dist/cockroachdb/docs/distributed-db/DOC.md +1500 -0
  28. package/dist/cohere/docs/llm/DOC.md +1335 -0
  29. package/dist/datadog/docs/monitoring/javascript/DOC.md +1740 -0
  30. package/dist/datadog/docs/monitoring/python/DOC.md +1815 -0
  31. package/dist/deepgram/docs/speech/javascript/DOC.md +885 -0
  32. package/dist/deepgram/docs/speech/python/DOC.md +685 -0
  33. package/dist/deepl/docs/translation/javascript/DOC.md +887 -0
  34. package/dist/deepl/docs/translation/python/DOC.md +944 -0
  35. package/dist/deepseek/docs/llm/DOC.md +1220 -0
  36. package/dist/directus/docs/headless-cms/javascript/DOC.md +1128 -0
  37. package/dist/directus/docs/headless-cms/python/DOC.md +1276 -0
  38. package/dist/discord/docs/bot/javascript/DOC.md +1090 -0
  39. package/dist/discord/docs/bot/python/DOC.md +1130 -0
  40. package/dist/elasticsearch/docs/search/DOC.md +1634 -0
  41. package/dist/elevenlabs/docs/text-to-speech/javascript/DOC.md +336 -0
  42. package/dist/elevenlabs/docs/text-to-speech/python/DOC.md +552 -0
  43. package/dist/firebase/docs/auth/DOC.md +1015 -0
  44. package/dist/gemini/docs/genai/javascript/DOC.md +691 -0
  45. package/dist/gemini/docs/genai/python/DOC.md +555 -0
  46. package/dist/github/docs/octokit/DOC.md +1560 -0
  47. package/dist/google/docs/bigquery/javascript/DOC.md +1688 -0
  48. package/dist/google/docs/bigquery/python/DOC.md +1503 -0
  49. package/dist/hubspot/docs/crm/javascript/DOC.md +1805 -0
  50. package/dist/hubspot/docs/crm/python/DOC.md +2033 -0
  51. package/dist/huggingface/docs/transformers/DOC.md +948 -0
  52. package/dist/intercom/docs/messaging/javascript/DOC.md +1844 -0
  53. package/dist/intercom/docs/messaging/python/DOC.md +1797 -0
  54. package/dist/jira/docs/issues/javascript/DOC.md +1420 -0
  55. package/dist/jira/docs/issues/python/DOC.md +1492 -0
  56. package/dist/kafka/docs/streaming/javascript/DOC.md +1671 -0
  57. package/dist/kafka/docs/streaming/python/DOC.md +1464 -0
  58. package/dist/landingai-ade/docs/api/DOC.md +620 -0
  59. package/dist/landingai-ade/docs/sdk/python/DOC.md +489 -0
  60. package/dist/landingai-ade/docs/sdk/typescript/DOC.md +542 -0
  61. package/dist/landingai-ade/skills/SKILL.md +489 -0
  62. package/dist/launchdarkly/docs/feature-flags/javascript/DOC.md +1191 -0
  63. package/dist/launchdarkly/docs/feature-flags/python/DOC.md +1671 -0
  64. package/dist/linear/docs/tracker/DOC.md +1554 -0
  65. package/dist/livekit/docs/realtime/javascript/DOC.md +303 -0
  66. package/dist/livekit/docs/realtime/python/DOC.md +163 -0
  67. package/dist/mailchimp/docs/marketing/DOC.md +1420 -0
  68. package/dist/meilisearch/docs/search/DOC.md +1241 -0
  69. package/dist/microsoft/docs/onedrive/javascript/DOC.md +1421 -0
  70. package/dist/microsoft/docs/onedrive/python/DOC.md +1549 -0
  71. package/dist/mongodb/docs/atlas/DOC.md +2041 -0
  72. package/dist/notion/docs/workspace-api/javascript/DOC.md +1435 -0
  73. package/dist/notion/docs/workspace-api/python/DOC.md +1400 -0
  74. package/dist/okta/docs/identity/javascript/DOC.md +1171 -0
  75. package/dist/okta/docs/identity/python/DOC.md +1401 -0
  76. package/dist/openai/docs/chat/javascript/DOC.md +407 -0
  77. package/dist/openai/docs/chat/python/DOC.md +568 -0
  78. package/dist/paypal/docs/checkout/DOC.md +278 -0
  79. package/dist/pinecone/docs/sdk/javascript/DOC.md +984 -0
  80. package/dist/pinecone/docs/sdk/python/DOC.md +1395 -0
  81. package/dist/plaid/docs/banking/javascript/DOC.md +1163 -0
  82. package/dist/plaid/docs/banking/python/DOC.md +1203 -0
  83. package/dist/playwright-community/skills/login-flows/SKILL.md +108 -0
  84. package/dist/postmark/docs/transactional-email/DOC.md +1168 -0
  85. package/dist/prisma/docs/orm/javascript/DOC.md +1419 -0
  86. package/dist/prisma/docs/orm/python/DOC.md +1317 -0
  87. package/dist/qdrant/docs/vector-search/javascript/DOC.md +1221 -0
  88. package/dist/qdrant/docs/vector-search/python/DOC.md +1653 -0
  89. package/dist/rabbitmq/docs/message-queue/javascript/DOC.md +1193 -0
  90. package/dist/rabbitmq/docs/message-queue/python/DOC.md +1243 -0
  91. package/dist/razorpay/docs/payments/javascript/DOC.md +1219 -0
  92. package/dist/razorpay/docs/payments/python/DOC.md +1330 -0
  93. package/dist/redis/docs/key-value/javascript/DOC.md +1851 -0
  94. package/dist/redis/docs/key-value/python/DOC.md +2054 -0
  95. package/dist/registry.json +2817 -0
  96. package/dist/replicate/docs/model-hosting/DOC.md +1318 -0
  97. package/dist/resend/docs/email/DOC.md +1271 -0
  98. package/dist/salesforce/docs/crm/javascript/DOC.md +1241 -0
  99. package/dist/salesforce/docs/crm/python/DOC.md +1183 -0
  100. package/dist/search-index.json +1 -0
  101. package/dist/sendgrid/docs/email-api/javascript/DOC.md +371 -0
  102. package/dist/sendgrid/docs/email-api/python/DOC.md +656 -0
  103. package/dist/sentry/docs/error-tracking/javascript/DOC.md +1073 -0
  104. package/dist/sentry/docs/error-tracking/python/DOC.md +1309 -0
  105. package/dist/shopify/docs/storefront/DOC.md +457 -0
  106. package/dist/slack/docs/workspace/javascript/DOC.md +933 -0
  107. package/dist/slack/docs/workspace/python/DOC.md +271 -0
  108. package/dist/square/docs/payments/javascript/DOC.md +1855 -0
  109. package/dist/square/docs/payments/python/DOC.md +1728 -0
  110. package/dist/stripe/docs/api/DOC.md +1727 -0
  111. package/dist/stripe/docs/payments/DOC.md +1726 -0
  112. package/dist/stytch/docs/auth/javascript/DOC.md +1813 -0
  113. package/dist/stytch/docs/auth/python/DOC.md +1962 -0
  114. package/dist/supabase/docs/client/DOC.md +1606 -0
  115. package/dist/twilio/docs/messaging/python/DOC.md +469 -0
  116. package/dist/twilio/docs/messaging/typescript/DOC.md +946 -0
  117. package/dist/vercel/docs/platform/DOC.md +1940 -0
  118. package/dist/weaviate/docs/vector-db/javascript/DOC.md +1268 -0
  119. package/dist/weaviate/docs/vector-db/python/DOC.md +1388 -0
  120. package/dist/zendesk/docs/support/javascript/DOC.md +2150 -0
  121. package/dist/zendesk/docs/support/python/DOC.md +2297 -0
  122. package/package.json +22 -6
  123. package/skills/get-api-docs/SKILL.md +84 -0
  124. package/src/commands/annotate.js +83 -0
  125. package/src/commands/build.js +12 -1
  126. package/src/commands/feedback.js +150 -0
  127. package/src/commands/get.js +83 -42
  128. package/src/commands/search.js +7 -0
  129. package/src/index.js +43 -17
  130. package/src/lib/analytics.js +90 -0
  131. package/src/lib/annotations.js +57 -0
  132. package/src/lib/bm25.js +170 -0
  133. package/src/lib/cache.js +69 -6
  134. package/src/lib/config.js +8 -3
  135. package/src/lib/identity.js +99 -0
  136. package/src/lib/registry.js +103 -20
  137. package/src/lib/telemetry.js +86 -0
  138. package/src/mcp/server.js +177 -0
  139. package/src/mcp/tools.js +251 -0
@@ -0,0 +1,568 @@
1
+ ---
2
+ name: chat
3
+ description: "OpenAI API for text generation, chat completions, streaming, function calling, vision, embeddings, and assistants"
4
+ metadata:
5
+ languages: "python"
6
+ versions: "2.26.0"
7
+ updated-on: "2026-03-06"
8
+ source: maintainer
9
+ tags: "openai,chat,llm,ai"
10
+ ---
11
+
12
+ # OpenAI Python SDK Coding Guidelines
13
+
14
+ You are an OpenAI API coding expert. Help me with writing code using the OpenAI API calling the official Python SDK.
15
+
16
+ You can find the official SDK documentation and code samples here:
17
+ https://platform.openai.com/docs/api-reference
18
+
19
+ ## Golden Rule: Use the Correct and Current SDK
20
+
21
+ Always use the official OpenAI Python SDK to call OpenAI models, which is the standard library for all OpenAI API interactions.
22
+
23
+ **Library Name:** OpenAI Python SDK
24
+ **PyPI Package:** `openai`
25
+
26
+ **Installation:**
27
+ - **Correct:** `pip install openai`
28
+
29
+ **APIs and Usage:**
30
+ - **Correct:** `from openai import OpenAI`
31
+ - **Correct:** `client = OpenAI()`
32
+ - **Primary API (Recommended):** `client.responses.create(...)`
33
+ - **Legacy API (Still Supported):** `client.chat.completions.create(...)`
34
+
35
+ ## Initialization and API Key
36
+
37
+ Set the `OPENAI_API_KEY` environment variable; the SDK will pick it up automatically.
38
+
39
+ ```python
40
+ import os
41
+ from openai import OpenAI
42
+
43
+ # Uses the OPENAI_API_KEY environment variable
44
+ client = OpenAI()
45
+
46
+ # Or pass the API key directly (not recommended for production)
47
+ # client = OpenAI(api_key="your-api-key-here")
48
+ ```
49
+
50
+ Use `python-dotenv` or your secret manager of choice to keep keys out of source control.
51
+
52
+ ## Models (as of March 2026)
53
+
54
+ Default choices:
55
+ - **General Text Tasks:** `gpt-5.4` (frontier) or `gpt-4.1` (non-reasoning)
56
+ - **Complex Reasoning Tasks:** `gpt-5.4` or `gpt-5.4-pro`
57
+ - **Fast & Cost-Efficient:** `gpt-5-mini` or `gpt-4.1-mini`
58
+ - **Cheapest / Fastest:** `gpt-5-nano` or `gpt-4.1-nano`
59
+ - **Audio Processing:** `gpt-audio` or `gpt-audio-mini`
60
+ - **Vision Tasks:** `gpt-5.4` or `gpt-4.1`
61
+ - **Agentic Coding:** `gpt-5.3-codex`
62
+ - **Search (Chat Completions):** `gpt-5-search-api`, `gpt-4o-search-preview`, or `gpt-4o-mini-search-preview`
63
+
64
+ Frontier (reasoning, configurable effort):
65
+ - `gpt-5.4`, `gpt-5.4-2026-03-05`, `gpt-5.4-pro`, `gpt-5.4-pro-2026-03-05`
66
+ - `gpt-5.2`, `gpt-5.2-2025-12-11`, `gpt-5.2-pro`
67
+ - `gpt-5.1`, `gpt-5.1-2025-11-13`, `gpt-5.1-pro`
68
+ - `gpt-5`, `gpt-5-2025-08-07`, `gpt-5-pro`
69
+ - `gpt-5-mini`, `gpt-5-mini-2025-08-07`
70
+ - `gpt-5-nano`, `gpt-5-nano-2025-08-07`
71
+
72
+ Non-reasoning:
73
+ - `gpt-4.1`, `gpt-4.1-2025-04-14`
74
+ - `gpt-4.1-mini`, `gpt-4.1-mini-2025-04-14`
75
+ - `gpt-4.1-nano`, `gpt-4.1-nano-2025-04-14`
76
+
77
+ Reasoning (o-series, succeeded by GPT-5):
78
+ - `o3`, `o3-2025-04-16`, `o3-pro`, `o3-pro-2025-06-10`
79
+ - `o4-mini`, `o4-mini-2025-04-16`
80
+ - `o3-mini`, `o3-mini-2025-01-31`
81
+ - `o1`, `o1-2024-12-17`
82
+
83
+ Deep research: `o3-deep-research`, `o4-mini-deep-research`
84
+
85
+ Codex (agentic coding, Responses API only):
86
+ - `gpt-5.3-codex`, `gpt-5.2-codex`, `gpt-5.1-codex`, `gpt-5.1-codex-max`, `gpt-5.1-codex-mini`, `gpt-5-codex`
87
+
88
+ Audio chat: `gpt-audio`, `gpt-audio-2025-08-28`, `gpt-audio-mini`
89
+ Realtime: `gpt-realtime`, `gpt-realtime-2025-08-28`, `gpt-realtime-mini`
90
+ TTS: `gpt-4o-mini-tts`, `gpt-4o-mini-tts-2025-12-15`, `tts-1`, `tts-1-hd`
91
+ STT: `gpt-4o-transcribe`, `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`, `gpt-4o-transcribe-diarize`, `whisper-1`
92
+ Image generation: `gpt-image-1.5`, `gpt-image-1.5-2025-12-16`, `gpt-image-1`, `gpt-image-1-mini`, `chatgpt-image-latest`
93
+ Embeddings: `text-embedding-3-large`, `text-embedding-3-small`, `text-embedding-ada-002`
94
+ Moderation: `omni-moderation-latest`
95
+ Search (Chat Completions only): `gpt-5-search-api`, `gpt-4o-search-preview`, `gpt-4o-mini-search-preview`
96
+
97
+ Legacy (still available): `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo`, `gpt-3.5-turbo`
98
+
99
+ Deprecated (shutdown scheduled):
100
+ - `dall-e-3`, `dall-e-2` → May 12, 2026 (use `gpt-image-1`)
101
+ - `o1-preview`, `o1-mini` → deprecated (use `o3` or `gpt-5`)
102
+ - `codex-mini-latest` → shut down Feb 12, 2026
103
+ - `chatgpt-4o-latest` → shut down Feb 17, 2026
104
+ - `gpt-4o-realtime-preview` → Mar 24, 2026 (use `gpt-realtime`)
105
+ - `gpt-4o-mini-audio-preview` → Mar 24, 2026 (use `gpt-audio-mini`)
106
+ - `gpt-4.5-preview` → deprecated
107
+ - Assistants API → sunset Aug 26, 2026 (migrate to Responses API)
108
+
109
+ ## Basic Inference (Text Generation)
110
+
111
+ ### Primary Method: Responses API (Recommended)
112
+
113
+ ```python
114
+ from openai import OpenAI
115
+
116
+ client = OpenAI()
117
+
118
+ response = client.responses.create(
119
+ model="gpt-5.4",
120
+ instructions="You are a helpful coding assistant.",
121
+ input="How do I reverse a string in Python?",
122
+ )
123
+
124
+ print(response.output_text)
125
+ ```
126
+
127
+ ### Legacy Method: Chat Completions API
128
+
129
+ ```python
130
+ from openai import OpenAI
131
+
132
+ client = OpenAI()
133
+
134
+ completion = client.chat.completions.create(
135
+ model="gpt-4.1",
136
+ messages=[
137
+ {"role": "system", "content": "You are a helpful assistant."},
138
+ {"role": "user", "content": "How do I reverse a string in Python?"},
139
+ ],
140
+ )
141
+
142
+ print(completion.choices[0].message.content)
143
+ ```
144
+
145
+ ## Vision (Multimodal Inputs)
146
+
147
+ ### With Image URL (Responses API)
148
+
149
+ ```python
150
+ from openai import OpenAI
151
+ client = OpenAI()
152
+
153
+ response = client.responses.create(
154
+ model="gpt-4.1-mini",
155
+ input=[
156
+ {
157
+ "role": "user",
158
+ "content": [
159
+ {"type": "input_text", "text": "What is in this image?"},
160
+ {"type": "input_image", "image_url": "https://example.com/image.jpg"},
161
+ ],
162
+ }
163
+ ],
164
+ )
165
+ ```
166
+
167
+ ### With Base64 Encoded Image
168
+
169
+ ```python
170
+ import base64
171
+ from openai import OpenAI
172
+
173
+ client = OpenAI()
174
+
175
+ with open("path/to/image.png", "rb") as image_file:
176
+ b64_image = base64.b64encode(image_file.read()).decode("utf-8")
177
+
178
+ response = client.responses.create(
179
+ model="gpt-4.1-mini",
180
+ input=[
181
+ {
182
+ "role": "user",
183
+ "content": [
184
+ {"type": "input_text", "text": "What is in this image?"},
185
+ {"type": "input_image", "image_url": f"data:image/png;base64,{b64_image}"},
186
+ ],
187
+ }
188
+ ],
189
+ )
190
+ ```
191
+
192
+ ## Async Usage
193
+
194
+ ```python
195
+ import asyncio
196
+ from openai import AsyncOpenAI
197
+
198
+ client = AsyncOpenAI()
199
+
200
+ async def main():
201
+ response = await client.responses.create(
202
+ model="gpt-5.4",
203
+ input="Explain quantum computing to a beginner."
204
+ )
205
+ print(response.output_text)
206
+
207
+ asyncio.run(main())
208
+ ```
209
+
210
+ Optionally use `aiohttp` backend via `pip install openai[aiohttp]` and instantiate with `DefaultAioHttpClient()`.
211
+
212
+ ## Streaming Responses
213
+
214
+ ### Responses API Streaming
215
+
216
+ ```python
217
+ from openai import OpenAI
218
+ client = OpenAI()
219
+
220
+ stream = client.responses.create(
221
+ model="gpt-5.4",
222
+ input="Write a short story about a robot.",
223
+ stream=True,
224
+ )
225
+
226
+ for event in stream:
227
+ print(event)
228
+ ```
229
+
230
+ ### Chat Completions Streaming
231
+
232
+ ```python
233
+ from openai import OpenAI
234
+ client = OpenAI()
235
+
236
+ stream = client.chat.completions.create(
237
+ model="gpt-4.1",
238
+ messages=[{"role": "user", "content": "Tell me a joke"}],
239
+ stream=True,
240
+ )
241
+
242
+ for chunk in stream:
243
+ if chunk.choices[0].delta.content is not None:
244
+ print(chunk.choices[0].delta.content, end="")
245
+ ```
246
+
247
+ ## Function Calling (Tools)
248
+
249
+ Type-safe function calling with Pydantic helpers.
250
+
251
+ ```python
252
+ from pydantic import BaseModel
253
+ from openai import OpenAI
254
+ import openai
255
+
256
+ class WeatherQuery(BaseModel):
257
+ """Get the current weather for a location"""
258
+ location: str
259
+ unit: str = "celsius"
260
+
261
+ client = OpenAI()
262
+
263
+ completion = client.chat.completions.parse(
264
+ model="gpt-4.1",
265
+ messages=[{"role": "user", "content": "What's the weather like in Paris?"}],
266
+ tools=[openai.pydantic_function_tool(WeatherQuery)],
267
+ )
268
+
269
+ if completion.choices[0].message.tool_calls:
270
+ for tool_call in completion.choices[0].message.tool_calls:
271
+ if getattr(tool_call, "parsed_arguments", None):
272
+ print(tool_call.parsed_arguments.location)
273
+ ```
274
+
275
+ ## Structured Outputs
276
+
277
+ Auto-parse JSON into Pydantic models.
278
+
279
+ ```python
280
+ from typing import List
281
+ from pydantic import BaseModel
282
+ from openai import OpenAI
283
+
284
+ class Step(BaseModel):
285
+ explanation: str
286
+ output: str
287
+
288
+ class MathResponse(BaseModel):
289
+ steps: List[Step]
290
+ final_answer: str
291
+
292
+ client = OpenAI()
293
+ completion = client.chat.completions.parse(
294
+ model="gpt-4.1",
295
+ messages=[
296
+ {"role": "system", "content": "You are a helpful math tutor."},
297
+ {"role": "user", "content": "solve 8x + 31 = 2"},
298
+ ],
299
+ response_format=MathResponse,
300
+ )
301
+
302
+ message = completion.choices[0].message
303
+ if message.parsed:
304
+ print(message.parsed.final_answer)
305
+ ```
306
+
307
+ ## Audio Capabilities
308
+
309
+ ### Speech Synthesis (Text-to-Speech)
310
+
311
+ ```python
312
+ from openai import OpenAI
313
+ client = OpenAI()
314
+
315
+ response = client.audio.speech.create(
316
+ model="gpt-4o-mini-tts",
317
+ voice="alloy",
318
+ input="Hello, this is a test of the text to speech API."
319
+ )
320
+
321
+ with open("output.mp3", "wb") as f:
322
+ f.write(response.content)
323
+ ```
324
+
325
+ ### Audio Transcription
326
+
327
+ ```python
328
+ from openai import OpenAI
329
+ client = OpenAI()
330
+
331
+ with open("audio.mp3", "rb") as audio_file:
332
+ transcription = client.audio.transcriptions.create(
333
+ model="gpt-4o-transcribe",
334
+ file=audio_file
335
+ )
336
+ print(transcription.text)
337
+ ```
338
+
339
+ ### Audio Translation
340
+
341
+ ```python
342
+ from openai import OpenAI
343
+ client = OpenAI()
344
+
345
+ with open("audio.mp3", "rb") as audio_file:
346
+ translation = client.audio.translations.create(
347
+ model="whisper-1",
348
+ file=audio_file
349
+ )
350
+ print(translation.text)
351
+ ```
352
+
353
+ ## File Operations
354
+
355
+ ### Upload Files
356
+
357
+ ```python
358
+ from pathlib import Path
359
+ from openai import OpenAI
360
+ client = OpenAI()
361
+
362
+ file_response = client.files.create(
363
+ file=Path("training_data.jsonl"),
364
+ purpose="fine-tune"
365
+ )
366
+
367
+ print(f"File ID: {file_response.id}")
368
+ ```
369
+
370
+ ### Retrieve, Download, Delete Files
371
+
372
+ ```python
373
+ from openai import OpenAI
374
+ client = OpenAI()
375
+
376
+ # List files
377
+ files = client.files.list()
378
+
379
+ # Retrieve a specific file
380
+ file_info = client.files.retrieve("file-abc123")
381
+
382
+ # Download file content
383
+ file_content = client.files.content("file-abc123")
384
+
385
+ # Delete a file
386
+ client.files.delete("file-abc123")
387
+ ```
388
+
389
+ ## Embeddings
390
+
391
+ ```python
392
+ from openai import OpenAI
393
+ client = OpenAI()
394
+
395
+ response = client.embeddings.create(
396
+ model="text-embedding-3-small",
397
+ input="The quick brown fox jumps over the lazy dog."
398
+ )
399
+
400
+ embeddings = response.data[0].embedding
401
+ print(f"Embedding dimensions: {len(embeddings)}")
402
+ ```
403
+
404
+ ## Image Generation
405
+
406
+ ```python
407
+ from openai import OpenAI
408
+ client = OpenAI()
409
+
410
+ response = client.images.generate(
411
+ model="gpt-image-1.5",
412
+ prompt="A futuristic city skyline at sunset",
413
+ size="1024x1024",
414
+ quality="standard",
415
+ n=1,
416
+ )
417
+
418
+ image_url = response.data[0].url
419
+ print(f"Generated image: {image_url}")
420
+ ```
421
+
422
+ ## Error Handling
423
+
424
+ ```python
425
+ import openai
426
+ from openai import OpenAI
427
+ client = OpenAI()
428
+
429
+ try:
430
+ response = client.responses.create(model="gpt-5.4", input="Hello, world!")
431
+ except openai.RateLimitError:
432
+ print("Rate limit exceeded. Please wait before retrying.")
433
+ except openai.APIConnectionError:
434
+ print("Failed to connect to OpenAI API.")
435
+ except openai.AuthenticationError:
436
+ print("Invalid API key provided.")
437
+ except openai.APIStatusError as e:
438
+ print(f"API error occurred: {e.status_code}")
439
+ print(f"Error response: {e.response}")
440
+ ```
441
+
442
+ ## Request IDs and Debugging
443
+
444
+ ```python
445
+ from openai import OpenAI
446
+ client = OpenAI()
447
+
448
+ response = client.responses.create(model="gpt-5.4", input="Test message")
449
+ print(f"Request ID: {response._request_id}")
450
+ ```
451
+
452
+ ## Retries and Timeouts
453
+
454
+ ```python
455
+ from openai import OpenAI
456
+
457
+ # Configure retries
458
+ client = OpenAI(max_retries=5)
459
+
460
+ # Configure timeouts
461
+ client = OpenAI(timeout=30.0)
462
+
463
+ # Per-request configuration
464
+ response = client.with_options(
465
+ max_retries=3,
466
+ timeout=60.0
467
+ ).responses.create(
468
+ model="gpt-5.4",
469
+ input="Hello"
470
+ )
471
+ ```
472
+
473
+ ## Realtime API
474
+
475
+ ```python
476
+ import asyncio
477
+ from openai import AsyncOpenAI
478
+
479
+ async def main():
480
+ client = AsyncOpenAI()
481
+
482
+ async with client.realtime.connect(model="gpt-realtime") as connection:
483
+ await connection.session.update(session={'modalities': ['text']})
484
+
485
+ await connection.conversation.item.create(
486
+ item={
487
+ "type": "message",
488
+ "role": "user",
489
+ "content": [{"type": "input_text", "text": "Say hello!"}],
490
+ }
491
+ )
492
+ await connection.response.create()
493
+
494
+ async for event in connection:
495
+ if event.type == "response.output_text.delta":
496
+ print(event.delta, end="")
497
+ elif event.type == "response.done":
498
+ break
499
+
500
+ asyncio.run(main())
501
+ ```
502
+
503
+ ## Microsoft Azure OpenAI
504
+
505
+ ```python
506
+ from openai import AzureOpenAI
507
+
508
+ client = AzureOpenAI(
509
+ azure_endpoint="https://your-endpoint.openai.azure.com",
510
+ )
511
+
512
+ completion = client.chat.completions.create(
513
+ model="deployment-name", # Your deployment name
514
+ messages=[{"role": "user", "content": "Hello, Azure OpenAI!"}],
515
+ )
516
+ print(completion.choices[0].message.content)
517
+ ```
518
+
519
+ ## Webhook Verification
520
+
521
+ ```python
522
+ from flask import Flask, request
523
+ from openai import OpenAI
524
+
525
+ app = Flask(__name__)
526
+ client = OpenAI() # Uses OPENAI_WEBHOOK_SECRET environment variable
527
+
528
+ @app.route("/webhook", methods=["POST"])
529
+ def webhook():
530
+ request_body = request.get_data(as_text=True)
531
+
532
+ try:
533
+ event = client.webhooks.unwrap(request_body, request.headers)
534
+
535
+ if event.type == "response.completed":
536
+ print("Response completed:", event.data)
537
+
538
+ return "ok"
539
+ except Exception as e:
540
+ print("Invalid signature:", e)
541
+ return "Invalid signature", 400
542
+ ```
543
+
544
+ ## Pagination
545
+
546
+ ```python
547
+ from openai import OpenAI
548
+
549
+ client = OpenAI()
550
+
551
+ # Automatic pagination
552
+ all_files = []
553
+ for file in client.files.list(limit=20):
554
+ all_files.append(file)
555
+
556
+ # Manual pagination
557
+ first_page = client.files.list(limit=20)
558
+ if first_page.has_next_page():
559
+ next_page = first_page.get_next_page()
560
+ ```
561
+
562
+ ## Notes
563
+
564
+ - Prefer the Responses API for new work; Chat Completions remains supported.
565
+ - Keep API keys in env vars or a secret manager.
566
+ - Both sync and async clients are available; interfaces mirror each other.
567
+ - Use streaming for lower latency UX.
568
+ - Pydantic-based structured outputs and function calling provide type safety.