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

# Responses API

> Rust から Phaseo Responses API を通じてテキスト生成とツール呼び出しを行います。

新しいテキスト生成やツール呼び出しには `responses(...)` を使用します。

```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(())
}
```

## 出力テキストを読む

Responses API の出力は配列です。シンプルなテキスト結果を取得するには：

```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()
    });
```

複数のメッセージ、推論項目、ツール呼び出し、プロバイダーのメタデータが返る可能性がある場合は、`body` 全体を保持してください。

## 関数ツールを送信する

```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"]
        }
    }]
}))?;
```

承認と再開可能な状態に対応したローカルツールループには、[Rust Agent SDK](./agent-sdk-overview.mdx) を使用します。

## 関連項目

* [Responses API リファレンス](../../api-reference/endpoint/responses.mdx)
* [Rust Agent SDK でエージェントを構築](./agent-sdk.mdx)


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