Skip to content

Conversation

@WestXu
Copy link

@WestXu WestXu commented Nov 29, 2025

WebSearchActionSearch.query should be Option<String>

Description

When using the Responses API with web search tools, deserialization fails with missing field 'query' because WebSearchActionSearch.query is defined as String but the OpenAI API sometimes returns search actions without a query field.

Error

failed to deserialize api response: error:missing field `query` at line 30 column 4

API Response (truncated)

{
  "output": [
    {
      "id": "ws_...",
      "type": "web_search_call",
      "status": "completed",
      "action": {
        "type": "search"
      }
    }
  ]
}

Note: action has "type": "search" but no query field.

Expected Behavior

The response should deserialize successfully since this is valid API output.

Suggested Fix

In src/types/responses/response.rs, change:

pub struct WebSearchActionSearch {
    pub query: String,  // <-- should be Option<String>
    pub sources: Option<Vec<WebSearchActionSearchSource>>,
}

To:

pub struct WebSearchActionSearch {
    pub query: Option<String>,
    pub sources: Option<Vec<WebSearchActionSearchSource>>,
}

References

This behavior is confirmed by OpenAI community discussions:

Minimal Reproduction

use async_openai::{
    Client,
    config::OpenAIConfig,
    types::responses::{
        CreateResponseArgs, EasyInputMessage, InputItem, InputParam, Role, Tool,
    },
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = Client::<OpenAIConfig>::new();

    let request = CreateResponseArgs::default()
        .model("gpt-5-mini")
        .input(InputParam::Items(vec![
            InputItem::EasyMessage(EasyInputMessage {
                role: Role::User,
                content: "what is bitcoin price today".into(),
                ..Default::default()
            }),
        ]))
        .tools(vec![Tool::WebSearch(Default::default())])
        .build()?;

    let response = client.responses().create(request).await?;
    println!("{:?}", response);
    Ok(())
}
# Cargo.toml
[dependencies]
async-openai = "0.31"
tokio = { version = "1", features = ["full"] }
anyhow = "1"

Version

  • async-openai: 0.31.1
  • Model: gpt-5-mini (gpt-5 series only - gpt-4.1 series returns query correctly)
  • Tool: Tool::WebSearch(Default::default())

Notes

The query field appears to be optional only for gpt-5 series models. gpt-4.1 series models return the query field as expected. However, since the API can return responses without query, the field should still be Option<String> for compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant