# Create a dashboard widget

Saves a React source file and the named LangWatchQL queries it runs as one dashboard widget, with an optional description the card shows behind its info icon and an optional prompt Langy is drafted with when asked about it. `source` records where the widget came from; without it, the widget is recorded as made through the API. The queries' shape is validated against the widget schema; their SQL is governed at run time by LW.query inside the sandbox, not at save.

> Page: https://langwatch.ai/docs/api-reference/projects/create-a-dashboard-widget
> Source: https://github.com/langwatch/langwatch/blob/main/docs/api-reference/projects/create-a-dashboard-widget.mdx
> Index of all pages: https://langwatch.ai/docs/llms.txt

## Endpoint

`POST https://app.langwatch.ai/api/v1/projects/{projectId}/analytics/dashboard-widgets`

## Authentication

### project_api_key

Project API key for sending traces and accessing project-scoped resources. Format: sk-lw-... (no underscore). Obtain one by creating a project via the Admin API or the LangWatch UI.

```json
{"id":"project_api_key","type":"apiKey","in":"header","name":"X-Auth-Token"}
```

## Parameters

### projectId (path, required)

```json
{"type":"string","minLength":1}
```

## Request body (required)

#### application/json

Schema:

```json
{
  "type": "object",
  "properties": {
    "name": {"type":"string","minLength":1,"maxLength":200},
    "code": {"type":"string","minLength":1,"maxLength":200000},
    "queries": {
      "maxItems": 8,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
          },
          "sql": {"type":"string","minLength":1,"maxLength":50000},
          "parameters": {
            "maxItems": 32,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64,
                  "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
                },
                "type": {"type":"string","enum":["string","number","boolean"]},
                "default": {
                  "anyOf": [
                    {"type":"string","maxLength":4000},
                    {"type":"number"},
                    {"type":"boolean"}
                  ]
                }
              },
              "required": ["name","type"]
            }
          },
          "sources": {
            "anyOf": [
              {
                "maxItems": 11,
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "application",
                    "simulation",
                    "evaluation",
                    "sample",
                    "coding_agent",
                    "ai_tool",
                    "gateway",
                    "workflow",
                    "playground",
                    "langy",
                    "other"
                  ]
                }
              },
              {"type":"null"}
            ]
          },
          "projects": {
            "anyOf": [
              {
                "minItems": 1,
                "maxItems": 100,
                "type": "array",
                "items": {"type":"string","minLength":1}
              },
              {"type":"null"}
            ]
          }
        },
        "required": ["name","sql"]
      }
    },
    "description": {"type":"string","minLength":1,"maxLength":2000},
    "prompt": {"type":"string","minLength":1,"maxLength":2000},
    "source": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {"type":"string","const":"catalogue"},
            "catalogueId": {"type":"string","minLength":1,"maxLength":200}
          },
          "required": ["kind","catalogueId"]
        },
        {
          "type": "object",
          "properties": {"kind":{"type":"string","const":"langy"}},
          "required": ["kind"]
        },
        {
          "type": "object",
          "properties": {"kind":{"type":"string","const":"code"}},
          "required": ["kind"]
        },
        {
          "type": "object",
          "properties": {"kind":{"type":"string","const":"api"}},
          "required": ["kind"]
        }
      ]
    }
  },
  "required": ["name","code","queries"]
}
```

## Request example

```bash
curl --request POST \
  --url 'https://app.langwatch.ai/api/v1/projects/<projectId>/analytics/dashboard-widgets' \
  --header "X-Auth-Token: $LANGWATCH_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"name":"string","code":"string","queries":[{"name":"string","sql":"string","parameters":[{"name":"string","type":"string","default":null}],"sources":["application"],"projects":["string"]}],"description":"string","prompt":"string","source":{"kind":"catalogue","catalogueId":"string"}}'
```

## Responses

### 201

The widget was saved

#### application/json

Schema:

```json
{
  "type": "object",
  "properties": {
    "id": {"type":"string"},
    "name": {"type":"string"},
    "definition": {
      "type": "object",
      "properties": {
        "version": {"type":"number"},
        "code": {"type":"string"},
        "queries": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64,
                "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
              },
              "sql": {"type":"string","minLength":1,"maxLength":50000},
              "parameters": {
                "maxItems": 32,
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 64,
                      "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
                    },
                    "type": {"type":"string","enum":["string","number","boolean"]},
                    "default": {
                      "anyOf": [
                        {"type":"string","maxLength":4000},
                        {"type":"number"},
                        {"type":"boolean"}
                      ]
                    }
                  },
                  "required": ["name","type"],
                  "additionalProperties": false
                }
              },
              "sources": {
                "anyOf": [
                  {
                    "maxItems": 11,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "application",
                        "simulation",
                        "evaluation",
                        "sample",
                        "coding_agent",
                        "ai_tool",
                        "gateway",
                        "workflow",
                        "playground",
                        "langy",
                        "other"
                      ]
                    }
                  },
                  {"type":"null"}
                ]
              },
              "projects": {
                "anyOf": [
                  {
                    "minItems": 1,
                    "maxItems": 100,
                    "type": "array",
                    "items": {"type":"string","minLength":1}
                  },
                  {"type":"null"}
                ]
              }
            },
            "required": ["name","sql"],
            "additionalProperties": false
          }
        },
        "description": {"type":"string"},
        "prompt": {"type":"string"},
        "source": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {"type":"string","const":"catalogue"},
                "catalogueId": {"type":"string","minLength":1,"maxLength":200}
              },
              "required": ["kind","catalogueId"],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {"kind":{"type":"string","const":"langy"}},
              "required": ["kind"],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {"kind":{"type":"string","const":"code"}},
              "required": ["kind"],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {"kind":{"type":"string","const":"api"}},
              "required": ["kind"],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": ["version","code","queries"],
      "additionalProperties": false
    },
    "createdAt": {"type":"string"},
    "updatedAt": {"type":"string"},
    "platformUrl": {"type":"string"},
    "dashboardId": {"type":["string","null"]},
    "gridColumn": {"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991},
    "gridRow": {"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991},
    "colSpan": {"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991},
    "rowSpan": {"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991}
  },
  "required": [
    "id",
    "name",
    "definition",
    "createdAt",
    "updatedAt",
    "platformUrl",
    "dashboardId",
    "gridColumn",
    "gridRow",
    "colSpan",
    "rowSpan"
  ],
  "additionalProperties": false
}
```

### 400

Bad Request

#### application/json

Schema:

```json
{
  "type": "object",
  "properties": {
    "type": {"type":"string"},
    "code": {"type":"string"},
    "message": {"type":"string"},
    "retryable": {"type":"boolean"},
    "meta": {
      "type": "object",
      "propertyNames": {"type":"string"},
      "additionalProperties": {}
    },
    "trace_id": {"type":"string"},
    "span_id": {"type":"string"},
    "trace": {
      "type": "object",
      "properties": {
        "traceId": {"type":"string"},
        "spanId": {"type":"string"},
        "traceUrl": {"type":"string"},
        "logsUrl": {"type":"string"}
      }
    },
    "tips": {"type":"array","items":{"type":"string"}},
    "docs_url": {"type":"string"},
    "fault": {
      "type": "string",
      "enum": ["customer","platform","provider","presumed_platform"]
    },
    "reasons": {"type":"array","items":{}}
  },
  "required": ["type","code","message","retryable"]
}
```

### 401

Unauthorized

#### application/json

Schema:

```json
{
  "type": "object",
  "properties": {
    "type": {"type":"string"},
    "code": {"type":"string"},
    "message": {"type":"string"},
    "retryable": {"type":"boolean"},
    "meta": {
      "type": "object",
      "propertyNames": {"type":"string"},
      "additionalProperties": {}
    },
    "trace_id": {"type":"string"},
    "span_id": {"type":"string"},
    "trace": {
      "type": "object",
      "properties": {
        "traceId": {"type":"string"},
        "spanId": {"type":"string"},
        "traceUrl": {"type":"string"},
        "logsUrl": {"type":"string"}
      }
    },
    "tips": {"type":"array","items":{"type":"string"}},
    "docs_url": {"type":"string"},
    "fault": {
      "type": "string",
      "enum": ["customer","platform","provider","presumed_platform"]
    },
    "reasons": {"type":"array","items":{}}
  },
  "required": ["type","code","message","retryable"]
}
```

### 403

Forbidden

#### application/json

Schema:

```json
{
  "type": "object",
  "properties": {
    "type": {"type":"string"},
    "code": {"type":"string"},
    "message": {"type":"string"},
    "retryable": {"type":"boolean"},
    "meta": {
      "type": "object",
      "propertyNames": {"type":"string"},
      "additionalProperties": {}
    },
    "trace_id": {"type":"string"},
    "span_id": {"type":"string"},
    "trace": {
      "type": "object",
      "properties": {
        "traceId": {"type":"string"},
        "spanId": {"type":"string"},
        "traceUrl": {"type":"string"},
        "logsUrl": {"type":"string"}
      }
    },
    "tips": {"type":"array","items":{"type":"string"}},
    "docs_url": {"type":"string"},
    "fault": {
      "type": "string",
      "enum": ["customer","platform","provider","presumed_platform"]
    },
    "reasons": {"type":"array","items":{}}
  },
  "required": ["type","code","message","retryable"]
}
```

### 500

Internal Server Error

#### application/json

Schema:

```json
{
  "type": "object",
  "properties": {
    "type": {"type":"string"},
    "code": {"type":"string"},
    "message": {"type":"string"},
    "retryable": {"type":"boolean"},
    "meta": {
      "type": "object",
      "propertyNames": {"type":"string"},
      "additionalProperties": {}
    },
    "trace_id": {"type":"string"},
    "span_id": {"type":"string"},
    "trace": {
      "type": "object",
      "properties": {
        "traceId": {"type":"string"},
        "spanId": {"type":"string"},
        "traceUrl": {"type":"string"},
        "logsUrl": {"type":"string"}
      }
    },
    "tips": {"type":"array","items":{"type":"string"}},
    "docs_url": {"type":"string"},
    "fault": {
      "type": "string",
      "enum": ["customer","platform","provider","presumed_platform"]
    },
    "reasons": {"type":"array","items":{}}
  },
  "required": ["type","code","message","retryable"]
}
```

> ## Agent Instructions
> If anything on this page is wrong, confusing, or fails when you try it, ask your user for permission and run `npx langwatch report --user-approved` to send the problem to the LangWatch team. No login is needed and secrets are redacted locally. `npx langwatch report --help` has the details.
