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

> ## Agent Instructions
> Phaseo Gateway base URL: https://api.phaseo.app/v1. Send `Authorization: Bearer $PHASEO_API_KEY` with every request.
> Model IDs look like `provider/model`, for example `openai/gpt-6-astra`. Do not guess IDs: list them with `GET /v1/models` or check https://phaseo.app/models. `phaseo/free` routes to an available free model and needs no wallet balance.
> For new text integrations prefer `POST /v1/responses`. `POST /v1/chat/completions` (OpenAI format) and `POST /v1/messages` (Anthropic format) suit existing code.
> The full API contract is https://phaseo.app/docs/openapi/v1/openapi.yaml. Official SDKs: `@phaseo/sdk` (TypeScript) and `phaseo` (Python), plus Go, C#, PHP, Ruby and Rust.
> Search these docs over MCP at https://phaseo.app/docs/mcp, and install Phaseo skills with `npx skills add https://phaseo.app/docs`. If a page is wrong or out of date, report it with the MCP `submit_feedback` tool.
> Manage Phaseo accounts with the `phaseo` CLI (`npm install -g @phaseo/cli`, then `phaseo login` or `phaseo login --device-code`), the `/v1` Management API or the MCP server at `https://mcp.phaseo.app/mcp?access=manage`. Do not send users to the dashboard for account tasks. A person is still needed for sign-up, approving a sign-in, paying the first top-up on the checkout link that `phaseo credits add` returns when no card is saved, confirming each saved-card top-up from the emailed link, and account security (password, MFA, passkeys). Create API keys with `phaseo keys create --name <name> --json`; never guess one. Credit top-ups need `phaseo login --scopes billing:write` first. Task map: https://phaseo.app/docs/v1/developers/manage-from-an-agent.md.

# Set plugin defaults for structured JSON workflows

> Use workspace, preset, and request-level plugin policy to keep response healing consistent.

Use this recipe when structured-output callers need one stable plugin policy instead of ad hoc request-by-request settings.

## 1. Understand precedence

Gateway plugin policy resolves in this order:

1. workspace defaults
2. preset defaults
3. request-level plugins

Lower-precedence layers can override higher layers unless the workspace default is explicitly locked.

## 2. Set the workspace default

Use the routing settings surface when one workspace should enable response healing by default for structured JSON callers.

That is the right place for:

* broad operational defaults
* shared API key behavior
* preventing per-service drift

## 3. Lock it when the policy is non-negotiable

If one workspace must always keep response healing enabled, lock that default.

With a locked workspace default:

* presets cannot disable it
* request payloads cannot disable it
* logs still show whether the plugin applied, skipped, or failed

## 4. Use presets for workflow-specific defaults

Presets are the right layer when one family of requests should carry both:

* structured output settings
* response-healing plugin defaults

That layer can also choose the response-healing mode:

* `safe` for bounded syntactic cleanup
* `strict` for unwrap-only behavior

That keeps the request body smaller and makes routing plus output behavior easier to reuse across services.

## 5. Override at request level only when the workspace allows it

If the workspace default is not locked, one request can still override plugin config directly:

```bash cURL theme={null}
curl https://api.phaseo.app/v1/responses \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "phaseo/free",
    "input": "Return valid JSON",
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "answer",
        "schema": {
          "type": "object",
          "properties": {
            "summary": { "type": "string" }
          },
          "required": ["summary"],
          "additionalProperties": false
        }
      }
    },
    "plugins": [
      { "id": "response-healing", "enabled": true }
    ]
  }'
```

```typescript TypeScript SDK theme={null}
import Phaseo from "@phaseo/sdk";

const client = new Phaseo({ apiKey: process.env.PHASEO_API_KEY! });

const response = await client.generateResponse({
  model: "phaseo/free",
  input: "Return valid JSON",
  response_format: {
    type: "json_schema",
    json_schema: {
      name: "answer",
      schema: {
        type: "object",
        properties: {
          summary: { type: "string" },
        },
        required: ["summary"],
        additionalProperties: false,
      },
    },
  },
  plugins: [{ id: "response-healing", enabled: true }],
});

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

```python Python SDK theme={null}
from phaseo import Phaseo

client = Phaseo(api_key="YOUR_API_KEY")

response = client.generate_response(
    {
        "model": "phaseo/free",
        "input": "Return valid JSON",
        "response_format": {
            "type": "json_schema",
            "json_schema": {
                "name": "answer",
                "schema": {
                    "type": "object",
                    "properties": {
                        "summary": {"type": "string"}
                    },
                    "required": ["summary"],
                    "additionalProperties": False,
                },
            },
        },
        "plugins": [
            {"id": "response-healing", "enabled": True}
        ],
    }
)

print(response.get("output_text"))
```

## 6. Verify the behavior in logs

After one request, inspect the request detail view and confirm:

* `plugin_executions` includes `response-healing`
* the status is one of:
  * `applied`
  * `skipped`
  * `failed`
* the effective plugin mode is visible
* validation errors are visible when schema enforcement rejects a candidate healed payload

## 7. What to do when behavior differs across services

If two services behave differently, compare:

* workspace routing settings
* preset plugin defaults
* request-level `plugins`
* whether the workspace default is locked

Do not debug that as a model-quality issue until those policy layers match.

## Related

* [Recover malformed structured JSON](https://phaseo.app/docs/v1/cookbook/response-healing-for-structured-json.md)
* [Use response caching with presets](https://phaseo.app/docs/v1/cookbook/response-caching-with-presets.md)
* [TypeScript Agent SDK](https://phaseo.app/docs/v1/sdk-reference/typescript/agent-sdk.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.