"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations from .preview_websearchuserlocation import ( PreviewWebSearchUserLocation, PreviewWebSearchUserLocationTypedDict, ) from .searchcontextsizeenum import SearchContextSizeEnum from .websearchdomainfilter import WebSearchDomainFilter, WebSearchDomainFilterTypedDict from .websearchengineenum import WebSearchEngineEnum from openrouter.types import ( BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL, ) from pydantic import model_serializer from typing import Literal, Optional from typing_extensions import NotRequired, TypedDict Preview20250311WebSearchServerToolType = Literal["web_search_preview_2025_03_11",] class Preview20250311WebSearchServerToolTypedDict(TypedDict): r"""Web search preview tool configuration (2025-03-11 version)""" type: Preview20250311WebSearchServerToolType engine: NotRequired[WebSearchEngineEnum] r"""Which search engine to use. \"auto\" (default) uses native if the provider supports it, otherwise Exa. \"native\" forces the provider's built-in search. \"exa\" forces the Exa search API. \"firecrawl\" uses Firecrawl (requires BYOK). \"parallel\" uses the Parallel search API. \"perplexity\" uses the Perplexity Search API (raw ranked results).""" filters: NotRequired[Nullable[WebSearchDomainFilterTypedDict]] max_results: NotRequired[int] r"""Maximum number of search results to return per search call. Defaults to 5. Applies to Exa, Firecrawl, Parallel, and Perplexity engines; ignored with native provider search. Perplexity supports a maximum of 20; values above 20 are clamped.""" search_context_size: NotRequired[SearchContextSizeEnum] r"""Size of the search context for web search tools""" user_location: NotRequired[Nullable[PreviewWebSearchUserLocationTypedDict]] class Preview20250311WebSearchServerTool(BaseModel): r"""Web search preview tool configuration (2025-03-11 version)""" type: Preview20250311WebSearchServerToolType engine: Optional[WebSearchEngineEnum] = None r"""Which search engine to use. \"auto\" (default) uses native if the provider supports it, otherwise Exa. \"native\" forces the provider's built-in search. \"exa\" forces the Exa search API. \"firecrawl\" uses Firecrawl (requires BYOK). \"parallel\" uses the Parallel search API. \"perplexity\" uses the Perplexity Search API (raw ranked results).""" filters: OptionalNullable[WebSearchDomainFilter] = UNSET max_results: Optional[int] = None r"""Maximum number of search results to return per search call. Defaults to 5. Applies to Exa, Firecrawl, Parallel, and Perplexity engines; ignored with native provider search. Perplexity supports a maximum of 20; values above 20 are clamped.""" search_context_size: Optional[SearchContextSizeEnum] = None r"""Size of the search context for web search tools""" user_location: OptionalNullable[PreviewWebSearchUserLocation] = UNSET @model_serializer(mode="wrap") def serialize_model(self, handler): optional_fields = set( ["engine", "filters", "max_results", "search_context_size", "user_location"] ) nullable_fields = set(["filters", "user_location"]) serialized = handler(self) m = {} for n, f in type(self).model_fields.items(): k = f.alias or n val = serialized.get(k, serialized.get(n)) is_nullable_and_explicitly_set = ( k in nullable_fields and (self.__pydantic_fields_set__.intersection({n})) # pylint: disable=no-member ) if val != UNSET_SENTINEL: if ( val is not None or k not in optional_fields or is_nullable_and_explicitly_set ): m[k] = val return m