Volume 17 ended in local generation UIs: Automatic1111 tabs and ComfyUI graphs wrapping diffusion checkpoints. Those surfaces are excellent studios. They are not a product. Volume 18 is the shipping volume: vendor SDKs, then your own API, FastAPI, Docker, and hardware (GPU).
The OpenAI Python SDK is the first production contract most teams learn. You stop clicking a WebUI and start calling a remote model with an API key, retries, streaming, and tool round-trips you already met in Vol. 15 function calling. After this page: Anthropic and Gemini—same job, different wire formats—then wrap them behind your backend.
Learning Objectives
By the end of this lesson, students should be able to:
- Contrast a local gen UI (A1111 / ComfyUI) with a hosted SDK as a product surface.
- Install and authenticate the official
openaiPython client via environment variables. - Run a chat completion (or Responses) call and read text, usage, and finish reasons.
- Stream tokens and sketch where FastAPI / SSE will sit in Module 18.2.
- Wire tools using the Vol. 15 function-calling round-trip, not ad-hoc JSON prompting.
- Treat model IDs as SKUs that change—never hard-code a nickname as architecture.
The OpenAI SDK (official openai Python / Node packages) is a typed HTTP client for OpenAI’s APIs: chat/completions or Responses, embeddings, images, audio, and assistants/tools. It is not the model. GPT-class weights live on OpenAI’s side; the SDK only serializes requests, handles auth headers, retries, and streaming. Compatible gateways (Azure OpenAI, many local servers) speak a similar wire format—still not “the OpenAI model.”
From Local Studio to Production Call
| Surface | What you operate | What ships to users |
|---|---|---|
| Automatic1111 | Gradio tabs, PNG infotext, local checkpoint | A demo on port 7860—not multi-tenant |
| ComfyUI | Tensor DAG + workflow JSON | Better reproducibility; still a studio |
| OpenAI SDK | API key + model SKU + messages/tools | A backend you can auth, meter, and deploy |
| Module 18.2 wrap | FastAPI + Docker + Redis/Celery | Your public product API |
Keep A1111/Comfy for stills R&D. When the user-facing app needs chat, RAG, or agents, call a hosted (or self-hosted compatible) API. Do not expose 7860 to the internet and call it shipping.
Client, Auth, and a First Completion
Never put keys in source. OpenAI() reads OPENAI_API_KEY. Model IDs below are teaching stand-ins—re-read current docs before a spike.
What Else the SDK Is For
Chat / Responses
- Messages + optional tools
- Vol. 15 function calling
- Agents, not just Q&A
Embeddings / audio
- Vectors for RAG (Vol. 14)
- Whisper / TTS (Vol. 16)
- Same client, different method
Images
- DALL·E / GPT Image API
- Not a replacement for SD/FLUX self-host
- Closed weights, ToS, safety filters
OpenAI vs the Rest of Module 18.1
Why start here
- Largest ecosystem + Azure / compatible servers
- Tool-calling contract students already practiced
- Images + audio + embeddings in one vendor
Related Lectures
| Lecture | Why it sits next to this SDK |
|---|---|
| A1111 / ComfyUI | Local stills UIs you are leaving as the product surface |
| Function calling | Tool round-trip the OpenAI client implements |
| DALL·E | Images API vs self-host SD/FLUX |
| Anthropic SDK | Next vendor; same shipping job |
| FastAPI / Streaming | Wrap this client behind your HTTP API |
| Authentication | Your users never see OPENAI_API_KEY |
“The OpenAI SDK is ChatGPT.” ChatGPT is a consumer app. The SDK talks to model endpoints. Second: copying a notebook that hard-codes sk-... is not authentication—that is a leak. Third: gpt-4o / gpt-4.1 / whatever ships next are product SKUs, not architectures like Stable Diffusion. Fourth: a working chat.completions.create in a laptop REPL is not a backend; Module 18.2 exists because latency, auth, queues, and cost meters are the real product.
Knowledge Check
- Short Answer: What did Volume 17 leave you with that is not a production API? Answer: Local gen UIs (Automatic1111 / ComfyUI) wrapping diffusion checkpoints.
- True/False: The OpenAI SDK contains the GPT weights. Answer: False—it is an HTTP client; weights stay on the provider (or a compatible server).
- Multiple Choice: Where should
OPENAI_API_KEYlive? (a) committed in git, (b) environment / secret store, (c) the system prompt. Answer: (b). - Short Answer: Name one usage field you should meter in production. Answer: prompt_tokens and/or completion_tokens (or total_tokens / cost).
- True/False: Streaming is done by setting
stream=Trueand iterating chunk deltas. Answer: True (chat.completions pattern). - Multiple Choice: Tool calling in this SDK implements: (a) Vol. 15 function-calling round-trip, (b) k-means, (c) DDIM steps. Answer: (a).
- Short Answer: Why wrap the SDK in FastAPI instead of giving every frontend the vendor key? Answer: Auth, rate limits, cost control, prompt/policy, and key secrecy.
- True/False: Model ID strings are stable architectures you can cite like “UNet.” Answer: False—they are changing SKUs; pin in config and re-read docs.
- Multiple Choice: Next lecture in this module: (a) Anthropic SDK, (b) DBSCAN, (c) Automatic1111. Answer: (a).
- Short Answer: When would you still use A1111/Comfy instead of the OpenAI Images API? Answer: Self-host stills, ControlNet/LoRA graphs, license/offline constraints—not consumer ChatGPT stills.
Key Takeaways
- Vol. 17 UIs are studios; Vol. 18 SDKs are how products call models.
- Official
openaiclient + env key + pin model SKUs in config. - Read
usage; stream tokens; tools follow Vol. 15, not vibes. - Never ship the vendor key to browsers; that is Module 18.2.
- Next: Anthropic SDK, then Gemini, then your API.
Lab: Same user brief via (1) A1111 txt2img still, (2) OpenAI chat explaining the still, (3) OpenAI Images API still. Discuss license, latency, and what you would put behind FastAPI. Add a tiny tool (e.g. get_sku_price) using the Vol. 15 round-trip.
Whiteboard: Box “studio UI” vs “vendor SDK” vs “your API.” Arrow secrets only into the backend. Preview streaming → SSE.
Recap: Leave Automatic1111/Comfy as labs; call models with the OpenAI SDK. Continue with Anthropic SDK.