---
title: "Google Programmable Search Engine (PSE)"
url: "/docs/search/google_pse"
canonical_url: "https://docs.litellm.ai/docs/search/google_pse"
type: "docs"
last_updated: "2026-10-09"
summary: "Get API Key: Google Cloud Console"
related:
  - "/docs/search/parallel_ai"
  - "/docs/search/dataforseo"
---
# Google Programmable Search Engine (PSE)

> Index of all LiteLLM docs: https://docs.litellm.ai/llms.txt


**Get API Key:** [Google Cloud Console](https://console.cloud.google.com/apis/credentials)  
**Create Search Engine:** [Programmable Search Engine](https://programmablesearchengine.google.com/)

## Setup

1. Go to [Google Developers Programmable Search Engine](https://programmablesearchengine.google.com/) and log in or create an account
2. Click the **Add** button in the control panel
3. Enter a search engine name and configure properties:
   - Choose which sites to search (entire web or specific sites)
   - Set language and other preferences
   - Verify you're not a robot
4. Click **Create** button
5. Once created, you'll see:
   - **Search engine ID (cx)** - Copy this for `GOOGLE_PSE_ENGINE_ID`
   - Instructions to get your API key
6. Generate API key:
   - Go to [Google Cloud Console - Credentials](https://console.cloud.google.com/apis/credentials)
   - Create a new API key or use existing one
   - Enable **Custom Search API** for your project
   - Copy the API key for `GOOGLE_PSE_API_KEY`

## LiteLLM Python SDK

```python showLineNumbers title="Google PSE Search"
import os
from litellm import search

os.environ["GOOGLE_PSE_API_KEY"] = "AIza..."
os.environ["GOOGLE_PSE_ENGINE_ID"] = "your-search-engine-id"

response = search(
    query="latest AI developments",
    search_provider="google_pse",
    max_results=10
)
```

## LiteLLM AI Gateway

### 1. Setup config.yaml

```yaml showLineNumbers title="config.yaml"
model_list:
  - model_name: gpt-5.6-terra
    litellm_params:
      model: gpt-5.6-terra
      api_key: os.environ/OPENAI_API_KEY

search_tools:
  - search_tool_name: google-search
    litellm_params:
      search_provider: google_pse
      api_key: os.environ/GOOGLE_PSE_API_KEY
```

The search engine id (`cx`) is read only from the `GOOGLE_PSE_ENGINE_ID` environment variable of the proxy process, so export it before starting the proxy. A `search_engine_id` key in the search tool's `litellm_params` is not used as `cx`

```bash
export GOOGLE_PSE_API_KEY="AIza..."
export GOOGLE_PSE_ENGINE_ID="your-search-engine-id"
```

### 2. Start the proxy

```bash
litellm --config /path/to/config.yaml

# RUNNING on http://0.0.0.0:4000
```

### 3. Test the search endpoint

```bash showLineNumbers title="Test Request"
curl http://0.0.0.0:4000/v1/search/google-search \
  -H "Authorization: Bearer $LITELLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "latest AI developments",
    "max_results": 10
  }'
```

## Provider-specific Parameters

```python showLineNumbers title="Google PSE Search with Provider-specific Parameters"
import os
from litellm import search

os.environ["GOOGLE_PSE_API_KEY"] = "AIza..."
os.environ["GOOGLE_PSE_ENGINE_ID"] = "your-search-engine-id"

response = search(
    query="latest AI research papers",
    search_provider="google_pse",
    max_results=10,
    search_domain_filter=["arxiv.org"],
    # Google PSE-specific parameters (use actual Google PSE API parameter names)
    dateRestrict="m6",               # 'm6' = last 6 months, 'd7' = last 7 days
    lr="lang_en",                    # Language restriction (e.g., 'lang_en', 'lang_es')
    safe="active",                   # Search safety level ('active' or 'off')
    exactTerms="machine learning",   # Phrase that all documents must contain
    fileType="pdf"                   # File type to restrict results to
)
```

## Related pages

- [Parallel AI Search](https://docs.litellm.ai/docs/search/parallel_ai.md)
- [DataForSEO Search](https://docs.litellm.ai/docs/search/dataforseo.md)
