Skip to content

Commit b746bed

Browse files
authored
Update docs with v2 version of execute program api (#173)
## Description 📝 This pull request introduces significant updates to the documentation for the Execute Program API, focusing on adding support for multiple API versions, improving structure, and enhancing clarity. Key changes include the introduction of API versioning (v1 and v2), detailed request and response specifications for each version, and additional guidance on DDN authentication and build selection. ## Quick Links 🚀 - https://rakesh-pql-606-update-docs-w.promptql-docs.pages.dev/promptql-apis/execute-program-api/ <!-- 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 -->
1 parent fc2c3cb commit b746bed

File tree

1 file changed

+235
-14
lines changed

1 file changed

+235
-14
lines changed

docs/promptql-apis/execute-program-api.mdx

Lines changed: 235 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ toc_max_heading_level: 4
1010
---
1111

1212
import Thumbnail from "@site/src/components/Thumbnail";
13+
import Tabs from "@theme/Tabs";
14+
import TabItem from "@theme/TabItem";
1315

1416
# Execute Program API
1517

@@ -101,8 +103,6 @@ As you add your own custom business logic, you're providing more specific tools
101103

102104
Execute a PromptQL program with your data.
103105

104-
### Request
105-
106106
`POST https://promptql.ddn.hasura.app/api/execute_program`
107107

108108
:::note Private DDN Endpoint
@@ -116,16 +116,40 @@ by the control plane. For example:
116116

117117
:::
118118

119-
**Headers**
119+
### API Versions
120+
121+
The Execute Program API supports two versions:
122+
123+
- **Version 1 (v1)**: Uses direct DDN URL configuration with optional LLM settings
124+
- **Version 2 (v2)**: Uses DDN build-based configuration with settings from build metadata
125+
126+
## Request Specifications
127+
128+
<Tabs groupId="api-version" className="api-tabs">
129+
<TabItem value="v1" label="Version 1">
130+
131+
### Request
132+
133+
#### Headers
120134

121135
```
122136
Content-Type: application/json
137+
Authorization: Bearer <your-promptql-api-key>
123138
```
124139

125-
**Request Body**
140+
:::info Authentication
141+
142+
Version 1 requests support both the `Authorization` header (recommended) and the deprecated `promptql_api_key` field in
143+
the request body. For new implementations, use the `Authorization` header with the `Bearer <your-promptql-api-key>`
144+
token format.
145+
146+
:::
147+
148+
#### Request Body
126149

127150
```json
128151
{
152+
"version": "v1",
129153
"code": "<YOUR_PROMPTQL_GENERATED_CODE_HERE>",
130154
"promptql_api_key": "<YOUR_API_KEY_HERE>",
131155
"ai_primitives_llm": {
@@ -139,17 +163,20 @@ Content-Type: application/json
139163
}
140164
```
141165

142-
**Request Body Fields**
166+
#### Request Body Fields
143167

144168
| Field | Type | Required | Description |
145169
| ------------------- | ------ | -------- | -------------------------------------------------------- |
170+
| `version` | string | No | Optional, must be "v1" for version 1 requests |
146171
| `code` | string | Yes | The PromptQL program code to execute |
147-
| `promptql_api_key` | string | Yes | PromptQL API key created from project settings |
172+
| `promptql_api_key` | string | No\* | PromptQL API key (deprecated, use Authorization header) |
148173
| `ai_primitives_llm` | object | Yes | Configuration for the AI primitives LLM provider |
149174
| `ddn` | object | Yes | DDN configuration including URL and headers |
150175
| `artifacts` | array | Yes | List of artifacts to provide as context or initial state |
151176

152-
**LLM Provider Options**
177+
\*Required if not using Authorization header
178+
179+
#### LLM Provider Options
153180

154181
The `ai_primitives_llm` field supports the following providers:
155182

@@ -179,7 +206,134 @@ The `ai_primitives_llm` field supports the following providers:
179206
}
180207
```
181208

182-
**Artifacts**
209+
#### Artifacts
210+
211+
The `artifacts` array can contain both text and table artifacts:
212+
213+
1. Text Artifact:
214+
215+
```json
216+
{
217+
"identifier": "my_text",
218+
"title": "My Text Document",
219+
"artifact_type": "text",
220+
"data": "Text content here"
221+
}
222+
```
223+
224+
2. Table Artifact:
225+
226+
```json
227+
{
228+
"identifier": "my_table",
229+
"title": "My Data Table",
230+
"artifact_type": "table",
231+
"data": [
232+
{
233+
"column1": "value1",
234+
"column2": "value2"
235+
}
236+
]
237+
}
238+
```
239+
240+
#### Request DDN Auth
241+
242+
The `ddn.headers` field can be used to pass any auth header information through to DDN. Read more about
243+
[auth with these APIs](/promptql-apis/auth.mdx).
244+
245+
</TabItem>
246+
<TabItem value="v2" label="Version 2">
247+
248+
### Request
249+
250+
Version 2 requests use supergraph build versions instead of direct DDN URLs. The `build_version` refers to the version
251+
of supergraph builds created in your DDN project. Users can view build details in the DDN console or fetch information
252+
using the [`ddn supergraph build get`](/reference/cli/commands/ddn_supergraph_build_get) command.
253+
254+
When `build_version` is not specified in the request, the project's applied build is automatically chosen. This allows
255+
you to use the currently deployed build without needing to specify its version explicitly.
256+
257+
#### Headers
258+
259+
```
260+
Content-Type: application/json
261+
Authorization: Bearer <your-promptql-api-key>
262+
```
263+
264+
:::info Authentication
265+
266+
Version 2 requests require the PromptQL API key to be sent as a Bearer token in the Authorization header.
267+
268+
:::
269+
270+
#### Request Body
271+
272+
```json
273+
{
274+
"version": "v2",
275+
"code": "<YOUR_PROMPTQL_GENERATED_CODE_HERE>",
276+
"ddn": {
277+
"build_version": "505331f4b2",
278+
"headers": {}
279+
},
280+
"artifacts": []
281+
}
282+
```
283+
284+
**Example using applied build (without specifying build_version):**
285+
286+
```json
287+
{
288+
"version": "v2",
289+
"code": "<YOUR_PROMPTQL_GENERATED_CODE_HERE>",
290+
"ddn": {
291+
"headers": {}
292+
},
293+
"artifacts": []
294+
}
295+
```
296+
297+
**Example using build_id instead of build_version:**
298+
299+
```json
300+
{
301+
"version": "v2",
302+
"code": "<YOUR_PROMPTQL_GENERATED_CODE_HERE>",
303+
"ddn": {
304+
"build_id": "8ac7ccd4-7502-44d5-b2ee-ea9639b1f653",
305+
"headers": {}
306+
},
307+
"artifacts": []
308+
}
309+
```
310+
311+
#### Request Body Fields
312+
313+
| Field | Type | Required | Description |
314+
| ----------- | ------ | -------- | -------------------------------------------------------- |
315+
| `version` | string | Yes | Must be "v2" for version 2 requests |
316+
| `code` | string | Yes | The PromptQL program code to execute |
317+
| `ddn` | object | No | DDN configuration for build selection and headers |
318+
| `artifacts` | array | No | List of artifacts to provide as context or initial state |
319+
320+
#### DDN Configuration Fields
321+
322+
| Field | Type | Required | Description |
323+
| --------------- | ------ | -------- | ---------------------------------------------------------- |
324+
| `build_id` | string | No | UUID of the DDN build. Cannot be used with `build_version` |
325+
| `build_version` | string | No | Version of the DDN build. Cannot be used with `build_id` |
326+
| `headers` | object | No | HTTP headers that should be forwarded to DDN |
327+
328+
:::note Build Selection
329+
330+
- If both `build_id` and `build_version` are omitted, the project's applied build is automatically used
331+
- You can specify either `build_id` OR `build_version`, but not both simultaneously
332+
- The `build_version` refers to supergraph build versions created in your DDN project
333+
334+
:::
335+
336+
#### Artifacts
183337

184338
The `artifacts` array can contain both text and table artifacts:
185339

@@ -215,7 +369,10 @@ The `artifacts` array can contain both text and table artifacts:
215369
The `ddn.headers` field can be used to pass any auth header information through to DDN. Read more about
216370
[auth with these APIs](/promptql-apis/auth.mdx).
217371

218-
### Response
372+
</TabItem>
373+
</Tabs>
374+
375+
## Response
219376

220377
```json
221378
{
@@ -246,7 +403,7 @@ The `ddn.headers` field can be used to pass any auth header information through
246403
}
247404
```
248405

249-
### Response Fields
406+
## Response Fields
250407

251408
| Field | Type | Description |
252409
| ----------------------- | ------------ | ---------------------------------------------------------------- |
@@ -256,7 +413,7 @@ The `ddn.headers` field can be used to pass any auth header information through
256413
| `modified_artifacts` | array | List of artifacts that were created or modified during execution |
257414
| `llm_usages` | array | Details about LLM usage during execution |
258415

259-
**LLM Usage Fields**
416+
### LLM Usage Fields
260417

261418
| Field | Type | Description |
262419
| --------------- | ------- | ------------------------------------------------------------- |
@@ -265,7 +422,7 @@ The `ddn.headers` field can be used to pass any auth header information through
265422
| `input_tokens` | integer | Number of input tokens consumed |
266423
| `output_tokens` | integer | Number of output tokens generated |
267424

268-
### Error Response
425+
## Error Response
269426

270427
When the API encounters an error, it will return a 422 status code with a validation error response:
271428

@@ -281,20 +438,84 @@ When the API encounters an error, it will return a 422 status code with a valida
281438
}
282439
```
283440

441+
## DDN Authentication
442+
443+
Both API versions support passing authentication headers to DDN through the `ddn.headers` field.
444+
445+
<Tabs groupId="api-version" className="api-tabs">
446+
<TabItem value="v1" label="Version 1">
447+
448+
Configure headers in the `ddn.headers` object:
449+
450+
```json
451+
{
452+
"code": "<YOUR_PROMPTQL_GENERATED_CODE_HERE>",
453+
"ddn": {
454+
"url": "https://<PROJECT_NAME>.ddn.hasura.app/v1/sql",
455+
"headers": {
456+
"x-hasura-ddn-token": "<YOUR_DDN_AUTH_TOKEN>"
457+
}
458+
}
459+
}
460+
```
461+
462+
</TabItem>
463+
<TabItem value="v2" label="Version 2">
464+
465+
Configure headers in the `ddn.headers` object:
466+
467+
```json
468+
{
469+
"version": "v2",
470+
"code": "<YOUR_PROMPTQL_GENERATED_CODE_HERE>",
471+
"ddn": {
472+
"build_version": "505331f4b2",
473+
"headers": {
474+
"x-hasura-ddn-token": "<YOUR_DDN_AUTH_TOKEN>"
475+
}
476+
}
477+
}
478+
```
479+
480+
**Using applied build:**
481+
482+
```json
483+
{
484+
"version": "v2",
485+
"code": "<YOUR_PROMPTQL_GENERATED_CODE_HERE>",
486+
"ddn": {
487+
"headers": {
488+
"x-hasura-ddn-token": "<YOUR_DDN_AUTH_TOKEN>"
489+
}
490+
}
491+
}
492+
```
493+
494+
</TabItem>
495+
</Tabs>
496+
497+
Read more about [auth with these APIs](/promptql-apis/auth.mdx).
498+
284499
## Notes for using the Execute Program API
285500

286501
1. **Program Code**
287502

288503
- Ensure your PromptQL program code is properly formatted and tested
289504
- You can export working programs from the PromptQL playground using the "Export as API" button
290505

291-
2. **Artifacts**
506+
2. **Build Selection (Version 2)**
507+
508+
- When using v2, you can specify either `build_id` or `build_version`, but not both
509+
- If neither is specified, the project's applied build is automatically used
510+
511+
3. **Artifacts**
292512

293513
- Provide all necessary artifacts that your program needs to run
294514
- Make sure artifact identifiers match those referenced in your program code
295515
- Both text and table artifacts are supported
296516

297-
3. **Error Handling**
517+
4. **Error Handling**
518+
298519
- Always check the error field in the response
299520
- Implement appropriate retry logic for transient failures
300521
- Validate your inputs against the API schema to catch issues early

0 commit comments

Comments
 (0)