Ross Masters's weblog

Chat context via an API

ChatGPT offered to create me a PDF on a document we'd been drafting today. At first I thought this might be a new in-built capability, but actually this was leveraging code execution to write a markdown→PDF script.

After a couple of minutes, I stepped into the reasoning detail to see why it was taking so long, and as is common, it was generating the markdown inline, despite the markdown already being present in the conversation.

CleanShot 2025-09-06 at 13

These abilities delight me, but the regeneration of known content seems so unnecessarily expensive. I then encountered two issues:

  1. GPT-5 took a few attempts to get the generator script working, time & energy spent on regurgitating could have been spent on iterating the script.
  2. The embedded content differed from the document I was happy with in minor ways - in an event taxonomy section, items became items[], and additional fields appeared.

In this case, the document itself was contained in an (whatever OpenAI call) artifact - so it's already separate in the data domain from any preamble and self-congratulation spam that comes in messages.

CleanShot 2025-09-06 at 13

What if each code-execution had a micro-API to programmatically access content from the chat? In this case, the script might look something like:

# Instructions/context

The following artifacts are available:
520de2cc-52f6-4845-9cbb-12dde9d7bd10 (2 mins ago): A draft of a business plan in Markdown format
af82a095-0442-4c47-984f-88dd514ad40d (just now): A revised business plan after feedback in Markdown format
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak, ListFlowable, ListItem
...
import os
import requests

# Content (from the canvas document we created)
content_md = requests.get(
    "https://chat-detail.openai.com/artifacts/af82a095-0442-4c47-984f-88dd514ad40d",
    headers={"Authorization": f"Bearer {os.getenv("CHAT_SESSION_TOKEN")}"}
)

CleanShot 2025-09-06 at 13

After all this, I spotted artifacts can be downloaded as PDFs anyway - without the rendering artifacts introduced by the generator script, that would have needed further regens. PDF exports of artifacts should probably just be a tool that uses this, but I could see some usefulness in a chat-scope API when it comes to UI artifacts (e.g. call a tool that can ship generated code straight from an artifact without generating).