Transform an OpenAI API response into clean production JSON by extracting message content, token usage, model, and finish status.
2026-06-018 min read
Transforming an OpenAI API response means extracting the model output and usage fields your application actually needs, then removing the transport wrapper around them.
OpenAI responses are useful, but they are not usually the shape you want to store or send downstream. The message content lives inside choices[0].message.content, token usage is nested under usage, and fields like object, created, and system_fingerprint are often noisy for product workflows.
Use this OpenAI response cleaner when you need a stable JSON shape for logs, analytics, support tools, workflow automation, or a second processing step.
An OpenAI API response is designed to describe the API transaction, not just the useful answer. That is why a single response can include:
request identifiers
model names
one or more choices
assistant messages
finish reasons
token usage
system fingerprints
timestamps
That metadata can be valuable, but most downstream systems need a smaller contract. A product database, analytics table, support log, or webhook step usually wants the answer text, the model, and the usage numbers.
Pipeline steps
This workflow uses two transformation steps:
Extract Response Fields: creates top-level fields for response_id, message_text, finish_reason, and token usage.
Keep Production Fields: removes the wrapper fields and keeps only the clean response object.
The result is easier to validate, diff, store, and review.
When to use this workflow
Use this workflow when you need to:
extract content from an OpenAI response
log token usage without storing the whole payload
compare model outputs across runs
send the answer into another automation step
normalize OpenAI responses before analytics
If you are cleaning unpredictable model-generated JSON rather than the OpenAI API envelope, use the related LLM cleanup workflow next.
Why use a visual pipeline instead of a script?
A small script works when the shape never changes. A visual pipeline is better when you want the transformation to be inspectable, reusable, and safe for repeated API payloads.
ForgeJSON Pipeline lets you keep the cleanup steps visible:
what gets extracted
what gets removed
what the final JSON looks like
which fields downstream systems can rely on
That matters when AI responses are part of product workflows, not just one-off experiments.
FAQ
How do I extract content from an OpenAI API response?
The answer text is usually inside choices[0].message.content. This workflow extracts that content into message_text and keeps it next to the model, finish reason, and token usage.
Can I clean OpenAI responses without writing code?
Yes. Paste an OpenAI response into the pipeline, run the extraction steps, and copy the clean JSON output.
Does this parse JSON inside the message content?
This template extracts the message content as text. If the content itself contains JSON, you can add a follow-up cleanup or parsing step in ForgeJSON Pipeline.
What should I store from an OpenAI response?
For many product workflows, store the response id, model, message text, finish reason, and token counts. Keep the full raw response only when you need audit-level debugging.
Support material
Practical example and product context
Use these examples to understand the transformation and apply the same workflow in your own JSON tasks.
Before & After
Example Transformation
See how this workflow reshapes the sample material into clean output.