# API reference

This reference describes the GraphN workspace HTTP API for building and running workflows without the web UI. Examples use curl and assume you substitute real identifiers where noted.

> **Scope:** This page covers the workflow, agent, function, MCP server, imported-model, secret, knowledge-base, storage, and API-key routes. It is task-oriented rather than a generated schema reference. For custom-model deployment, see [Import a custom model with the Python SDK](./tutorial-custom-model-sdk.md); for inference, see [Getting started with inference](./inference-quickstart.md). For the generated OpenAPI surface, use the [API explorer](/api) or the [OpenAPI spec](https://github.com/voltagepark/graphn-openapi).

## Base URL and authentication

**Base URL:** `https://cp.graphn.ai`

> **Important:** Every example targets **graphn-cp** (`https://cp.graphn.ai`), the control plane. For `run`, `test`, and `dry-run`, graphn-cp **enriches** your request — it attaches the published DSL, resource snapshots, and resolved secrets — before forwarding it to the Agent Foundry (AF) execution service. Do **not** call the AF API (port `:8000`) directly for CRUD, and do not send a bare `{ "input": ... }` run straight to AF: AF rejects non-enriched run payloads with `400`. Always go through graphn-cp.

Send a valid Bearer token on every request:

```http
Authorization: Bearer <token>
```

Create a token on the app's **API keys** page (sidebar → **API keys**). Keys use the `gn_` prefix and authorize access for that workspace only. Use the **same workspace identifier** in URLs as the workspace the key belongs to.

**Content type:** Use `Content-Type: application/json` for JSON bodies.

> **Tip:** If you use a session or user token instead of a workspace API key, you may need to pass the workspace explicitly when the product supports it. Workspace API keys are scoped to one workspace and are the usual choice for automation.

## Finding your workspace and workflow IDs

The **API** tab on the workflow editor (after you publish a workflow) shows the full **POST** URL for running that workflow, including your workspace ID and workflow ID. Copy that URL as the starting point for runs and for matching the path pattern used below.

![Workflow API tab showing the endpoint URL, input schema, and curl snippet](/docs/screenshot-workflow-api-tab.png)

## URL patterns

Most resources are addressed as:

- `https://cp.graphn.ai/v1/{workspace_id}/...`

Most resources use this same pattern. **Storage is the exception:** object storage is served by the takao **storage service**, which the web UI calls directly (via `VITE_STORAGE_URL`, or the `/storage` dev proxy locally) rather than through the graphn-cp workspace routes. In all examples, replace `{workspace_id}`, `{workflow_id}`, `{agent_id}`, and similar tokens with your values.

## Common errors

| Status | Meaning |
|--------|---------|
| `401` | Missing, invalid, or expired Bearer token. |
| `403` | Authenticated but not allowed to access this workspace or resource (for example, wrong `{workspace_id}` in the URL). |
| `404` | Resource does not exist or is not visible in this workspace. |
| `409` | Conflict (for example, duplicate secret name). |
| `422` | Request body failed validation (for example, missing required workflow input, invalid DSL). |
| `429` | Rate limited. Retry after the interval in the `Retry-After` header. |

Error bodies are JSON and usually include a `detail` field (string or list of validation issues) you can log or surface.

## Rate limits

Requests are subject to rate limiting. If you receive a `429 Too Many Requests` response, back off and retry after the interval indicated by the `Retry-After` header. Current rate-limit quotas depend on your plan; contact support for details.

---

## Workflows

### List workflows

- **Method and path:** `GET /v1/{workspace_id}/workflows`
- **Query parameters (optional):** `limit` (default `100`, max `100`), `continue_token` (opaque cursor returned by the previous page).
- **Response:** `200` — JSON object with `items` (array of workflow objects), `count`, and `continue_token` (present only when more results remain; pass it back as `continue_token` to fetch the next page). Each workflow includes `id`, `name`, `dsl`, `status`, `versions`, timestamps, and related metadata.

```bash
curl -sS "https://cp.graphn.ai/v1/${WORKSPACE_ID}/workflows?limit=20" \
  -H "Authorization: Bearer ${TOKEN}"
```

### Create workflow

- **Method and path:** `POST /v1/{workspace_id}/workflows`
- **Request body (JSON):** At minimum `name` (string). Optional fields include `dsl` (YAML string), `layout` (object), `input_schema` and `output_schema` (JSON objects), `description`, optional free-text chat hints for the workspace assistant, and `source` (origin metadata).
- **Response:** `201` — Created workflow object.

```bash
curl -sS -X POST "https://cp.graphn.ai/v1/${WORKSPACE_ID}/workflows" \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"name":"My workflow","description":"Created via API"}'
```

### Get workflow by ID

- **Method and path:** `GET /v1/{workspace_id}/workflows/{workflow_id}`
- **Response:** `200` — Workflow object. `404` if not found or not in this workspace.

```bash
curl -sS "https://cp.graphn.ai/v1/${WORKSPACE_ID}/workflows/${WORKFLOW_ID}" \
  -H "Authorization: Bearer ${TOKEN}"
```

### Get workflow by name

- **Method and path:** `GET /v1/{workspace_id}/workflows/by-name/{name}` (URL-encode the name if it contains special characters).
- **Response:** `200` — Workflow object. `404` if not found.

### Update workflow

- **Method and path:** `PATCH /v1/{workspace_id}/workflows/{workflow_id}`
- **Request body (JSON):** Any subset of `name`, `dsl`, `layout`, `input_schema`, `output_schema`, `description`, and optional hints.
- **Response:** `200` — Updated workflow object.

### Delete workflow

- **Method and path:** `DELETE /v1/{workspace_id}/workflows/{workflow_id}`
- **Response:** `204` — No content on success. `404`/`403` on failure.

### Get workflow bundle (read)

- **Method and path:** `GET /v1/{workspace_id}/workflows/{workflow_id}/bundle`
- **Response:** `200` — JSON with `workflow`, `agents`, `functions`, and `mcp_servers` (full draft state for the workflow).

### Save workflow bundle (atomic save)

- **Method and path:** `PUT /v1/{workspace_id}/workflows/{workflow_id}/bundle`
- **Request body (JSON):**
  - `workflow` — object with fields to update (same shape as `PATCH` for a workflow).
  - `agents` — array of `{ "id"?: string, "name": string, "spec": { ... } }`.
  - `functions` — array of `{ "id"?: string, "name": string, "spec": { ... } }`.
  - `mcp_servers` — array of `{ "id"?: string, "name": string, "spec": { ... } }`.
- **Response:** `200` — JSON with updated `workflow`, `agents`, `functions`, `mcp_servers`, and `validation` (`{ "valid": boolean, "errors": [...] }`).

### Publish workflow

- **Method and path:** `POST /v1/{workspace_id}/workflows/{workflow_id}/publish`
- **Request body (optional JSON):** `{ "message": "optional note" }` or empty body.
- **Response:** `200` — Published version details including `version_id`, `version_number`, `dsl`, and resource snapshots. `422` if the DSL is missing or invalid.

### List workflow versions

- **Method and path:** `GET /v1/{workspace_id}/workflows/{workflow_id}/versions`
- **Response:** `200` — JSON with `versions` (array of version metadata) and `published_version_id`.

### Get one workflow version

- **Method and path:** `GET /v1/{workspace_id}/workflows/{workflow_id}/versions/{version_id}`
- **Response:** `200` — Version metadata plus `dsl` and resource snapshots when available.

### Restore workflow to a version

- **Method and path:** `POST /v1/{workspace_id}/workflows/{workflow_id}/restore/{version_number}`
- **Query (optional):** `restore_resources` (boolean, default `true`) — whether to restore linked resource specs from the snapshot.
- **Response:** `200` — Updated workflow object.

### Run workflow

- **Method and path:** `POST /v1/{workspace_id}/workflows/{workflow_id}/run`
- **Request body (JSON):**
  - `input` (object, required) — Payload your workflow expects (keys must match the workflow’s published input schema when defined).
- **Response:** `200` — JSON including:
  - `execution_id` — Identifier for this run.
  - `status` — `"completed"` or `"failed"` (or other execution status values).
  - `output` — Result value when completed.
  - `error` — Message when failed.
  - `trace` — Execution trace with spans, token usage, and resource references when available.
  - `node_results` — Per-node summaries when the DAG executor produced them.

```bash
curl -sS -X POST "https://cp.graphn.ai/v1/${WORKSPACE_ID}/workflows/${WORKFLOW_ID}/run" \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"input":{"your_field":"value"}}'
```

```python
import requests

resp = requests.post(
    f"https://cp.graphn.ai/v1/{WORKSPACE_ID}/workflows/{WORKFLOW_ID}/run",
    headers={"Authorization": f"Bearer {TOKEN}"},
    json={"input": {"your_field": "value"}},
)
result = resp.json()
print(result["status"], result.get("output"))
```

### Run workflow (test / preview)

- **Method and path:** `POST /v1/{workspace_id}/workflows/{workflow_id}/test`
- **Request and response:** Same body and response shape as **Run workflow** (useful for preview runs from the editor; behavior matches your product’s test execution path).

> **Note:** The **API** tab on the workflow editor shows the exact **POST** URL for **Run workflow** with your real IDs. The tab’s sample wraps your JSON in an `input` wrapper: `{ "input": { ... } }` — keep that structure when the workflow defines structured input.

### Dry-run workflow (inline DSL)

- **Method and path:** `POST /v1/{workspace_id}/workflows/dry-run`
- **Request body (JSON):** An inline workflow `dsl` plus `input` (and any inline resource definitions the DSL references). graphn-cp enriches and forwards the request to AF; nothing is persisted.
- **Response:** `200` — Same execution result shape as **Run workflow**.

---

## Executions

### Get execution

- **Method and path:** `GET /v1/{workspace_id}/executions/{execution_id}`
- **Response:** `200` — JSON including:
  - `id`, `workflow_id`, `workspace_id`
  - `status`
  - `input_data` — Object (the input payload for the run).
  - `output`, `error` — When finished.
  - `trace` — Trace object when available.
  - `duration_ms`, `created_at`, `started_at`, `completed_at`

```bash
curl -sS "https://cp.graphn.ai/v1/${WORKSPACE_ID}/executions/${EXECUTION_ID}" \
  -H "Authorization: Bearer ${TOKEN}"
```

### List executions for a workflow

- **Method and path:** `GET /v1/{workspace_id}/executions`
- **Query parameters (required):** `workflow_id` — Target workflow.
- **Query parameters (optional):** `limit` (max `100`). graphn-cp accepts `limit` and maps it to the underlying AF executions API internally.
- **Response:** `200` — JSON with `items` and `total`.

```bash
curl -sS "https://cp.graphn.ai/v1/${WORKSPACE_ID}/executions?workflow_id=${WORKFLOW_ID}&limit=20" \
  -H "Authorization: Bearer ${TOKEN}"
```

---

## Agents

### List agents

- **Method and path:** `GET /v1/{workspace_id}/agents`
- **Query parameters (optional):** `limit` (default `100`, max `100`), `continue_token` (cursor for the next page), `workflow_id` (filter agents linked to a workflow).
- **Response:** `200` — JSON with `items`, `count`, and `continue_token` (present only when more results remain).

```bash
curl -sS "https://cp.graphn.ai/v1/${WORKSPACE_ID}/agents?limit=20" \
  -H "Authorization: Bearer ${TOKEN}"
```

### Create agent

- **Method and path:** `POST /v1/{workspace_id}/agents`
- **Request body (JSON):**
  - `name` (string, required).
  - `spec` (object, required) — includes at least `instructions`; optional `model`, `mcp_tools` (array of `{ "server_id", "tool_name" }`), `knowledge_base_id`, `output_schema`, `timeout_seconds`, `max_llm_calls`.
  - `workflow_id` (string, optional) — Associate the agent with a workflow.
- **Response:** `201` — Agent object.

### Get agent by ID or name

- **GET** `/v1/{workspace_id}/agents/{agent_id}` → `200` and agent object, or `404`.
- **GET** `/v1/{workspace_id}/agents/by-name/{name}` → `200` and agent object, or `404`.

### Update agent

- **Method and path:** `PATCH /v1/{workspace_id}/agents/{agent_id}`
- **Request body (JSON):** Optional `name`, `spec`, `workflow_id`.
- **Response:** `200` — Updated agent object.

### Publish, archive, delete

- **POST** `/v1/{workspace_id}/agents/{agent_id}/publish` — Optional body `{ "message": "..." }`. **Response:** `200` — Updated agent.
- **POST** `/v1/{workspace_id}/agents/{agent_id}/archive` — **Response:** `200` — Archived agent.
- **DELETE** `/v1/{workspace_id}/agents/{agent_id}` — **Response:** `204` on success, or `400` if the agent is tied to a workflow (delete the workflow instead).

### Run agent

- **Method and path:** `POST /v1/{workspace_id}/agents/{agent_id}/run`
- **Request body (JSON):** `{ "input": "<text or message>" }` (required). Advanced integrations may send additional enriched fields; the common case is a single string `input`.
- **Response:** `200` — JSON with `status`, `output`, `error`, `duration_ms`, and optional `trace` (steps, LLM calls, tool calls).

```bash
curl -sS -X POST "https://cp.graphn.ai/v1/${WORKSPACE_ID}/agents/${AGENT_ID}/run" \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"input":"Hello"}'
```

### Dry-run agent (inline definition)

- **Method and path:** `POST /v1/{workspace_id}/agents/dry-run`
- **Request body (JSON):** An inline agent definition plus `input` (and any inline tool definitions). Useful for previewing an unsaved agent from the editor or a script.
- **Response:** `200` — Same result shape as **Run agent**.

---

## Functions

### List built-in functions

- **Method and path:** `GET /v1/{workspace_id}/functions/builtins`
- **Response:** `200` — JSON describing available built-in functions and metadata.

### List functions

- **Method and path:** `GET /v1/{workspace_id}/functions`
- **Query parameters (optional):** `limit` (default `100`, max `100`), `continue_token` (cursor for the next page), `type`, `workflow_id`.
- **Response:** `200` — JSON with `items`, `count`, and `continue_token` (present only when more results remain).

### Create function

- **Method and path:** `POST /v1/{workspace_id}/functions`
- **Request body (JSON):** Includes `name`, `type` (for example built-in vs custom), optional `files`, `description`, `builtin_name`, `workflow_id`, and related fields per your function type.
- **Response:** `201` — Function object.

### Get function by ID or name

- **GET** `/v1/{workspace_id}/functions/{function_id}`
- **GET** `/v1/{workspace_id}/functions/by-name/{name}`

### Update and delete

- **PATCH** `/v1/{workspace_id}/functions/{function_id}` — **Response:** `200`.
- **DELETE** `/v1/{workspace_id}/functions/{function_id}` — **Response:** `204`, or `400` if the function belongs to a workflow.

### Publish function

- **POST** `/v1/{workspace_id}/functions/{function_id}/publish` — Body may include `{ "message": "..." }`. **Response:** `200`.

### Test function

- **POST** `/v1/{workspace_id}/functions/{function_id}/test` — Body `{ "input": { ... } }` matching the function’s parameters. **Response:** `200` — Test result (success flag, output or error, timing).

### Dry-run function (unsaved code)

- **POST** `/v1/{workspace_id}/functions/dry-run` — Body includes `files` (map of filename to source), `input`, optional `timeout`. **Response:** `200` — Test result.

---

## MCP servers

### List MCP servers

- **Method and path:** `GET /v1/{workspace_id}/mcp-servers`
- **Query parameters (optional):** `limit` (default `100`, max `100`), `continue_token` (cursor for the next page), `type`, `workflow_id`.
- **Response:** `200` — JSON with `items`, `count`, and `continue_token` (present only when more results remain).

### Create MCP server

- **Method and path:** `POST /v1/{workspace_id}/mcp-servers`
- **Request body (JSON):** `name` (required), `type` (for example hosted or remote), `files` (for hosted), `endpoint_url` (for remote), optional `workflow_id`. You may also nest the same fields under a `spec` object; the service accepts both shapes.
- **Response:** `201` — Created server object.

### Get server by ID or name

- **GET** `/v1/{workspace_id}/mcp-servers/{server_id}`
- **GET** `/v1/{workspace_id}/mcp-servers/by-name/{name}`

### Update server

- **PATCH** `/v1/{workspace_id}/mcp-servers/{server_id}` — Optional `name`, `files`, `endpoint_url`, `message`, `workflow_id`. **Response:** `200`.

### Delete server

- **DELETE** `/v1/{workspace_id}/mcp-servers/{server_id}` — **Response:** `200` with `{ "deleted": true }`, or `400` if the server belongs to a workflow.

### Versions and publish

- **GET** `/v1/{workspace_id}/mcp-servers/{server_id}/versions` — List versions.
- **POST** `/v1/{workspace_id}/mcp-servers/{server_id}/versions` — Body `{ "files": { ... }, "message"?: "..." }` to save a new version.
- **POST** `/v1/{workspace_id}/mcp-servers/{server_id}/publish` — Optional `{ "message" }`. **Response:** `200`.

### Tools

- **GET** `/v1/{workspace_id}/mcp-servers/{server_id}/tools` — List cached tool definitions without executing server code.
- **POST** `/v1/{workspace_id}/mcp-servers/{server_id}/tools/{tool_name}/test` — Body `{ "input": { ... } }`. **Response:** `200` — Tool test result.
- **POST** `/v1/{workspace_id}/mcp-servers/{server_id}/refresh-tools` — Explicitly execute the saved server in an isolated sandbox to refresh its tools. Subject to sandbox admission controls. **Response:** `200` — Updated server.

### Discover tools from files

- **POST** `/v1/{workspace_id}/mcp-servers/discover-tools` — Explicitly execute the supplied files in an isolated sandbox to discover tools. Subject to sandbox admission controls. Body `{ "files": { "main.py": "..." } }`. **Response:** `200` — Discovered tools and optional error string.

### Dry-run MCP tool

- **POST** `/v1/{workspace_id}/mcp-servers/test-dry-run` — Body includes inline server/tool definitions for a quick test. **Response:** `200` — Test result.

---

## Imported models

Imported models register an external **OpenAI-compatible** endpoint (vLLM, Ollama, OpenAI, OpenRouter, etc.) as a selectable model. See [Models reference](./models.md#custom-model-import) for the connection-test and model-discovery helpers and full field descriptions.

### List imported models

- **Method and path:** `GET /v1/{workspace_id}/imported-models`
- **Query parameters (optional):** `limit`.
- **Response:** `200` — JSON with `items` and `total`.

### Create imported model

- **Method and path:** `POST /v1/{workspace_id}/imported-models`
- **Request body (JSON):** `name` (URL-friendly id, required), `endpoint`, `model_id`, optional `display_name`, `api_key_secret_id`, `type`, `capabilities`, `context_length`, `description`.
- **Response:** `201` — Created imported-model object.

### Get, update, delete

- **GET** `/v1/{workspace_id}/imported-models/{model_id}` — **Response:** `200`.
- **PATCH** `/v1/{workspace_id}/imported-models/{model_id}` — **Response:** `200`.
- **DELETE** `/v1/{workspace_id}/imported-models/{model_id}` — **Response:** `204`.

---

## Secrets

### List secrets

- **Method and path:** `GET /v1/{workspace_id}/secrets`
- **Response:** `200` — JSON with `secrets` (array of `{ id, name, workspace_id, value_preview, provider_id, field_name, created_at, updated_at }`) and `total`. Secret values are never returned in full; only previews.

### Create secret

- **Method and path:** `POST /v1/{workspace_id}/secrets`
- **Request body (JSON):** `name` (required, alphanumeric, hyphens, underscores), `value` (required), optional `provider_id`, `field_name`.
- **Response:** `201` — Secret metadata (no full value). `409` if the name already exists.

### Update secret

- **Method and path:** `PUT /v1/{workspace_id}/secrets/{secret_id}`
- **Request body (JSON):** `{ "value": "new-value" }`
- **Response:** `200` — Secret metadata.

### Delete secret

- **Method and path:** `DELETE /v1/{workspace_id}/secrets/{secret_id}`
- **Response:** `204` — No content.

```bash
curl -sS "https://cp.graphn.ai/v1/${WORKSPACE_ID}/secrets" \
  -H "Authorization: Bearer ${TOKEN}"
```

---

## Knowledge bases

Knowledge base routes are served under the workspace prefix. Typical operations:

- **GET** `/v1/{workspace_id}/knowledgebases` — List knowledge bases.
- **POST** `/v1/{workspace_id}/knowledgebases` — Create (`name`, `description`, optional fields).
- **GET** `/v1/{workspace_id}/knowledgebases/{kb_id}` — Get one.
- **PATCH** `/v1/{workspace_id}/knowledgebases/{kb_id}` — Update.
- **DELETE** `/v1/{workspace_id}/knowledgebases/{kb_id}` — **Permanent** delete (HTTP `204`). There is no soft-delete or restore. A successful delete purges all vectors and document metadata, removes ingest bookkeeping, and deletes the KB record. Cancellation of in-flight ingest and cleanup of media objects under the KB prefix are best-effort, so orphaned work or objects can remain if those dependencies are unavailable.
- **POST** `/v1/{workspace_id}/knowledgebases/batch/delete` — Body `{ "ids": ["kb_…", …] }` — permanently delete multiple KBs (same cascade; per-item success/failure).
- **GET** `/v1/{workspace_id}/knowledgebases/{kb_id}/stats` — Usage statistics.
- **GET** `/v1/{workspace_id}/knowledgebases/{kb_id}/documents` — List documents.
- **POST** `/v1/{workspace_id}/knowledgebases/{kb_id}/documents` — Upload document (`multipart/form-data` with a `file` field; optional `metadata` JSON).
- **DELETE** `/v1/{workspace_id}/knowledgebases/{kb_id}/documents/{document_id}` — Permanently remove a document and its vectors.
- **POST** `/v1/{workspace_id}/knowledgebases/{kb_id}/search` — Body `{ "query": "...", "top_k": 5, "rerank": true }` — Returns ranked chunks.

Other surfaces for the same permanent delete: UI (Knowledge Bases list/detail), CLI (`graphn kb delete <id> [--force]`), MCP (`graphn_kb_delete`), and workflow helpers (`await kb.delete(kb_id)`).

### Text embeddings

- **POST** `/v1/{workspace_id}/embed` — Body `{ "texts": ["..."], "normalize": true, "model": "BAAI/bge-m3" }` — Returns vectors and dimensions. `model` is optional and takes a knowledge-base embedding model ID from `GET /v1/knowledgebases/models` (for example `Qwen/Qwen3-VL-Embedding-8B` for 4,096-dim vectors), not the model alias; it defaults to BGE-M3.

Exact response fields for knowledge base and search endpoints follow the JSON returned by the service; list or get one resource in your workspace to inspect the shape.

---

## Storage

> **Note:** Object storage is served by the takao **storage service**, not graphn-cp. The web UI talks to it directly (via `VITE_STORAGE_URL`, or the `/storage` dev proxy in local dev). The paths below are graphn-cp’s REST overlay on `https://cp.graphn.ai`. The storage service’s S3-style root API is `https://storage.graphn.ai` and does not serve `/v1/{workspace_id}/storages`.

Object storage uses a workspace prefix similar to other resources.

### List stores

- **GET** `/v1/{workspace_id}/storages` — **Response:** `200` — List of stores with `items` and `total`.

### Create store

- **POST** `/v1/{workspace_id}/storages`
- **Body:** `{ "name": "lowercase-name-3-63-chars", "description": "" }` — `name` must match the documented pattern rules.
- **Response:** `201` — Store metadata.

### Get or delete store

- **GET** `/v1/{workspace_id}/storages/{store_name}` — Metadata. **Response:** `200`.
- **DELETE** `/v1/{workspace_id}/storages/{store_name}` — Query `hard_delete=true` for permanent removal. **Response:** `204`.

### Stats

- **GET** `/v1/{workspace_id}/storages/{store_name}/stats` — **Response:** `200` — Counts and sizes.

### Files in a store

- **GET** `/v1/{workspace_id}/storages/{store_name}/files` — Query: `prefix`, `delimiter`, `max_keys`, `continuation_token`.

- **POST** `/v1/{workspace_id}/storages/{store_name}/files` — `multipart/form-data` upload; optional query `path` for object key.

- **GET** `/v1/{workspace_id}/storages/{store_name}/files/{path}` — Download (path may contain slashes).

- **DELETE** `/v1/{workspace_id}/storages/{store_name}/files/{path}` — Delete object. **Response:** `204`.

- **POST** `/v1/{workspace_id}/storages/{store_name}/files/{path}/presign` — Query `expires_in` (seconds), `upload` (boolean). **Response:** `200` — Presigned URL payload.

```bash
curl -sS "https://cp.graphn.ai/v1/${WORKSPACE_ID}/storages" \
  -H "Authorization: Bearer ${TOKEN}"
```

---

## Workspace API keys

Manage keys from the app's **API keys** page, or via the endpoints below.

![The API keys page — create keys with the gn_ prefix](/docs/screenshot-api-keys.png)

### List API keys

- **GET** `/v1/{workspace_id}/api-keys`
- **Response:** `200` — JSON with `api_keys` (array of `{ key_id, workspace_id, description, created_at, expires_at }`).

### Create API key

- **POST** `/v1/{workspace_id}/api-keys`
- **Body:** `{ "description": "CI bot", "expires_at": "2026-12-31T00:00:00Z" }` — `expires_at` optional.
- **Response:** `200` — Includes the full `key` string **once** (save it immediately), plus `key_id`, `workspace_id`, `description`, `created_at`, `expires_at`.

### Delete API key

- **DELETE** `/v1/{workspace_id}/api-keys/{key_id}`
- **Response:** `204` — No content.

---

## Quick start

Try the API in four steps:

1. Create a workspace API key on the **API keys** page and copy `WORKSPACE_ID` from the workflow **API** tab.
2. **List workflows** and read `items[].id` for `WORKFLOW_ID`.
3. **Run** a workflow with `curl` using `POST /v1/{workspace_id}/workflows/{workflow_id}/run` and `{ "input": { ... } }`.
4. **List agents** with `GET /v1/{workspace_id}/agents`.

If any step returns `401`, refresh the token. If you see `403`, double-check that `{workspace_id}` in the URL matches the workspace the key belongs to.

---

## See also

- [Getting Started](./getting-started.md) — deploy and test your first workflow
- [DSL Reference](./dsl-reference.md) — the YAML format behind every workflow
- [Function SDK Reference](./sdk-reference.md) — writing Python functions called by workflows
- [Models Reference](./models.md) — import and manage models via the API
- [GraphN FAQ](/faq) — product and API answers, including authentication and execution modes
