This quickstart shows you how to answer queries and search and retrieve developer documentation with the Developer Knowledge API by using the Google Cloud CLI.
Before you begin
Before you start using the Developer Knowledge API with the gcloud CLI, complete the following steps.
Install and configure the gcloud CLI
To install and configure the gcloud CLI, complete the following steps:
If you haven't installed the gcloud CLI, then install the gcloud CLI.
Run the
gcloud components updatecommand to make sure that you have the latest version:gcloud components update
Sign in to your Google Cloud account by running the
gcloud auth logincommand:gcloud auth login
Set your active Google Cloud project by running the
gcloud config setcommand:gcloud config set project PROJECT_ID
Replace
PROJECT_IDwith the ID of your Google Cloud project.
Enable the API
To enable the Developer Knowledge API, complete the following steps:
Enable the Developer Knowledge API in your Google Cloud project by running the
gcloud services enablecommand:gcloud services enable developerknowledge.googleapis.com
You don't need specific Identity and Access Management (IAM) roles to enable or use the API.
Verify that the API is enabled for your project by running the
gcloud services listcommand:gcloud services list --enabled \ --filter="name:developerknowledge.googleapis.com"The output lists the API name and title:
NAME TITLE developerknowledge.googleapis.com Developer Knowledge API
Generate answers from documentation
The gcloud developer-knowledge answer-query command
lets you ask questions about Google products and receive direct,
natural-language answers. The command pulls information from official
documentation sources and provides citations to the referenced pages.
To ask a question and generate an answer, complete the following steps:
Run the following command to ask how to create a Cloud Storage bucket:
gcloud developer-knowledge answer-query \ --query="How do I create a Cloud Storage bucket?"Confirm that the command returns a generated answer and source references in YAML format:
answer: answerText: |- To create a Cloud Storage bucket, you can use the Google Cloud console, the gcloud CLI (`gcloud storage buckets create`), client libraries, or the REST API... citations: - endIndex: 158 sources: - referenceIndex: 0 startIndex: 0 references: - documentReference: documentChunk: content: |- This document shows you how to create a Cloud Storage [bucket](https://docs.cloud.google.com/storage/docs/buckets)... document: dataSource: docs.cloud.google.com name: documents/docs.cloud.google.com/storage/docs/creating-buckets title: Create a bucket uri: https://docs.cloud.google.com/storage/docs/creating-buckets parent: documents/docs.cloud.google.com/storage/docs/creating-bucketsThe
answerobject in the output includes the following fields:answerText: the generated natural-language answer to your query.citations: byte-offset ranges,startIndexandendIndex, inanswerTextthat map to supporting entries inreferencesbyreferenceIndex.references: the source documentation chunks and metadata, includingdocumentandparent, used to generate the answer.
Search for document chunks
To find specific text excerpts in Google's developer documentation rather than
a generated answer, use the
gcloud developer-knowledge documents search-chunks command.
This command scans the documentation corpus and returns matching content chunks
alongside the resource names of their parent documents.
To search for document chunks, complete the following steps:
Run the following command to search for documentation about creating Cloud Storage buckets:
gcloud developer-knowledge documents search-chunks \ --query="How do I create a Cloud Storage bucket?"Confirm that the command returns a list of matching document chunks in YAML format:
--- content: |- This document shows you how to create a Cloud Storage [bucket](https://docs.cloud.google.com/storage/docs/buckets). If not otherwise specified in your request, buckets are created in the [US multi-region](https://docs.cloud.google.com/storage/docs/locations)... document: contentLengthBytes: 31842 dataSource: docs.cloud.google.com description: World-wide storage and retrieval of data in Google Cloud. name: documents/docs.cloud.google.com/storage/docs/creating-buckets title: Create a bucket updateTime: '2026-09-10T20:05:41Z' uri: https://docs.cloud.google.com/storage/docs/creating-buckets view: DOCUMENT_VIEW_BASIC id: c1 parent: documents/docs.cloud.google.com/storage/docs/creating-buckets relevanceScore: 0.856608Each chunk in the output includes the following fields:
content: the matched text snippet from the documentation.document: metadata about the source document, including itstitle,description,uri,dataSource, andupdateTime.id: the identifier of the chunk within the document.parent: the resource name of the parent document. You can pass this value to thedescribecommand to retrieve the full document.relevanceScore: the relevance score of the chunk to the search query.
Retrieve a document
After you find a relevant document chunk, use the parent field from those
search results to fetch the complete Markdown content of the document.
Run the gcloud developer-knowledge documents describe command
with the resource name of the document. For example, to retrieve the document on
creating Cloud Storage buckets, complete the following steps:
Run the following command:
gcloud developer-knowledge documents describe \ documents/docs.cloud.google.com/storage/docs/creating-buckets
Confirm that the command returns the metadata and full Markdown content of the document:
content: | This document shows you how to create a Cloud Storage [bucket](https://docs.cloud.google.com/storage/docs/buckets). If not otherwise specified in your request, buckets are created in the [`US` multi-region](https://docs.cloud.google.com/storage/docs/locations) with a default storage class of [Standard storage](https://docs.cloud.google.com/storage/docs/storage-classes) and have a seven-day [soft delete](https://docs.cloud.google.com/storage/docs/soft-delete) retention duration... contentLengthBytes: 31842 dataSource: docs.cloud.google.com description: World-wide storage and retrieval of data in Google Cloud. name: documents/docs.cloud.google.com/storage/docs/creating-buckets title: Create a bucket updateTime: '2026-09-10T20:05:41Z' uri: https://docs.cloud.google.com/storage/docs/creating-buckets view: DOCUMENT_VIEW_CONTENTThe output includes the following fields:
content: the full Markdown text of the document.contentLengthBytes: the total size of the document content in bytes.dataSource: the documentation domain hosting the document.description: a brief summary of the document.name: the unique resource name of the document.title: the title of the document.updateTime: the timestamp when the document was last updated.uri: the public URL of the documentation page.view: the document view returned (DOCUMENT_VIEW_CONTENT,DOCUMENT_VIEW_BASIC, orDOCUMENT_VIEW_FULL).
What's next
- Learn how to generate answers from documentation.
- Learn how to filter search results, paginate, and specify document views.
- Explore the corpus reference to view the full list of included documentation.
- Refer to the
gcloud developer-knowledgereference for details on all available commands and flags. - Review the REST API reference for complete specifications for API methods.
- Learn how to set up the Model Context Protocol (MCP) server in Google Antigravity.