Skip to main content

How do I create or update a workload using an external key?

Last updated 6 min read

To create or update a workload using an external key, send a PUT request to `/api/v2/workloads/by_key/{external_key}` with your private API key in the `X-API-Key` or `Authorization: Bearer` header. Pass optional `name`, `description`, and `reporter` fields in the JSON body. Coolhand returns 201 for new workloads and 200 for updates.

A workload in Coolhand groups related prompt templates belonging to a single task, feature, or AI agent (see What is a workload?). While you can create workloads through the dashboard or let them be created on the fly during log ingestion, you can also manage them programmatically using stable, user-defined external keys.

When to use external keys for workloads

Using external keys is recommended when you want to:

  • Manage workloads as code: Provision and configure workloads automatically within CI/CD pipelines, configuration management, or deployment scripts.
  • Maintain stable identifiers across renames: The external key remains fixed once assigned. You can freely change the workload's display name or description without breaking any integrations that reference the key.
  • Declare workloads in log ingestion: When sending logs via POST /api/v2/llm_request_logs, you can specify declared.workload.key. The incoming log links directly to your workload even if the dashboard display name has changed.
  • Reference workloads when creating templates: When creating declared prompt templates via PUT /api/v2/llm_request_templates/by_key/{external_key} (see How do I create or update a template using an external key?), you can pass workload_key to attach the template directly to your workload.

Steps to create or update a workload

  1. Choose an external key: Select a stable, unique identifier up to 255 characters for your workload (such as support/tier-1-triage or billing:invoices).
  2. Set up authentication: Obtain your Coolhand private API key (ch_priv_...) and pass it in the X-API-Key or Authorization: Bearer header.
  3. Send the PUT request: Send a PUT request to /api/v2/workloads/by_key/{external_key}, optionally including name, description, and reporter in the JSON body.
  4. Check the response status: Verify that Coolhand returns 201 Created for a newly created workload or 200 OK for an updated existing workload.
  5. Link logs and templates: Use declared.workload.key in POST /api/v2/llm_request_logs to associate logs, or pass workload_key when creating declared templates via PUT /api/v2/llm_request_templates/by_key/{external_key}.

Authentication requirements

This endpoint requires your private API key (ch_priv_...). The public API key used in client-side SDK setups cannot write to workloads.

Authenticate by passing your private key in either the X-API-Key header or as a bearer token in the Authorization header:

X-API-Key: ch_priv_your_private_api_key

or

Authorization: Bearer ch_priv_your_private_api_key

Sending a public API key or an invalid key returns a 401 Unauthorized response.

Request format

Send a PUT request to /api/v2/workloads/by_key/{external_key}:

PUT /api/v2/workloads/by_key/{external_key}
Content-Type: application/json

Path parameters

  • external_key (required, string): A stable identifier of your choosing, up to 255 characters. The key may contain alphanumeric characters, hyphens, underscores, colons, and forward slashes (for example, customer-support/triage-agent or billing:invoices).

Request body

The JSON request body accepts the following optional fields:

  • name (string, optional): The human-readable display name for the workload. When creating a workload, if you omit name, it defaults to the value of external_key.
  • description (string, optional): A text summary describing the agent or capability this workload represents.
  • reporter (string, optional): An identifier marking where the workload configuration originated, such as a deployment service, tool, or SDK name (e.g., support-service or squishling).

Response status codes and name collision handling

The endpoint behaves as an idempotent upsert:

  • 201 Created: Returned when no workload with the specified external_key exists yet, and a new workload is created.
  • 200 OK: Returned when a workload with the specified external_key already exists, and its display name, description, or reporter attributes are updated.
  • 401 Unauthorized: Returned when the request is missing an API key or uses a public API key.
  • 422 Unprocessable Entity: Returned when input validation fails, such as an invalid external_key format or an invalid display name.

Name collisions

Coolhand handles display name collisions differently depending on whether you are creating or updating:

  • On creation: If another workload in your account already uses the requested name, Coolhand automatically appends a numeric suffix (such as "Customer Support (2)") to avoid conflicts while still creating the workload.
  • On update: If you update an existing workload and attempt to change its name to a name already held by another workload or a reserved system name, the request fails with 422 Unprocessable Entity.

Example: Creating a workload

Here is an example creating a new workload with the key support/tier-1-triage:

curl -X PUT \
  https://api.coolhandlabs.com/api/v2/workloads/by_key/support/tier-1-triage \
  -H "X-API-Key: $COOLHAND_PRIVATE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Customer Support Triage",
    "description": "Classifies incoming customer tickets and routes them to specialist agents.",
    "reporter": "support-deploy-pipeline"
  }'

Response (201 Created)

{
  "id": "wkld_7a8b9c0d",
  "name": "Customer Support Triage",
  "description": "Classifies incoming customer tickets and routes them to specialist agents.",
  "external_key": "support/tier-1-triage",
  "reporter": "support-deploy-pipeline",
  "archived": false,
  "system": false,
  "merged": false,
  "maturity": null,
  "maturity_override": null,
  "archive_suggested": false,
  "template_count": 0,
  "draft_template_count": 0,
  "log_count": 0,
  "last_activity": null
}

Example: Updating an existing workload

To update the display name or description of an existing workload, send a PUT request with the same external_key:

curl -X PUT \
  https://api.coolhandlabs.com/api/v2/workloads/by_key/support/tier-1-triage \
  -H "X-API-Key: $COOLHAND_PRIVATE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Customer Support Triage & Routing",
    "description": "Classifies incoming tickets, extracts urgency, and routes them to agents."
  }'

Response (200 OK)

{
  "id": "wkld_7a8b9c0d",
  "name": "Customer Support Triage & Routing",
  "description": "Classifies incoming tickets, extracts urgency, and routes them to agents.",
  "external_key": "support/tier-1-triage",
  "reporter": "support-deploy-pipeline",
  "archived": false,
  "system": false,
  "merged": false,
  "maturity": null,
  "maturity_override": null,
  "archive_suggested": false,
  "template_count": 0,
  "draft_template_count": 0,
  "log_count": 0,
  "last_activity": null
}

Associating logs with a workload by key

Once a workload has an external key, you can link incoming LLM logs to it directly. In your POST /api/v2/llm_request_logs payload, pass the key inside declared.workload.key:

{
  "llm_request_log": {
    "raw_request": {
      "model": "gpt-4o",
      "messages": [
        { "role": "user", "content": "Categorize this support ticket: ..." }
      ]
    },
    "declared": {
      "workload": {
        "key": "support/tier-1-triage"
      }
    }
  }
}

Because the association relies on the fixed external_key, future changes to the workload's display name will not interrupt log routing.

Related articles