Skip to main content
API Reference

Projects API

HTTP API reference for creating, listing, updating, and deleting projects -- the second level of CodeSpar's org -> project tenancy model.

1 min read · updated

Projects API

The Projects API manages the second level of CodeSpar's tenancy model: Organization -> Project. See the Projects concept for the full model.

Base URL: https://api.codespar.dev

All endpoints require authentication via Bearer token. See Authentication.

Project object

FieldTypeDescription
idstringProject ID in the form prj_<16chars>
org_idstringParent organization ID
namestringDisplay name (free-form)
slugstringURL-safe identifier, unique per organization
is_defaultbooleantrue for the org's default project (exactly one per org)
created_atstringISO 8601 timestamp

Slug rules

  • Lowercase alphanumeric characters plus _ and -
  • Max length: 64 characters
  • default is reserved (only the auto-created default project uses it)
  • Must be unique within the organization

Violations return slug_invalid, slug_reserved, or slug_conflict (see Errors).


GET /v1/projects

Lists all projects in the authenticated organization.

Auth required: Yes

Query parameters

ParameterTypeDefaultDescription
is_defaultboolean--Filter to only the default project (true) or non-default projects (false)
limitnumber50Results per page (max 100)
offsetnumber0Pagination offset

curl example

curl https://api.codespar.dev/v1/projects \
  -H "Authorization: Bearer csk_live_abc123..."

Response -- 200 OK

{
  "data": [
    {
      "id": "prj_a1b2c3d4e5f6g7h8",
      "org_id": "org_xyz789",
      "name": "Default",
      "slug": "default",
      "is_default": true,
      "created_at": "2026-04-01T10:00:00Z"
    },
    {
      "id": "prj_i9j0k1l2m3n4o5p6",
      "org_id": "org_xyz789",
      "name": "Staging",
      "slug": "staging",
      "is_default": false,
      "created_at": "2026-04-15T09:12:00Z"
    }
  ],
  "total": 2,
  "limit": 50,
  "offset": 0
}

GET /v1/projects/:id

Retrieves a single project by ID.

Auth required: Yes

curl example

curl https://api.codespar.dev/v1/projects/prj_a1b2c3d4e5f6g7h8 \
  -H "Authorization: Bearer csk_live_abc123..."

Response -- 200 OK

{
  "id": "prj_a1b2c3d4e5f6g7h8",
  "org_id": "org_xyz789",
  "name": "Default",
  "slug": "default",
  "is_default": true,
  "created_at": "2026-04-01T10:00:00Z"
}

POST /v1/projects

Creates a new project in the authenticated organization.

Auth required: Yes

Request body

FieldTypeRequiredDescription
namestringYesDisplay name
slugstringYesURL-safe identifier (see slug rules)

New projects are always created with is_default: false. To promote a project to default, use PATCH /v1/projects/:id with {"is_default": true}.

curl example

curl -X POST https://api.codespar.dev/v1/projects \
  -H "Authorization: Bearer csk_live_abc123..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production",
    "slug": "prod"
  }'

Response -- 201 Created

{
  "id": "prj_q7r8s9t0u1v2w3x4",
  "org_id": "org_xyz789",
  "name": "Production",
  "slug": "prod",
  "is_default": false,
  "created_at": "2026-04-20T14:22:00Z"
}

PATCH /v1/projects/:id

Updates a project's name, slug, or default status.

Auth required: Yes

Request body

FieldTypeRequiredDescription
namestringNoNew display name
slugstringNoNew slug (subject to slug rules)
is_defaultbooleanNoSet to true to promote this project to default. Atomic: the previous default is demoted in the same transaction.

is_default can only be set to true. You cannot un-set it directly -- to change the default, promote a different project instead. Sending {"is_default": false} on the current default project is a no-op or error (exact behavior: TODO -- confirm).

curl example -- promote to default

curl -X PATCH https://api.codespar.dev/v1/projects/prj_q7r8s9t0u1v2w3x4 \
  -H "Authorization: Bearer csk_live_abc123..." \
  -H "Content-Type: application/json" \
  -d '{"is_default": true}'

Response -- 200 OK

{
  "id": "prj_q7r8s9t0u1v2w3x4",
  "org_id": "org_xyz789",
  "name": "Production",
  "slug": "prod",
  "is_default": true,
  "created_at": "2026-04-20T14:22:00Z"
}

DELETE /v1/projects/:id

Deletes a project and all of its scoped resources (API keys, triggers, session history, connection records).

Auth required: Yes

Deletion cascades. There is no undo. Export audit logs first if you need to retain them.

curl example

curl -X DELETE https://api.codespar.dev/v1/projects/prj_q7r8s9t0u1v2w3x4 \
  -H "Authorization: Bearer csk_live_abc123..."

Response -- 200 OK

{
  "id": "prj_q7r8s9t0u1v2w3x4",
  "deleted": true
}

Deletion fails with cannot_delete_default or cannot_delete_last_project (see below).


Errors

All endpoints follow the standard error format:

{
  "error": "error_code",
  "message": "Human-readable error description.",
  "status": 400
}

Project-specific error codes

StatusError codeWhen
400slug_invalidSlug contains disallowed characters, exceeds 64 chars, or is empty
400slug_reservedSlug is default (reserved for the auto-created default project)
409slug_conflictAnother project in the organization already uses this slug
409cannot_delete_defaultDELETE on the default project. Promote another project first.
409cannot_delete_last_projectDELETE on the only remaining project. Every org must have at least one project.

Standard error codes

StatusError codeWhen
401unauthorizedInvalid or missing API key
403forbiddenAPI key lacks permission (e.g. a project-scoped key trying to manage a different project)
404not_foundProject ID does not exist or does not belong to the authenticated organization
429rate_limitedToo many requests
500internal_errorServer error. Retry with exponential backoff.

Next steps

Last updated on