# Error using response\_format for json-output?

**URL:** <https://community.openai.com/t/error-using-response-format-for-json-output/1371890>\
**Category:** API\
**Created:** [January 17, 2026, 8:02pm UTC](https://community.openai.com/t/error-using-response-format-for-json-output/1371890 "2026-01-17T20:02:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rapid1898](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/rapid1898/32/450051_2.png) [@rapid1898](https://community.openai.com/u/rapid1898)\
**Post date:** [January 17, 2026, 8:02pm UTC](https://community.openai.com/t/error-using-response-format-for-json-output/1371890/1 "2026-01-17T20:02:17Z")

</div>

Hello - i try to read a txt-file, analyse some data and ouput the result in json-format using the following code:

```auto
import os, sys
from urllib.parse import urlparse
import time
from dotenv import load_dotenv
from openai import OpenAI
from pydantic import BaseModel
from typing import List

class ArticleSummary(BaseModel):
    category: str
class Messages(BaseModel):
    messages: List[ArticleSummary]

path = os.path.abspath(os.path.dirname(sys.argv[0])) 

fn = os.path.join(path, ".env")
load_dotenv(fn)
CHATGPT_API_KEY = os.environ.get("CHATGPT_API_KEY")
client = OpenAI(api_key = CHATGPT_API_KEY)

fn = os.path.join(path, "prompt.txt")
with open(fn, encoding="utf-8", errors="ignore") as f:
  lines = f.read().splitlines()
question = "\n".join(lines)

### upload txt-file for analysis
fn = os.path.join(path, "categories.txt")
vector_store = client.vector_stores.create(name="File")
file_paths = [fn]
file_streams = [open(path, "rb") for path in file_paths]
file_batch = client.vector_stores.file_batches.upload_and_poll(
  vector_store_id=vector_store.id, files=file_streams
)
print(file_batch.status)
print(file_batch.file_counts)
# exit()    

resp = client.responses.create(
  model="gpt-4o-mini",
  input=[{"role": "user", "content": question}],
  tools=[{"type": "file_search", "vector_store_ids": [vector_store.id]}],
  response_format={
      "type": "json_schema",
      "json_schema": {
          "name": "test_schema",
          "schema": Messages.model_json_schema()
      }
  }    
)

resultAnswer = resp.output[-1].content[0].text
fnResult = os.path.join(path, "result.txt")
with open(fnResult, "w", encoding="UTF-8", errors="ignore") as f:
  f.write(resultAnswer)
print(f"Result written to {fnResult}")

print(f"Program {os.path.basename( __file__ )} finished - will close soon...") 
time.sleep(5)  

```

Unfortunately i get this erroor when running the program:

`TypeError: Responses.create() got an unexpected keyword argument ‘response_format’`

How can i output the result as json-file?

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [January 17, 2026, 10:07pm UTC](https://community.openai.com/t/error-using-response-format-for-json-output/1371890/2 "2026-01-17T22:07:23Z")

</div>

You have several missteps there in forming the correct API call.

This forum post has discussion about using the server-side chat history, but the code snippet at the bottom is a fully-realized use of responses.parse() for sending in a pydantic basemodel as a text.format and the API SDK library validating and loading the output to a “parsed” alongside “content”. You can still consume the API SDK helper’s `response.output_text` to receive and save the plain text of the JSON response.

> [@Does response chaining with previous\_response\_id only work with text response type and not json\_schema or structured response type?](https://community.openai.com/t/does-response-chaining-with-previous-response-id-only-work-with-text-response-type-and-not-json-schema-or-structured-response-type/1365129/2):
>
> You can have a conversation context with a chain of previous response IDs when using “store”:true on the Responses API, even if the output is a JSON object specified by a text.format for structured output, even strict. Some caveats: If using the “playground”, it does not use response ID for chat persistence. Only the seen messages are run like a self-managed conversation, (along with unpresented encrypted reasoning that is sent back in also). It is unclear how you are asking the AI about …

---

<div class="post-metadata">

**Author:** ![rapid1898](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/rapid1898/32/450051_2.png) [@rapid1898](https://community.openai.com/u/rapid1898)\
**Post date:** [January 29, 2026, 11:03am UTC](https://community.openai.com/t/error-using-response-format-for-json-output/1371890/4 "2026-01-29T11:03:33Z")

</div>

Thanks for your response - so when i understand this correct -

in can simply forget all this stuff from the past  
`response_format={`  
` "type": "json_schema",`  
` "json_schema": {`  
` "name": "test_schema",`  
` "schema": Messages.model_json_schema()`  
` }`  
` }`

And also all the pydantic stuff i used before like:

```auto
class ArticleSummary(BaseModel)
  businessName: str
  dba: str
  ownerName: str
  ownershipPercent: str

class Messages(BaseModel)
  messages: List[ArticleSummary]

```

And simply define the json-strucurte i want in the prompt  
and get the json data output using  
`resp.output_text`

Correct?

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [January 29, 2026, 2:26pm UTC](https://community.openai.com/t/error-using-response-format-for-json-output/1371890/5 "2026-01-29T14:26:12Z")

</div>

You historically always could ask for a JSON and then have mixed results in receiving it depending on the quality of the prompt messages, with the typical symptom of the AI also wanting to chat about it.

Since mid-2023 models, you also could write that instruction about always producing JSON and turn on text.format → “type”: “json\_object” and get some more training in producing JSON. With the Responses API correct parameter:

`text={"format": { "type": "json_object"} }`

However the recommended way is to use “strict” JSON structured outputs.

`text={ "format": {"type": "json_schema", "strict": true, "name":"api_output", "schema": … } }`

Movie review JSON AI example, including a JSON schema, a definition of the JSON output to receive:

```python
from openai import OpenAI
client = OpenAI()

response = client.responses.create(
  model="gpt-4.1",
  input=[
    {
      "role": "system",
      "content": [
        {
          "type": "input_text",
          "text": "Your a movie reviewer. Using your knowledge output a movie score for the movie the user discusses with an IMDB-style rating of the movie."
        }
      ]
    },
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "\"Wayne's World 2\" Movie score?"
        }
      ]
    }
  ],
  text={
    "format": {
      "type": "json_schema",
      "name": "movie_review",
      "strict": True,
      "schema": {
        "type": "object",
        "properties": {
          "movie_title": {
            "type": "string",
            "description": "The title of the movie being reviewed."
          },
          "movie_score": {
            "type": "number",
            "description": "The review score given to the movie (1-10).",
            "minimum": 1,
            "maximum": 10
          }
        },
        "required": [
          "movie_title",
          "movie_score"
        ],
        "additionalProperties": False
      }
    }
  },
  max_output_tokens=1000,
  top_p=0.01,
  store=False,
)

```

JSON schema is a specific subset of [supported JSON keywords](https://platform.openai.com/docs/guides/structured-outputs#supported-schemas) and features.

With the API SDK library, “response.output\_text” is a collector of just the AI’s response output, without other event items seen in “output”.

* * *

The prior reply’s linked code is the opposite, not merely asking nicely, but using the OpenAI library’s method of ingesting a Pydantic BaseModel to create the strict schema, using a custom API parameter.
