DocsGuidesPromptQL Program API

PromptQL Program API

(For advanced users)

The PromptQL agent creates PromptQL programs that work on your data. Usually, these programs are created and invoked by interacting within the PromptQL playground.

However, you can also use an API to run these programs dynamically.

API Reference

Execute Program

Execute a PromptQL program with your data.

Request

POST https://api.promptql.pro.hasura.io/execute_program

Headers

Content-Type: application/json

Request Body

{
  "code": "<your code>",
  "promptql_api_key": "<promptql api key created from project settings>",
  "ai_primitives_llm": {
    "provider": "hasura"
  },
  "ddn": {
    "url": "<project sql endpoint url, eg: https://tidy-katydid-4994.ddn.hasura.app/v1/sql>",
    "headers": {}
  },
  "artifacts": []
}

Example cURL

curl -X POST "https://api.promptql.pro.hasura.io/execute_program" \
-H "Content-Type: application/json" \
-d '{
  "code": "<your code>",
  "promptql_api_key": "<promptql api key created from project settings>",
  "ai_primitives_llm": {
    "provider": "hasura"
  },
  "ddn": {
    "url": "<sql endpoint url, eg: https://tidy-katydid-4994.ddn.hasura.app/v1/sql>",
    "headers": {}
  },
  "artifacts": []
}'

Response

{
  "output": "<program output>",
  "error": null,
  "modified_artifacts": [
    {
      "identifier": "my_artifact",
      "title": "My artifact",
      "artifact_type": "table",
      "data": [
        {
          "my_column": 1
        },
        {
          "my_column": 2
        }
      ]
    }
  ],
  "llm_usages": [
    {
      "provider": "anthropic",
      "model": "claude-3-5-sonnet-20241022",
      "input_tokens": 691,
      "output_tokens": 33
    }
  ]
}
FieldTypeDescription
outputstringThe program’s output, similar to what you see in the playground
errorstring|nullError message if execution failed, null otherwise
modified_artifactsarrayList of artifacts modified or created by the program
llm_usagesarrayDetails about LLM usage during execution

Get PromptQL programs from the playground

You can get PromptQL programs from PromptQL playground interactions by clicking on the “Export as API” button next to the Query Plan in the playground.

Export as API