This integration demonstrates how to use Parallel's Web Search API as a grounding source for Gemini models on Google Cloud Vertex AI. Grounding with Parallel enables Gemini to access real-time web information to provide accurate, up-to-date responses.
Grounding with Parallel on Vertex AI connects Gemini models to Parallel's LLM-optimized web search index. This ensures responses are:
- Current: Access to live information from billions of web pages
- Accurate: Responses grounded in verifiable sources
- Cited: Sources are returned with each response for verification
- Information Enrichment: Complete or enrich entity data with current web information
- Multi-hop Agents: Deep web searches for complex questions
- Research Assistants: Employee-facing tools for reports using latest web data
- Consumer Applications: Retail and travel apps with informed purchase decisions
- Automated Agents: News analysis, KYC checks, and other automated tasks
- Vertical Agents: Sales, coding, and finance agents with current context
┌─────────────────────────────────────────────────────────────┐
│ Your Application │
│ client.generate("What is the latest news about AI?") │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Vertex AI Gemini API │
│ - Receives prompt with Parallel grounding config │
│ - Model determines search queries needed │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Parallel Web Search API │
│ - Executes semantic web searches │
│ - Returns LLM-optimized content and citations │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Grounded Response │
│ - Generated text with real-time information │
│ - Source citations for verification │
│ - Search queries executed │
└─────────────────────────────────────────────────────────────┘
- Google Cloud Project with billing enabled
- Vertex AI API enabled in your project
- Parallel auth configured via one of:
- Google Cloud Marketplace (recommended): an active Parallel Web Search subscription on your GCP project — no API key needed, or
- Bring Your Own Key (BYOK): a Parallel API key from platform.parallel.ai
- Python 3.10+ and uv package manager
- Google Cloud authentication configured
See the Parallel + Vertex AI integration docs for a comparison of the two modes.
cd gemini_ai_demo
# Install dependencies using uv
uv sync
# Or install with pip
pip install -e .# Authenticate with Google Cloud
gcloud auth application-default login
# Set your project
export GOOGLE_CLOUD_PROJECT="your-gcp-project-id"
# Optional: only if using Bring Your Own Key (BYOK) instead of a
# Google Cloud Marketplace subscription.
# Get a key from https://platform.parallel.ai
# export PARALLEL_API_KEY="your-parallel-api-key"# Check that everything is configured correctly
python demo.py --checkThe fastest way to get started is with our minimal example:
python quickstart.pyOr in Python:
from gemini_parallel import GroundedGeminiClient
client = GroundedGeminiClient()
response = client.generate("Who won the most recent Super Bowl?")
print(response.text)# Run with sample questions (shows grounded vs ungrounded comparison)
python demo.py
# Run more sample questions
python demo.py --num 5
# Interactive mode - ask your own questions
python demo.py --interactive
# Use a different model
python demo.py --model gemini-2.5-flash
# Show full responses (not truncated)
python demo.py --fullThe demo compares responses with and without Parallel grounding for questions about recent events, showing how grounding provides access to real-time web information.
For a step-by-step learning experience, open the Jupyter notebook:
# Install notebook dependencies
pip install -e ".[notebook]"
# Or with uv
uv sync --extra notebook
# Launch the tutorial
jupyter notebook tutorial.ipynbFor a full production pattern built on this client — verifiable company and people
enrichment with typed outputs and mechanically verified citations — see
gemini_search_enrichment.ipynb:
jupyter notebook gemini_search_enrichment.ipynbWhen your GCP project has a Parallel Web Search Marketplace subscription, no API key is needed.
from gemini_parallel import GroundedGeminiClient
# Initialize the client (Marketplace mode)
client = GroundedGeminiClient(
project_id="your-project-id",
)
# Generate a grounded response
response = client.generate(
prompt="Who won the most recent FIFA World Cup?",
model_id="gemini-2.0-flash",
)
print(response.text)
print(f"Sources: {[s.uri for s in response.sources]}")Pass parallel_api_key (or set PARALLEL_API_KEY) to authenticate with a Parallel key instead.
from gemini_parallel import GroundedGeminiClient
client = GroundedGeminiClient(
project_id="your-project-id",
parallel_api_key="your-parallel-api-key",
)
response = client.generate("Who won the most recent FIFA World Cup?")
print(response.text)Note: If both a Marketplace subscription and an API key are present, the API key takes precedence.
from gemini_parallel import GroundedGeminiClient, GroundingConfig
# Configure grounding options. Leave api_key unset for Marketplace mode,
# or pass a key for BYOK.
config = GroundingConfig(
# api_key="your-parallel-api-key", # Uncomment for BYOK
max_results=5, # Max search results (1-20)
include_domains=["www.example.com"], # Only these domains
exclude_domains=[], # Exclude these domains
)
client = GroundedGeminiClient(
project_id="your-project-id",
grounding_config=config,
)
response = client.generate(
prompt="What is the latest news about AI regulation?",
temperature=0.2,
system_instruction="Provide a concise summary with key dates.",
)Before running your code, you can validate that all credentials are configured correctly:
from gemini_parallel import validate_setup
status = validate_setup()
print(status)
if not status.is_valid:
# status shows exactly what's missing and how to fix it
exit(1)from gemini_parallel import generate_grounded_response
# Marketplace
response = generate_grounded_response(
prompt="What are the latest breakthroughs in quantum computing?",
project_id="your-project",
)
# BYOK
response = generate_grounded_response(
prompt="What are the latest breakthroughs in quantum computing?",
project_id="your-project",
parallel_api_key="your-parallel-api-key",
)| Variable | Description | Required |
|---|---|---|
GOOGLE_CLOUD_PROJECT |
Google Cloud project ID | Yes |
PARALLEL_API_KEY |
Parallel API key. Only required for Bring Your Own Key (BYOK) mode; leave unset when using a Google Cloud Marketplace subscription | No |
GOOGLE_CLOUD_LOCATION |
GCP region (default: us-central1) | No |
GOOGLE_APPLICATION_CREDENTIALS |
Path to service account JSON | No |
| Parameter | Description | Default | Range |
|---|---|---|---|
api_key |
Parallel API key for BYOK mode. Leave unset for Marketplace. | None | - |
max_results |
Max search results | 10 | 1-20 |
max_chars_per_result |
Max chars per result excerpt | 30,000 | 1,000-100,000 |
max_chars_total |
Max total chars from all excerpts | 100,000 | 1,000-1,000,000 |
include_domains |
Only search these domains | None | Up to 10 |
exclude_domains |
Exclude these domains | None | Up to 10 |
See the official documentation for the latest list.
Gemini 3 (Preview)
gemini-3.0-flashgemini-3.0-progemini-3.0-pro-image
Gemini 2.5
gemini-2.5-progemini-2.5-flashgemini-2.5-flash-lite
Gemini 2.0
gemini-2.0-flash
The default model is gemini-2.5-flash.
The GroundedResponse object contains:
@dataclass
class GroundedResponse:
text: str # Generated response text
sources: list[GroundingSource] # List of source URLs and titles
web_search_queries: list[str] # Queries executed by the model
raw_response: dict # Full API response for debugging
grounding_supports: list[dict] # Detailed grounding informationgemini_ai_demo/
├── src/gemini_parallel/ # Source code
│ ├── __init__.py # Package exports
│ └── client.py # Main client implementation
├── tests/ # Test suite
│ ├── conftest.py # Test fixtures
│ └── test_client.py # Unit tests
├── quickstart.py # Minimal example (~15 lines)
├── demo.py # Full demo script with comparisons
├── tutorial.ipynb # Interactive Jupyter tutorial
├── gemini_search_enrichment.ipynb # Cookbook: verifiable company & people enrichment
├── pyproject.toml # Project configuration
├── README.md # This file
├── .env.example # Environment variable template
└── .gitignore # Git ignore patterns
# Run all tests
uv run pytest tests/ -v
# Run with coverage
uv run pytest tests/ --cov=src/gemini_parallel
# Run specific test
uv run pytest tests/test_client.py::TestGroundedGeminiClient -vUsing Grounding with Parallel incurs the following charges:
| Component | Description |
|---|---|
| Gemini tokens | Prompt, thinking, and output tokens (Vertex AI pricing) |
| Grounding | Vertex AI grounding charges |
| Parallel Search | Per-query pricing (Parallel pricing) |
Note: Input tokens provided by Parallel are not charged extra.
The default quota is 200 prompts per minute. To increase rate limits, contact your Google account team (Marketplace) or support@parallel.ai (BYOK) with your use case.
-
Authentication Error
gcloud auth application-default login
-
API Not Enabled
gcloud services enable aiplatform.googleapis.com -
Marketplace subscription missing
- If you're not using BYOK, make sure the GCP project you pass to
GroundedGeminiClienthas an active Parallel Web Search Marketplace subscription. - Otherwise set
PARALLEL_API_KEY(or passparallel_api_key) to use BYOK.
- If you're not using BYOK, make sure the GCP project you pass to
-
Invalid API Key (BYOK only)
- Verify your Parallel API key at platform.parallel.ai
- Ensure the key has web search permissions
-
Rate Limiting
- Default quota is 200 requests/minute
- Contact support for higher limits
# Access raw API response for debugging
response = client.generate("...")
print(response.raw_response)
# Check grounding supports for citation details
print(response.grounding_supports)- Vertex AI Grounding Documentation
- Grounding with Parallel on Vertex AI
- Parallel Web Search API
- Parallel Pricing
- Google Gen AI SDK
See repository root for license information.
Your use of Parallel requires Google Cloud to send certain Customer Data to Parallel for processing. Your use of the Parallel service is governed by: