---
title: "How do I list and search optimizations using the REST API?"
answer: "Query the `GET /api/v2/optimizations` endpoint with your workspace private API key to list and search Coolhand prompt and workflow optimizations. Filter results by template, workload, status, type, or category, perform substring searches across analysis and plan text, inspect contextual assignment and completion fields, and paginate using response headers."
category: "Logs \u0026 API"
tags: ["optimizations","rest-api","query-filters","assignments","reason-codes"]
published: 2026-11-28T18:55:53Z
updated: 2026-12-03T22:09:50Z
canonical_url: https://coolhandlabs.com/help/list-and-search-optimizations-api
index_url: https://coolhandlabs.com/help.md
---

# How do I list and search optimizations using the REST API?

Query the `GET /api/v2/optimizations` endpoint with your workspace private API key to list and search Coolhand prompt and workflow optimizations. Filter results by template, workload, status, type, or category, perform substring searches across analysis and plan text, inspect contextual assignment and completion fields, and paginate using response headers.

## What is an optimization?

Coolhand continuously evaluates prompt templates, request logs, and feedback to identify ways to make your AI workloads cheaper, faster, and more reliable. Each recommendation—whether it proposes prompt restructuring, error mitigation, model migrations, or cost reduction—is captured as an optimization.

You can view optimizations in the Coolhand web dashboard, but you can also query them programmatically using the v2 REST API to build custom dashboards, trigger CI/CD alerts, or automate triage workflows.

To list and search optimizations, follow these steps:

1. Authenticate and query the endpoint.
2. Apply scope, status, type, or category filters.
3. Search optimization text across diagnostics and plans.
4. Sort your results.
5. Paginate through results using response headers.

## Step 1: Authenticate and query the endpoint

To list your optimizations, send a `GET` request to `/api/v2/optimizations`.

Authentication requires your workspace's **private API key**. Public API keys used for client-side logging are rejected with a `401 Unauthorized` status. Pass your private key in the `Authorization` header as a Bearer token or in the `X-API-Key` header:

```bash
curl -H "Authorization: Bearer $COOLHAND_PRIVATE_API_KEY" \
  "https://coolhandlabs.com/api/v2/optimizations"
```

The endpoint returns a bare JSON array of optimization objects sorted by impact (highest impact first) by default.

```json
[
  {
    "id": "opt_9f8a1c",
    "title": "Migrate invoice extraction prompt to structured output schema",
    "status": "proposed",
    "optimization_type": "improvement",
    "category": "quality_improvement",
    "complexity": "low_complexity",
    "impact": "high_impact",
    "client_name": "Acme Corp",
    "template_id": "tmpl_3b2a1",
    "template_name": "Extract Invoice Data",
    "workload_name": "Document Processing",
    "created_at": "2025-02-14T18:22:10Z"
  }
]
```

## Step 2: Apply query filters

You can narrow your query using several query parameters:

### Scope filters

Filter by specific resources associated with your workspace:

*   `optimization_id`: Retrieve a single optimization by its ID.
*   `template_id`: Restrict results to optimizations linked to a specific prompt template.
*   `workload_id`: Restrict results to optimizations on templates belonging to a specific [workload](https://coolhandlabs.com/help/what-is-a-workload.md).

If you supply an ID filter that does not exist or belongs to another workspace, the API returns `404 Not Found`.

### Status filter

Use `status` to filter by the lifecycle stage of an optimization:

*   `proposed`: Active recommendations ready for review and implementation.
*   `draft`: Early-stage or candidate recommendations being refined.
*   `queued`: Recommendations parked awaiting client review capacity or quota limits.
*   `completed`: Recommendations that were applied, merged, or marked done.
*   `dismissed`: Recommendations that were rejected or closed without implementation.

```bash
curl -H "Authorization: Bearer $COOLHAND_PRIVATE_API_KEY" \
  "https://coolhandlabs.com/api/v2/optimizations?status=proposed"
```

### Type filter

Use `optimization_type` to filter by the underlying mechanism:

*   `improvement`: Refinements to an existing prompt template.
*   `suggestion`: Recommendations for new prompt patterns or task architectures.
*   `setup`: Configuration, tooling, or model setup suggestions.
*   `error_fix`: Targeted resolutions for recurring request errors.
*   `operational`: Reliability and hygiene adjustments.
*   `wildcard_report`: Findings surfaced through triage sweeps.

### Category filter

Use `category` to filter by the optimization objective:

*   `cost_reduction`: Lowering token usage, caching prompts, or reducing model spend.
*   `quality_improvement`: Increasing output accuracy, formatting compliance, or user sentiment.
*   `maintenance`: Upkeep, schema hygiene, and prompt cleanliness.
*   `feature_suggestion`: Adopting new model capabilities.
*   `best_practices`: Aligning prompts with provider recommendations.
*   `model_deprecation`: Replacing retiring models or responding to pricing revisions.
*   `system_one_migration`: Transitioning tasks to fast deterministic models.
*   `task_decomposition`: Decomposing monolithic prompts into staged multi-step workflows (see [task decomposition optimizations](https://coolhandlabs.com/help/what-is-a-task-decomposition-optimization.md)).
*   `runtime_tool_install`: Adding runtime tools or packages.

### Recency filter

Use `days_back` to limit results to optimizations created (or reopened) within a given number of days. The value must be a positive integer:

```bash
curl -H "Authorization: Bearer $COOLHAND_PRIVATE_API_KEY" \
  "https://coolhandlabs.com/api/v2/optimizations?days_back=14"
```

## Step 3: Search optimization text

Use the `search` parameter to run a case-insensitive substring search across optimization titles, analyses, and implementation plans:

```bash
curl -H "Authorization: Bearer $COOLHAND_PRIVATE_API_KEY" \
  "https://coolhandlabs.com/api/v2/optimizations?search=timeout"
```

This searches across:
*   The headline `title`.
*   The detailed diagnostic `analysis` explaining why the optimization was generated.
*   The proposed step-by-step `plan`.

## Step 4: Sort your results

Use the `sort_by` parameter to control result order:

*   `impact_desc` (default): Orders from highest impact to lowest impact (`high_impact`, `medium_impact`, `low_impact`).
*   `complexity_asc`: Orders from simplest to most complex (`low_complexity`, `medium_complexity`, `high_complexity`).
*   `created_at_desc`: Orders newest optimizations first.

```bash
curl -H "Authorization: Bearer $COOLHAND_PRIVATE_API_KEY" \
  "https://coolhandlabs.com/api/v2/optimizations?sort_by=complexity_asc"
```

## Step 5: Paginate using response headers

Results are paginated. You can navigate pages using:

*   `page`: Page number to fetch (starts at 1).
*   `per` (or `per_page`): Records per page (default is 25, maximum is 100).

Because the response body is a bare JSON array, pagination metadata is delivered in HTTP response headers:

*   `X-Page`: The current page number.
*   `X-Per-Page`: The number of records requested per page.
*   `X-Total-Count`: Total number of matching records across all pages.
*   `X-Total-Pages`: Total number of pages available.

To inspect pagination headers with `curl`, use the `-i` flag:

```bash
curl -i -H "Authorization: Bearer $COOLHAND_PRIVATE_API_KEY" \
  "https://coolhandlabs.com/api/v2/optimizations?page=1&per=10"
```

Example response headers:

```http
HTTP/2 200
x-page: 1
x-per-page: 10
x-total-count: 42
x-total-pages: 5
content-type: application/json; charset=utf-8
```

## Contextual fields

In addition to standard properties (`id`, `title`, `status`, `optimization_type`, `category`, `complexity`, `impact`, `template_id`, `template_name`, `workload_name`, `created_at`), individual optimizations include contextual fields based on their lifecycle status. These fields are omitted entirely when they do not apply:

### Assignment fields (claimed optimizations)

When a developer or coding agent claims a proposed optimization, the record includes an `assignment` object:

*   `assignment.assigned_to`: An actor object identifying who claimed the task:
    *   `name`: The display name of the user or reviewer.
    *   `type`: Either `"user"` for team members in your workspace or `"coolhand"` for Coolhand reviewers or automated agents.
*   `assignment.assigned_at`: An ISO 8601 UTC timestamp recording when the optimization was claimed.
*   `assignment.days_ago`: An integer showing the number of full days elapsed since the assignment was recorded.
*   `assignment.stale`: A boolean set to `true` when the assignment has remained open and unresolved for seven or more days. This highlights tasks that may have stalled or been abandoned.
*   `assignment.work_item_url`: Present when a URL was provided during assignment, linking to the tracking issue or pull request in progress.

Example assigned optimization:

```json
{
  "id": "opt_2c9d1e",
  "title": "Add prompt caching to support documentation template",
  "status": "proposed",
  "optimization_type": "improvement",
  "category": "cost_reduction",
  "complexity": "low_complexity",
  "impact": "high_impact",
  "client_name": "Acme Corp",
  "template_id": "tmpl_9c1f2",
  "template_name": "Support Bot Docs",
  "workload_name": "Customer Support",
  "created_at": "2025-02-10T14:00:00Z",
  "assignment": {
    "assigned_to": {
      "name": "Jane Doe",
      "type": "user"
    },
    "assigned_at": "2025-02-12T10:30:00Z",
    "days_ago": 2,
    "stale": false,
    "work_item_url": "https://github.com/acme/support-bot"
  }
}
```

### Completion fields (completed optimizations)

When an optimization reaches the `completed` status, Coolhand records what was implemented and who verified it:

*   `completion_note`: A free-text description (up to 5,000 characters) detailing what changes were made and where they were applied.
*   `completed_by`: Present when completion attribution exists, returning an actor object with `name` and `type` (`"user"` or `"coolhand"`).
*   `work_item_url`: The HTTP(S) URL of the merged pull request or issue tracking the completed implementation.

Example completed optimization:

```json
{
  "id": "opt_4a8b2d",
  "title": "Adopt prompt caching for reference documentation",
  "status": "completed",
  "optimization_type": "improvement",
  "category": "cost_reduction",
  "complexity": "low_complexity",
  "impact": "high_impact",
  "client_name": "Acme Corp",
  "template_id": "tmpl_9c1f2",
  "template_name": "API Assistant",
  "workload_name": "Support Bot",
  "created_at": "2025-01-20T10:15:00Z",
  "completion_note": "Added cache_control ephemeral breakpoint on reference documentation block.",
  "completed_by": {
    "name": "Alex Mercer",
    "type": "user"
  },
  "work_item_url": "https://github.com/acme/support-bot"
}
```

### Dismissal and reopening fields

When an optimization is dismissed or revived, Coolhand records attribution and reasoning:

*   `reason_code`: Present on dismissed optimizations, classifying why the recommendation was closed. The value is one of:
    *   `not_relevant`: The recommendation does not fit the architecture or requirements.
    *   `already_done`: The proposed changes were already implemented independently.
    *   `wrong_analysis`: The underlying diagnostic assumptions or conclusions were incorrect.
    *   `insufficient_context`: There is not enough log history or feedback to safely evaluate the recommendation.
    *   `too_risky`: The proposed modification introduces unacceptable operational or behavioral risk.
    *   `not_now`: The recommendation is acknowledged as valid but postponed for later prioritization.
    *   `other`: An unclassified or bespoke dismissal rationale.
*   `dismissal_explanation`: An optional free-text explanation describing why the recommendation was closed.
*   `dismissed_by`: Present when dismissal attribution exists, returning an actor object with `name` and `type` (`"user"` or `"coolhand"`).
*   `reopen_explanation`: Present if an optimization was previously dismissed and subsequently reopened for review.
*   `reopened_at`: An ISO 8601 UTC timestamp recording when the recommendation was reopened.

Example dismissed optimization:

```json
{
  "id": "opt_7d3e5f",
  "title": "Decompose extraction prompt into classifier and parser",
  "status": "dismissed",
  "optimization_type": "improvement",
  "category": "task_decomposition",
  "complexity": "medium_complexity",
  "impact": "medium_impact",
  "client_name": "Acme Corp",
  "template_id": "tmpl_3b2a1",
  "template_name": "Extract Invoice Data",
  "workload_name": "Document Processing",
  "created_at": "2025-02-01T09:00:00Z",
  "reason_code": "too_risky",
  "dismissal_explanation": "Splitting the step would add latency to our synchronous customer-facing API.",
  "dismissed_by": {
    "name": "Jane Doe",
    "type": "user"
  }
}
```

### Proposal and review annotations

*   `optimization_thesis`: Present when the optimization includes a high-level thesis describing the core hypothesis behind the recommendation.
*   `pr_number` and `pr_url`: Present when an automated or linked pull request / merge request has been generated for the optimization.
*   `warnings`: Present when an item requires reviewer attention, such as when supporting feedback or logs were linked across different workloads. Each entry contains `kind`, `message`, `reason`, and associated resource identifier arrays.

## Error handling

*   `401 Unauthorized`: Returned when the private API key is missing or invalid, or if a public API key was provided.
*   `404 Not Found`: Returned when an ID filter (`optimization_id`, `template_id`, or `workload_id`) does not match any record belonging to your workspace.
*   `422 Unprocessable Content`: Returned when a query parameter fails validation, such as an unrecognized value for `status`, `optimization_type`, `category`, or `sort_by`, or a non-positive integer for `days_back`.
*   `504 Gateway Timeout`: Returned if the database query exceeds the query statement timeout. If you encounter timeouts, narrow your filters (for example, by adding `days_back` or filtering to a specific `workload_id`) or decrease `per`.

---

Related:
- [How do I claim, complete, or dismiss an optimization using the REST API or MCP?](https://coolhandlabs.com/help/how-do-i-claim-complete-or-dismiss-an-optimization.md)
- [How do I create or update a workload using an external key?](https://coolhandlabs.com/help/how-do-i-create-or-update-a-workload-using-an-external-key.md)
- [How do open-weights labels and license filters work in the model catalog?](https://coolhandlabs.com/help/how-do-open-weights-labels-and-license-filters-work.md)
- [What do the Development, Maturing, Stable, and Dormant labels on a workload mean?](https://coolhandlabs.com/help/workload-maturity.md)

[← All help articles](https://coolhandlabs.com/help.md) · [Logs & API](https://coolhandlabs.com/help/category/logs-and-api.md)
