1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* OpenAI API
*
* The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
*
* The version of the OpenAPI document: 2.3.0
*
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
/// BetaWebSearchTool : Search the Internet for sources related to the prompt. Learn more about the [web search tool](https://developers.openai.com/api/docs/guides/tools-web-search).
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct BetaWebSearchTool {
/// The type of the web search tool. One of `web_search` or `web_search_2025_08_26`.
#[serde(rename = "type")]
pub r#type: Type,
/// Allow live internet access for web search. Defaults to true when omitted. When false, the web search tool runs in offline/cache-only mode and will not fetch new external content.
#[serde(
rename = "external_web_access",
skip_serializing_if = "Option::is_none"
)]
pub external_web_access: Option<bool>,
#[serde(
rename = "filters",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub filters: Option<Option<Box<models::Object028>>>,
#[serde(
rename = "user_location",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub user_location: Option<Option<Box<models::BetaWebSearchApproximateLocation>>>,
/// High level guidance for the amount of context window space to use for the search. One of `low`, `medium`, or `high`. `medium` is the default.
#[serde(
rename = "search_context_size",
skip_serializing_if = "Option::is_none"
)]
pub search_context_size: Option<SearchContextSize>,
}
impl BetaWebSearchTool {
/// Search the Internet for sources related to the prompt. Learn more about the [web search tool](https://developers.openai.com/api/docs/guides/tools-web-search).
pub fn new(r#type: Type) -> BetaWebSearchTool {
BetaWebSearchTool {
r#type,
external_web_access: None,
filters: None,
user_location: None,
search_context_size: None,
}
}
}
/// The type of the web search tool. One of `web_search` or `web_search_2025_08_26`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "web_search")]
WebSearch,
#[serde(rename = "web_search_2025_08_26")]
WebSearch20250826,
}
impl Default for Type {
fn default() -> Type {
Self::WebSearch
}
}
/// High level guidance for the amount of context window space to use for the search. One of `low`, `medium`, or `high`. `medium` is the default.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum SearchContextSize {
#[serde(rename = "low")]
Low,
#[serde(rename = "medium")]
Medium,
#[serde(rename = "high")]
High,
}
impl Default for SearchContextSize {
fn default() -> SearchContextSize {
Self::Low
}
}
impl std::fmt::Display for BetaWebSearchTool {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string(self) {
Ok(s) => write!(f, "{}", s),
Err(_) => Err(std::fmt::Error),
}
}
}