> ## 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.

# API Responses

> Genera texto y llamadas a herramientas mediante la API Responses de Phaseo desde Rust.

Usa `responses(...)` para generar texto y llamar a herramientas en nuevos desarrollos.

```rust theme={null}
use phaseo::Phaseo;
use serde_json::json;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Phaseo::from_env()?;
    let response = client.responses(&json!({
        "model": "openai/gpt-6-astra",
        "input": "Give three concise benefits of model routing.",
        "max_output_tokens": 200
    }))?;

    println!("status: {}", response.status);
    println!("request ID: {:?}", response.request_id);
    println!("{}", serde_json::to_string_pretty(&response.body)?);
    Ok(())
}
```

## Leer el texto de salida

La salida de la API Responses es una matriz. Para obtener un resultado de texto sencillo:

```rust theme={null}
use serde_json::Value;

let text = response.body
    .get("output")
    .and_then(Value::as_array)
    .into_iter()
    .flatten()
    .filter(|item| item.get("type").and_then(Value::as_str) == Some("message"))
    .flat_map(|item| {
        item.get("content")
            .and_then(Value::as_array)
            .into_iter()
            .flatten()
    })
    .find_map(|part| {
        (part.get("type").and_then(Value::as_str) == Some("output_text"))
            .then(|| part.get("text").and_then(Value::as_str))
            .flatten()
    });
```

Conserva todo el `body` cuando la solicitud pueda devolver varios mensajes, elementos de razonamiento, llamadas a herramientas o metadatos del proveedor.

## Enviar herramientas de función

```rust theme={null}
let response = client.responses(&json!({
    "model": "openai/gpt-6-astra",
    "input": "Check the weather in London.",
    "tools": [{
        "type": "function",
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
            "type": "object",
            "properties": {
                "city": { "type": "string" }
            },
            "required": ["city"]
        }
    }]
}))?;
```

Para crear un ciclo local de herramientas con aprobaciones y estado reanudable, usa el [SDK de agentes para Rust](./agent-sdk-overview.mdx).

## Relacionado

* [Referencia de la API Responses](../../api-reference/endpoint/responses.mdx)
* [Crear agentes con el SDK de agentes para Rust](./agent-sdk.mdx)


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