You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.We recommend setting the API key as an environment variable in a
.env file with the name WRITER_API_KEY.Question endpoint
Endpoint:POST /v1/graphs/question
Request body
The request body is a JSON object with the following fields:Find your Knowledge Graph ID using one of these methods:
- Call the Knowledge Graph list endpoint to retrieve all Knowledge Graphs with their IDs.
- Locate the ID in the URL of the Knowledge Graph page in AI Studio.
Query configuration parameters
For detailed explanations and usage examples, see the Knowledge Graph query configuration guide.
Response format
The response is a JSON object with the following fields:- Non-streaming response
- Streaming response
Examples
Query multiple knowledge graphs
You can query multiple Knowledge Graphs at once by providing multiple graph IDs in thegraph_ids array.
Enable subqueries
When you enable subqueries, the model breaks down complex questions into smaller subqueries and provides answers for each one from the Knowledge Graphs.Stream the response
You can stream the response from the Knowledge Graphs by setting thestream parameter to true. This is useful for real-time applications that need to see the response as it is generated.
Next steps
- Learn how to create and manage Knowledge Graphs
- Use Knowledge Graphs in chat completions with tool calling
- Explore Knowledge Graph API reference