> ## Documentation Index
> Fetch the complete documentation index at: https://docs.naga.ac/llms.txt
> Use this file to discover all available pages before exploring further.

# Text Generation

> Generate text with the Responses API and understand the response item model.

Use this page for the simplest `Responses API` workflow: send text in `input` and read text back from the response.

Start here if you want a plain text answer before adding tools, schema enforcement, or multimodal inputs.

## Minimal Request

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.naga.ac/v1",
      api_key="YOUR_API_KEY",
  )

  response = client.responses.create(
      model="gpt-4.1-mini",
      input="Write one sentence about graceful degradation.",
  )

  print(response.output_text)
  ```

  ```javascript Node.js theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://api.naga.ac/v1',
    apiKey: 'YOUR_API_KEY',
  });

  const response = await client.responses.create({
    model: 'gpt-4.1-mini',
    input: 'Write one sentence about graceful degradation.',
  });

  console.log(response.output_text);
  ```

  ```bash cURL theme={null}
  curl https://api.naga.ac/v1/responses \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4.1-mini",
      "input": "Write one sentence about graceful degradation."
    }'
  ```
</CodeGroup>

## Minimal Response

```json theme={null}
{
  "object": "response",
  "status": "completed",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Graceful degradation keeps a system useful even when some components fail.",
          "annotations": [],
          "logprobs": []
        }
      ]
    }
  ]
}
```

If you only need the final text, `response.output_text` is the simplest accessor in the official OpenAI SDKs.

## Response Shape At A Glance

<Tree>
  <Tree.Folder name="response" defaultOpen>
    <Tree.File name="status" />

    <Tree.Folder name="output[]" defaultOpen>
      <Tree.Folder name="message" defaultOpen>
        <Tree.File name="role" />

        <Tree.Folder name="content[]" defaultOpen>
          <Tree.File name="output_text" />
        </Tree.Folder>
      </Tree.Folder>

      <Tree.File name="reasoning" />

      <Tree.File name="function_call" />

      <Tree.File name="function_call_output" />

      <Tree.File name="image-generation item" />
    </Tree.Folder>
  </Tree.Folder>
</Tree>

## Instructions vs Input Items

Use `instructions` for high-level developer guidance and `input` for the actual request payload.

```json theme={null}
{
  "model": "gpt-4.1-mini",
  "instructions": "Respond in two concise bullet points.",
  "input": "Explain the difference between caching and buffering."
}
```

You can also send structured input items instead of a plain string:

```json theme={null}
{
  "model": "gpt-4.1-mini",
  "input": [
    {
      "type": "message",
      "role": "developer",
      "content": "Answer like an SRE writing internal notes."
    },
    {
      "type": "message",
      "role": "user",
      "content": "Explain retry storms."
    }
  ]
}
```

Use a plain string for simple one-shot prompts.

Use structured `message` items when you need multiple turns, multimodal content, or fine-grained control over roles.

## Important Mental Model

Do not assume the final answer always lives at `output[0].content[0].text`.

The `output` array may also contain:

* reasoning items
* function calls
* function call outputs
* image-generation items

If you use official OpenAI SDKs, `output_text` is the simplest convenience accessor when you only care about concatenated text output.

## Common mistakes

* assuming `output[0]` is always the final assistant answer
* using `input` string format when you actually need multiple messages or multimodal parts
* mixing request instructions into user content when `instructions` would be clearer

## Related Docs

* [Responses API](/api/responses)
* [Structured Outputs](/api/responses/structured-outputs)
* [Tool Calling](/api/responses/tool-calling)
