Skip to main content
Gemini on Vertex AI can call a search API you provide and use the results as grounding sources. This guide deploys a short adapter on Cloud Run that turns Gemini’s request into a Firecrawl search and returns the results in the shape Gemini expects.
Google documents this feature as Grounding with your search API. The adapter in this guide runs in your own Google Cloud project, and your Firecrawl account is billed for the searches it makes.

How it works

  1. Your request to Gemini includes a retrieval tool of type externalApi that points at your adapter.
  2. When Gemini needs information, it sends POST {"query": "..."} to the adapter with your key appended as ?key=.
  3. The adapter calls Firecrawl /v2/search and answers with a JSON array of objects that each have a snippet and a uri. An empty array means no results.
  4. Gemini uses the snippets as grounding sources and lists them in groundingMetadata on the response.

Prerequisites

  • A Firecrawl API key
  • A Google Cloud project with billing, Vertex AI and Cloud Run enabled, and the gcloud CLI signed in
  • A Gemini model that supports grounding with your search API. Google lists them on the page linked above, and gemini-2.5-flash is one of them.

Build the adapter

Create a folder with these three files.
The adapter reads the key from ?key=. It sends that key to Firecrawl as a Bearer token, so the apiKeyString you give Gemini is your Firecrawl API key. A missing or rejected key returns 401. The Dockerfile starts gunicorn without an access log, because an access log would record the ?key= value. The adapter never writes the query or the key.

Deploy to Cloud Run

The command prints a service URL. Your endpoint is that URL followed by /v0/search. Gemini cannot attach a Google identity token to this call, so the service allows unauthenticated requests and the ?key= check is its access control.

Keep the Firecrawl key out of URLs

Cloud Run keeps a request log for each service, and it records request URLs. To keep your Firecrawl key out of it, run the adapter in gateway mode. You choose a shared secret for Gemini to send, and the adapter uses the Firecrawl key from Secret Manager.
Give the service’s runtime service account the roles/secretmanager.secretAccessor role on both secrets. In this mode, apiKeyString is the gateway secret, which you can read with gcloud secrets versions access latest --secret grounding-gateway-key.

Check the endpoint

You get back an array of objects with snippet and uri. Without ?key= the service answers 401.

Ground a Gemini request

Replace YOUR_SERVICE_URL with your service host and YOUR_KEY with your Firecrawl API key, or with the gateway secret if you deployed in gateway mode. For a regional location other than global, use LOCATION-aiplatform.googleapis.com as the host, as in Google’s reference. In the response, the sources Gemini used appear under candidates[0].groundingMetadata.groundingChunks. In the REST response, each chunk’s retrievedContext carries the uri and snippet your adapter returned.

Options

Set these as environment variables on the Cloud Run service, for example with gcloud run services update firecrawl-grounding --update-env-vars RESULT_LIMIT=5.

Choosing a snippet

Gemini grounds on the snippet text, so its content matters more than the link. The default uses the description Firecrawl search returns. Search returns query-relevant highlights in that field by default, and falls back to the page’s plain description when it cannot make one, so each snippet is a passage chosen for the query. The markdown mode takes the first characters of each result’s main content, which on some sites is a banner or menu ahead of the article, so it is usually the weaker choice. It also makes each Firecrawl response much larger. Use it when the results you care about have no useful description.

Limits and behavior

  • Google lets one generation request use up to 10 grounding sources, and you can combine this tool with others such as Google Search.
  • Google’s page does not state a maximum response size or a timeout for your endpoint. Keep the adapter fast and the snippets short. With the defaults, a response holds at most 10 snippets of 1,200 characters.
  • Firecrawl search accepts queries of up to 500 characters. The adapter cuts longer queries to that length.
  • Each query is one Firecrawl search request, so your rate limits and billing apply to every search Gemini makes.
  • Gemini calls the adapter once for each search it decides to run, and a single request can trigger more than one.