Skip to content

Commit a623e48

Browse files
Add Version 2 request support to Natural Language API documentation (#130)
## Description 📝 This PR enhances the Natural Language API documentation by adding comprehensive support for Version 2 (v2) requests alongside the existing Version 1 (v1) documentation. Key changes: - Added complete v2 request documentation with build-based configuration - Clarified authentication requirements for both versions (Bearer token vs deprecated API key field) - Documented PromptQL configuration resolution order for v2 (build-level config with project-level fallback) - Enhanced DDN authentication section to cover both v1 and v2 implementations - Improved overall structure and organization of the API documentation - The updates provide clear guidance for developers migrating to v2 while maintaining backward compatibility documentation for v1 users. ## Quick Links 🚀 <!-- Links to the relevant place(s) in the CloudFlare Pages build. Wait for CF comment for link. --> ## Assertion Tests 🤖 <!-- Add assertions between the comments below to have ChatGPT check the quality of your docs contribution (Diff) and how well it integrates with existing docs. E.g., A user should be able to easily understand how to make a simple query. --> <!-- For more info, see the Action's docs in the marketplace: https://github.com/marketplace/actions/docs-assertion-tester#usage --> <!-- DX:Assertion-start --> <!-- DX:Assertion-end --> --------- Co-authored-by: Sean <[email protected]> Co-authored-by: Sean Park-Ross <[email protected]>
1 parent 19400e7 commit a623e48

File tree

1 file changed

+178
-14
lines changed

1 file changed

+178
-14
lines changed

docs/promptql-apis/natural-language-api.mdx

Lines changed: 178 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ keywords:
66
- hasura ddn
77
- natural language
88
- apis
9-
toc_max_heading_level: 4
9+
toc_max_heading_level: 2
1010
---
1111

12+
import Tabs from "@theme/Tabs";
13+
import TabItem from "@theme/TabItem";
14+
1215
# Natural Language API
1316

1417
## Introduction
@@ -69,8 +72,6 @@ communicate with PromptQL in real-time.
6972

7073
Send messages to PromptQL and receive responses, optionally in a streaming format.
7174

72-
### Request
73-
7475
`POST https://promptql.ddn.hasura.me/api/query`
7576

7677
:::note Private DDN Endpoint
@@ -82,13 +83,35 @@ by the control plane. For example:
8283

8384
:::
8485

85-
**Headers**
86+
### API Versions
87+
88+
The Natural Language API supports two versions:
89+
90+
- **Version 1 (v1)**: Uses direct DDN URL configuration with optional LLM settings
91+
- **Version 2 (v2)**: Uses DDN build-based configuration with settings from build metadata
92+
93+
## Request Specifications
94+
95+
<Tabs groupId="api-version" className="api-tabs">
96+
<TabItem value="v1" label="Version 1">
97+
98+
### Request
99+
100+
#### Headers
86101

87102
```
88103
Content-Type: application/json
104+
Authorization: Bearer <your-promptql-api-key>
89105
```
90106

91-
**Request Body**
107+
:::info Authentication
108+
109+
Version 1 requests support both the `Authorization` header (recommended) and the deprecated `promptql_api_key` field in the
110+
request body. For new implementations, use the `Authorization` header with the `Bearer <your-promptql-api-key>` token format.
111+
112+
:::
113+
114+
#### Request Body
92115

93116
```json
94117
{
@@ -124,7 +147,7 @@ Content-Type: application/json
124147
}
125148
```
126149

127-
**Request Body Fields**
150+
#### Request Body Fields
128151

129152
| Field | Type | Required | Description |
130153
| --------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -139,7 +162,7 @@ Content-Type: application/json
139162
| `interactions` | array | Yes | List of message interactions, including user messages and assistant responses. Each interaction contains a `user_message` object with the user's text and an optional `assistant_actions` array containing previous assistant responses with their messages, plans, code executions, and outputs. |
140163
| `stream` | boolean | Yes | Whether to return a streaming response |
141164

142-
**LLM Provider Options**
165+
#### LLM Provider Configuration
143166

144167
The `llm` and `ai_primitives_llm` fields support the following providers:
145168

@@ -176,16 +199,155 @@ You get $20 worth of free credits with Hasura's built-in provider during the tri
176199
}
177200
```
178201

179-
#### Request DDN Auth
202+
</TabItem>
203+
<TabItem value="v2" label="Version 2">
204+
205+
### Request
206+
207+
Version 2 requests use supergraph build versions instead of direct DDN URLs. The `build_version` refers to the version
208+
of supergraph builds created in your DDN project. Users can view build details in the DDN console or fetch information
209+
using the [`ddn supergraph build get`](/reference/cli/commands/ddn_supergraph_build_get) command.
210+
211+
#### Headers
212+
213+
```
214+
Content-Type: application/json
215+
Authorization: Bearer <your-promptql-api-key>
216+
```
217+
218+
:::info Authentication
219+
220+
Version 2 requests require the PromptQL API key to be sent as a Bearer token in the Authorization header.
221+
222+
:::
223+
224+
#### Request Body
225+
226+
```json
227+
{
228+
"version": "v2",
229+
"ddn": {
230+
"build_version": "505331f4b2",
231+
"headers": {}
232+
},
233+
"artifacts": [],
234+
"timezone": "America/Los_Angeles",
235+
"interactions": [
236+
{
237+
"user_message": {
238+
"text": "Your message here"
239+
},
240+
"assistant_actions": [
241+
{
242+
"message": "Previous assistant message",
243+
"plan": "Previous execution plan",
244+
"code": "Previously executed code",
245+
"code_output": "Previous code output",
246+
"code_error": "Previous error message if any"
247+
}
248+
]
249+
}
250+
],
251+
"stream": false
252+
}
253+
```
254+
255+
#### Request Body Fields
256+
257+
| Field | Type | Required | Description |
258+
| -------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
259+
| `version` | string | Yes | Must be set to "v2" |
260+
| `ddn` | object | Yes | DDN configuration including `build_version` and headers |
261+
| `artifacts` | array | No | List of existing artifacts to provide context |
262+
| `timezone` | string | Yes | IANA timezone for interpreting time-based queries |
263+
| `interactions` | array | Yes | List of message interactions, including user messages and assistant responses. Each interaction contains a `user_message` object with the user's text and an optional `assistant_actions` array containing previous assistant responses with their messages, plans, code executions, and outputs. |
264+
| `stream` | boolean | Yes | Whether to return a streaming response |
265+
266+
#### PromptQL Configuration
267+
268+
Unlike v1 requests, v2 requests do not accept `llm`, `ai_primitives_llm`, or `system_instructions` fields in the request
269+
body. Instead, these PromptQL settings are automatically inferred from the supergraph build configuration.
270+
271+
**Configuration Resolution Order:**
272+
273+
1. **Build-level PromptQL Config**: Settings are first retrieved from the
274+
[PromptQL configuration](/project-configuration/promptql-config/) associated with the specified `build_version`
275+
2. **Project-level Fallback**: For older builds that don't have PromptQL config included, the system falls back to the
276+
PromptQL configuration saved in the project settings
277+
278+
This approach ensures consistent configuration management and eliminates the need to specify LLM settings in each API
279+
request when using v2.
280+
281+
</TabItem>
282+
</Tabs>
283+
284+
## Authentication
285+
286+
### PromptQL API Authentication
287+
288+
Both API versions require authentication using your PromptQL API key:
289+
290+
- **Version 1**: Supports both `Authorization` header (recommended) and deprecated `promptql_api_key` field
291+
- **Version 2**: Requires `Authorization` header with Bearer token format
292+
293+
### DDN Authentication
294+
295+
The `ddn.headers` field allows you to pass authentication headers to your DDN endpoint and is supported in both
296+
**version 1 (v1)** and **version 2 (v2)** requests. This enables you to use any DDN-compatible authentication strategy
297+
with the Natural Language API.
298+
299+
<Tabs groupId="api-version" className="api-tabs">
300+
<TabItem value="v1" label="Version 1">
301+
302+
Configure headers in the `ddn.headers` object:
303+
304+
```json
305+
{
306+
"version": "v1",
307+
"ddn": {
308+
"url": "https://<PROJECT_NAME>.ddn.hasura.app/v1/sql",
309+
"headers": {
310+
"x-hasura-ddn-token": "<YOUR_DDN_AUTH_TOKEN>"
311+
}
312+
}
313+
}
314+
```
315+
316+
</TabItem>
317+
<TabItem value="v2" label="Version 2">
318+
319+
Configure headers in the `ddn.headers` object:
320+
321+
```json
322+
{
323+
"version": "v2",
324+
"ddn": {
325+
"build_version": "505331f4b2",
326+
"headers": {
327+
"x-hasura-ddn-token": "<YOUR_DDN_AUTH_TOKEN>"
328+
}
329+
}
330+
}
331+
```
332+
333+
</TabItem>
334+
</Tabs>
335+
336+
:::info Authentication Strategies
337+
338+
The headers you need to include depend on your DDN project's authentication configuration. For comprehensive information
339+
about setting up authentication modes and understanding which headers to use, refer to our
340+
[Authentication in APIs](/promptql-apis/auth.mdx) documentation.
180341

181-
The `ddn.headers` field can be used to pass any auth header information through to DDN. Read more about
182-
[auth with these APIs](/promptql-apis/auth.mdx).
342+
:::
343+
344+
## Response Format
183345

184-
### Response
346+
The response format depends on the `stream` parameter in your request:
185347

186-
The response format depends on the `stream` parameter:
348+
### Non-streaming Response
187349

188-
**Non-streaming Response** (application/json)
350+
**Content-Type:** `application/json`
189351

190352
```json
191353
{
@@ -209,7 +371,9 @@ The response format depends on the `stream` parameter:
209371
}
210372
```
211373

212-
**Streaming Response** (text/event-stream)
374+
### Streaming Response
375+
376+
**Content-Type:** `text/event-stream`
213377

214378
The streaming response sends chunks of data in Server-Sent Events (SSE) format:
215379

0 commit comments

Comments
 (0)