The Developer Knowledge API lets you ask questions about Google developer products and receive direct, natural-language answers. For each query, the API composes a response drawn from the Developer Knowledge corpus (referred to in the API reference as grounded generation) and includes citations to the relevant documentation pages.
Before you begin
Set up your environment for your preferred tool:
gcloud
Install and configure the gcloud CLI, and enable the Developer Knowledge API.
REST
Enable the API and generate a Developer Knowledge API key. Then, save your key to an environment variable:
export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"
Replace YOUR_API_KEY with your Developer Knowledge API key.
Answer a query
Use the
gcloud developer-knowledge answer-query command or the
answerQuery REST method
to ask a question.
The following example sends a query asking how to create a BigQuery dataset:
gcloud
gcloud developer-knowledge answer-query \ --query="How do I create a BigQuery dataset?"
REST
curl -X POST "https://developerknowledge.googleapis.com/v1:answerQuery?key=$DEVELOPERKNOWLEDGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "How do I create a BigQuery dataset?"}'
The response contains the text answer in the answer.answerText field,
along with citations and references in the
answer
object:
{
"answer": {
"answerText": "To create a BigQuery dataset, you can use the Google Cloud Console, the bq command-line tool, or the BigQuery client libraries.",
"citations": [
{
"startIndex": 0,
"endIndex": 123,
"sources": [
{
"referenceIndex": 0
}
]
}
],
"references": [
{
"documentReference": {
"documentChunk": {
"parent": "documents/docs.cloud.google.com/bigquery/docs/datasets",
"content": "This page explains how to create BigQuery datasets...",
"document": {
"name": "documents/docs.cloud.google.com/bigquery/docs/datasets",
"title": "Introduction to datasets",
"uri": "https://docs.cloud.google.com/bigquery/docs/datasets"
}
}
}
}
]
}
}
Filter documentation sources
To restrict the documentation sources used to generate the answer, pass a filter
expression using the --query-filter flag in the gcloud CLI or the
filter field in your REST request body. For details on supported filter fields
and operators, see Filter search results.
The following example restricts the documentation sources to
docs.cloud.google.com:
gcloud
gcloud developer-knowledge answer-query \ --query="How do I create a BigQuery dataset?" \ --query-filter='data_source = "docs.cloud.google.com"'
REST
curl -X POST "https://developerknowledge.googleapis.com/v1:answerQuery?key=$DEVELOPERKNOWLEDGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "How do I create a BigQuery dataset?",
"filter": "data_source = \"docs.cloud.google.com\""
}'
Choose between AnswerQuery and SearchDocumentChunks
When you're using the API or the Developer Knowledge MCP server, choose the method that best fits what you're looking for:
AnswerQuery(or theanswer_queryMCP tool): best for general "how-to" questions, comparing products, and step-by-step guides where you want a complete summary with links to the source docs.SearchDocumentChunks(or thesearch_documentsMCP tool): best for looking up exact CLI flags, code syntax, parameter names, or IAM permissions (such asservice.resource.verb). Use two to five specific keywords instead of a full question.
What's next
- Search and retrieve documents to fetch matching text snippets or full Markdown pages.
- Connect to the Developer Knowledge MCP server and install the
retrieving-developer-knowledgeagent skill. - Browse the Corpus reference to view all supported documentation sources.