Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langchain Perplexity Types

From Leeroopedia
Knowledge Sources
Domains LLM, Perplexity, Data Models
Last Updated 2026-02-11 00:00 GMT

Overview

Pydantic data models for Perplexity API configuration options including web search settings, user location, and media response overrides.

Description

This module defines Pydantic BaseModel classes used to configure Perplexity API requests in the langchain-perplexity partner package. It includes four models: UserLocation for geographic coordinates and location metadata, WebSearchOptions for controlling search context size, search type, and image relevance, MediaResponseOverrides for toggling video and image returns, and MediaResponse as a wrapper around the overrides.

Usage

Import these types when constructing Perplexity chat model requests that require fine-grained control over web search behavior, user location context, or media response settings.

Code Reference

Source Location

Signature

class UserLocation(BaseModel):
    latitude: float | None = None
    longitude: float | None = None
    country: str | None = None
    region: str | None = None
    city: str | None = None

class WebSearchOptions(BaseModel):
    search_context_size: Literal["low", "medium", "high"] | None = None
    user_location: UserLocation | None = None
    search_type: Literal["fast", "pro", "auto"] | None = None
    image_search_relevance_enhanced: bool | None = None

class MediaResponseOverrides(BaseModel):
    return_videos: bool | None = None
    return_images: bool | None = None

class MediaResponse(BaseModel):
    overrides: MediaResponseOverrides | None = None

Import

from langchain_perplexity.types import (
    UserLocation,
    WebSearchOptions,
    MediaResponseOverrides,
    MediaResponse,
)

I/O Contract

UserLocation Fields

Name Type Required Description
latitude None No Geographic latitude coordinate.
longitude None No Geographic longitude coordinate.
country None No Country name or code.
region None No Region or state name.
city None No City name.

WebSearchOptions Fields

Name Type Required Description
search_context_size None No Controls the amount of search context retrieved.
user_location None No User location for geo-contextualized search results.
search_type None No Search mode: fast, pro, or auto-detect.
image_search_relevance_enhanced None No Whether to enhance image search relevance.

MediaResponseOverrides Fields

Name Type Required Description
return_videos None No Whether to include videos in the response.
return_images None No Whether to include images in the response.

MediaResponse Fields

Name Type Required Description
overrides None No Media response override settings.

Usage Examples

Basic Usage

from langchain_perplexity.types import WebSearchOptions, UserLocation

# Configure web search options with user location
location = UserLocation(
    latitude=37.7749,
    longitude=-122.4194,
    city="San Francisco",
    region="California",
    country="US",
)

search_options = WebSearchOptions(
    search_context_size="high",
    user_location=location,
    search_type="pro",
)

Media Response Configuration

from langchain_perplexity.types import MediaResponse, MediaResponseOverrides

media = MediaResponse(
    overrides=MediaResponseOverrides(
        return_images=True,
        return_videos=False,
    )
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment