> ## Documentation Index
> Fetch the complete documentation index at: https://docs.metabind.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Package

> Create a new package, publishing all draft and modified components

## Request Body

<ParamField body="version" type="string" required>
  Semantic version number (e.g., `1.0.0`, `2.1.0`)
</ParamField>

<ParamField body="metadata" type="object" required>
  <Expandable title="properties">
    <ParamField body="metadata.description" type="string" required>
      Package description
    </ParamField>

    <ParamField body="metadata.tags" type="string[]">
      Package categories
    </ParamField>
  </Expandable>
</ParamField>

### Example Request

```json theme={null}
{
  "version": "1.0.0",
  "metadata": {
    "description": "Initial release with core UI components",
    "tags": ["ui", "core"]
  }
}
```

<Warning>
  Creating a package will automatically publish all draft and modified components, assigning them new version numbers. This action cannot be undone.
</Warning>

## Response

Returns the created Package object along with validation results showing what changed.

```json theme={null}
{
  "package": {
    "id": "pkg123",
    "projectId": "proj123",
    "version": "1.0.0",
    "components": [
      {
        "id": "comp123",
        "name": "ProductCard",
        "type": "view",
        "version": 1
      },
      {
        "id": "comp124",
        "name": "ArticleLayout",
        "type": "layout",
        "version": 1
      }
    ],
    "assets": [...],
    "compiled": {...},
    "dependencies": [...],
    "metadata": {
      "author": "user123",
      "description": "Initial release with core UI components",
      "tags": ["ui", "core"]
    },
    "createdAt": "2024-03-20T10:00:00Z",
    "updatedAt": "2024-03-20T10:00:00Z"
  },
  "validation": {
    "componentChanges": {
      "added": ["comp123"],
      "updated": ["comp124", "comp125"],
      "deleted": []
    },
    "statusChanges": {
      "draft": ["comp123"],
      "modified": ["comp124"],
      "published": ["comp125"]
    },
    "versionIncrements": {
      "comp123": { "from": null, "to": 1 },
      "comp124": { "from": 2, "to": 3 }
    }
  }
}
```

## Error Responses

### Version Already Exists

```json theme={null}
{
  "error": {
    "code": "PACKAGE_VERSION_EXISTS",
    "message": "Package version 1.0.0 already exists"
  }
}
```

### No Components

```json theme={null}
{
  "error": {
    "code": "NO_COMPONENTS_TO_PACKAGE",
    "message": "Cannot create package: project contains no components. Create at least one component before creating a package."
  }
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/packages" \
    -H "Authorization: Bearer YOUR_JWT" \
    -H "Content-Type: application/json" \
    -d '{
      "version": "1.0.0",
      "metadata": {
        "description": "Initial release"
      }
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/packages',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        version: '1.0.0',
        metadata: {
          description: 'Initial release'
        }
      })
    }
  );

  const { package: pkg, validation } = await response.json();
  console.log(`Created package ${pkg.version} with ${pkg.components.length} components`);
  ```
</CodeGroup>
