@@ -10,6 +10,8 @@ toc_max_heading_level: 4
10
10
---
11
11
12
12
import Thumbnail from " @site/src/components/Thumbnail" ;
13
+ import Tabs from " @theme/Tabs" ;
14
+ import TabItem from " @theme/TabItem" ;
13
15
14
16
# Execute Program API
15
17
@@ -101,8 +103,6 @@ As you add your own custom business logic, you're providing more specific tools
101
103
102
104
Execute a PromptQL program with your data.
103
105
104
- ### Request
105
-
106
106
` POST https://promptql.ddn.hasura.app/api/execute_program `
107
107
108
108
:::note Private DDN Endpoint
@@ -116,16 +116,40 @@ by the control plane. For example:
116
116
117
117
:::
118
118
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
120
134
121
135
```
122
136
Content-Type: application/json
137
+ Authorization: Bearer <your-promptql-api-key>
123
138
```
124
139
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
126
149
127
150
``` json
128
151
{
152
+ "version" : " v1" ,
129
153
"code" : " <YOUR_PROMPTQL_GENERATED_CODE_HERE>" ,
130
154
"promptql_api_key" : " <YOUR_API_KEY_HERE>" ,
131
155
"ai_primitives_llm" : {
@@ -139,17 +163,20 @@ Content-Type: application/json
139
163
}
140
164
```
141
165
142
- ** Request Body Fields**
166
+ #### Request Body Fields
143
167
144
168
| Field | Type | Required | Description |
145
169
| ------------------- | ------ | -------- | -------------------------------------------------------- |
170
+ | ` version ` | string | No | Optional, must be "v1" for version 1 requests |
146
171
| ` 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) |
148
173
| ` ai_primitives_llm ` | object | Yes | Configuration for the AI primitives LLM provider |
149
174
| ` ddn ` | object | Yes | DDN configuration including URL and headers |
150
175
| ` artifacts ` | array | Yes | List of artifacts to provide as context or initial state |
151
176
152
- ** LLM Provider Options**
177
+ \* Required if not using Authorization header
178
+
179
+ #### LLM Provider Options
153
180
154
181
The ` ai_primitives_llm ` field supports the following providers:
155
182
@@ -179,7 +206,134 @@ The `ai_primitives_llm` field supports the following providers:
179
206
}
180
207
```
181
208
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
183
337
184
338
The ` artifacts ` array can contain both text and table artifacts:
185
339
@@ -215,7 +369,10 @@ The `artifacts` array can contain both text and table artifacts:
215
369
The ` ddn.headers ` field can be used to pass any auth header information through to DDN. Read more about
216
370
[ auth with these APIs] ( /promptql-apis/auth.mdx ) .
217
371
218
- ### Response
372
+ </TabItem >
373
+ </Tabs >
374
+
375
+ ## Response
219
376
220
377
``` json
221
378
{
@@ -246,7 +403,7 @@ The `ddn.headers` field can be used to pass any auth header information through
246
403
}
247
404
```
248
405
249
- ### Response Fields
406
+ ## Response Fields
250
407
251
408
| Field | Type | Description |
252
409
| ----------------------- | ------------ | ---------------------------------------------------------------- |
@@ -256,7 +413,7 @@ The `ddn.headers` field can be used to pass any auth header information through
256
413
| ` modified_artifacts ` | array | List of artifacts that were created or modified during execution |
257
414
| ` llm_usages ` | array | Details about LLM usage during execution |
258
415
259
- ** LLM Usage Fields**
416
+ ### LLM Usage Fields
260
417
261
418
| Field | Type | Description |
262
419
| --------------- | ------- | ------------------------------------------------------------- |
@@ -265,7 +422,7 @@ The `ddn.headers` field can be used to pass any auth header information through
265
422
| ` input_tokens ` | integer | Number of input tokens consumed |
266
423
| ` output_tokens ` | integer | Number of output tokens generated |
267
424
268
- ### Error Response
425
+ ## Error Response
269
426
270
427
When the API encounters an error, it will return a 422 status code with a validation error response:
271
428
@@ -281,20 +438,84 @@ When the API encounters an error, it will return a 422 status code with a valida
281
438
}
282
439
```
283
440
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
+
284
499
## Notes for using the Execute Program API
285
500
286
501
1 . ** Program Code**
287
502
288
503
- Ensure your PromptQL program code is properly formatted and tested
289
504
- You can export working programs from the PromptQL playground using the "Export as API" button
290
505
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**
292
512
293
513
- Provide all necessary artifacts that your program needs to run
294
514
- Make sure artifact identifiers match those referenced in your program code
295
515
- Both text and table artifacts are supported
296
516
297
- 3 . ** Error Handling**
517
+ 4 . ** Error Handling**
518
+
298
519
- Always check the error field in the response
299
520
- Implement appropriate retry logic for transient failures
300
521
- Validate your inputs against the API schema to catch issues early
0 commit comments