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

# Responses API

> Guard OpenAI Responses API calls, tool loops, and streamed output.

Use this page when your agent is built on OpenAI's Responses API. The wrappers preserve the native OpenAI method names and add Averta decisions around supported calls.

## Guarded Methods

| Method                                           | JavaScript | Python                     |
| ------------------------------------------------ | ---------- | -------------------------- |
| `client.responses.create(...)`                   | Supported  | Supported                  |
| `client.responses.create({ stream: true, ... })` | Supported  | Supported as `stream=True` |
| `client.responses.stream(...)`                   | Supported  | Supported                  |

## Non-streaming Request

<CodeGroup>
  ```typescript TypeScript theme={null}
  const response = await client.responses.create({
    model: process.env.OPENAI_MODEL ?? "gpt-5.4-mini",
    input: [
      {
        role: "developer",
        content: [{ type: "input_text", text: "Be concise." }],
      },
      {
        role: "user",
        content: [{ type: "input_text", text: "Summarize this runbook." }],
      },
    ],
    tools,
  });
  ```

  ```python Python theme={null}
  response = client.responses.create(
      model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),
      input=[
          {
              "role": "developer",
              "content": [{"type": "input_text", "text": "Be concise."}],
          },
          {
              "role": "user",
              "content": [{"type": "input_text", "text": "Summarize this runbook."}],
          },
      ],
      tools=tools,
  )
  ```
</CodeGroup>

Before calling OpenAI, Averta can:

* normalize request input
* extract supported image Data URLs
* normalize tools
* return `block` before the provider call
* return `restrict_tools` and remove blocked tools before forwarding

## Tool Loop Continuation

When the response contains function calls, execute the tools in your app and send the results through the same wrapped client.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const functionCall = response.output.find(
    (item) => item.type === "function_call"
  );

  if (functionCall) {
    const continuedResponse = await client.responses.create({
      model: process.env.OPENAI_MODEL ?? "gpt-5.4-mini",
      input: [
        ...response.output,
        {
          type: "function_call_output",
          call_id: functionCall.call_id,
          output: JSON.stringify({
            matches: ["Password reset links expire after 24 hours."],
          }),
        },
      ],
      tools,
    });

    console.log(continuedResponse.output_text);
  }
  ```

  ```python Python theme={null}
  function_call = next(
      (item for item in response.output if item.type == "function_call"),
      None,
  )

  if function_call:
      continued_response = client.responses.create(
          model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),
          input=[
              *response.output,
              {
                  "type": "function_call_output",
                  "call_id": function_call.call_id,
                  "output": '{"matches":["Password reset links expire after 24 hours."]}',
              },
          ],
          tools=tools,
      )

      print(continued_response.output_text)
  ```
</CodeGroup>

On continuation calls, Averta evaluates new `function_call_output` items before OpenAI sees them.

## Output Checks

If the response is final text and does not contain tool calls, Averta evaluates the output before returning it to your app.

For non-streaming output:

* `allow` returns the original result
* `block` throws `AvertaSdkError`
* `rewrite` asks OpenAI for a rewritten result and checks that rewritten output once more

## Streaming

Responses streaming is guarded in both OpenAI wrappers:

<CodeGroup>
  ```typescript TypeScript theme={null}
  const stream = await client.responses.create({
    model: process.env.OPENAI_MODEL ?? "gpt-5.4-mini",
    input: "Summarize password reset link expiration guidance.",
    stream: true,
  });
  ```

  ```python Python theme={null}
  stream = client.responses.create(
      model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),
      input="Summarize password reset link expiration guidance.",
      stream=True,
  )
  ```
</CodeGroup>

<CodeGroup>
  ```typescript TypeScript theme={null}
  const stream = client.responses.stream({
    model: process.env.OPENAI_MODEL ?? "gpt-5.4-mini",
    input: "Summarize password reset link expiration guidance.",
  });
  ```

  ```python Python theme={null}
  with client.responses.stream(
      model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),
      input="Summarize password reset link expiration guidance.",
  ) as stream:
      for event in stream:
          ...
  ```
</CodeGroup>

For streaming calls, request and tool-result checks run before the stream opens. Streaming output is checked as it is produced.

## Current Limits

* Responses streaming supports one output text stream per response.
* Streaming output rewrite is not supported yet. If policy requires rewrite, the wrapper fails closed.
* Rich media request preflight supports Data URL images only.
* Remote image URLs, OpenAI file IDs, file content parts, and audio parts are rejected before preflight.

## Debugging

| Symptom                     | Check                                                                             |
| --------------------------- | --------------------------------------------------------------------------------- |
| No request decision         | Confirm the OpenAI client is wrapped before `responses.create(...)` is called.    |
| No tool-result decision     | Confirm the continuation sends `function_call_output` through the wrapped client. |
| Missing tool after request  | Check request decision `blockedTools` and dashboard tool exposure policy.         |
| Stream fails on unsafe text | Streaming rewrite is unsupported; use non-streaming calls for rewrite behavior.   |

## Related Pages

<CardGroup cols={2}>
  <Card title="Tools" icon="toolbox" href="/openai/tools">
    Learn how tool exposure filtering works.
  </Card>

  <Card title="Streaming" icon="waves" href="/openai/streaming">
    See streaming-specific limits.
  </Card>

  <Card title="Tool results" icon="file-shield" href="/openai/tool-results">
    Screen returned tool content.
  </Card>

  <Card title="Output checks" icon="file-check" href="/openai/output-checks">
    Understand output blocks and rewrites.
  </Card>
</CardGroup>
