# Using the CardSight AI API - Set Search API

## Overview
List and search for card sets across all releases. Sets represent collections within releases like "Base Set", "Rookie Autographs", etc.

## Endpoint Details
- **Method**: GET
- **URL**: `https://api.cardsight.ai/v1/catalog/sets`
- **Authentication**: API Key required (X-Api-Key header)

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| releaseId | UUID | No | Filter sets to a specific release |
| name | string | No | Search by set name (partial match, case-insensitive) |
| year | string | No | Filter by exact release year |
| min_year | string | No | Filter sets from this year onwards |
| max_year | string | No | Filter sets up to this year |
| manufacturer | string | No | Filter by manufacturer name or UUID |
| is_identifiable | string | No | Filter by AI identification support ("true" returns only identifiable sets, "false" returns only non-identifiable sets) |
| take | integer | No | Results per page (1-100, default: 20) |
| skip | integer | No | Number of results to skip for pagination |
| sort | string | No | Sort by: name, year |
| order | string | No | Sort order: asc, desc (default: asc) |

## Using the CardSight AI SDK (Recommended)

### Node.js / TypeScript
```typescript
import { CardSightAI } from 'cardsightai'

const client = new CardSightAI({ apiKey: 'your-api-key' })

const response = await client.catalog.sets.list({
  name: 'Base',
  year: '2023',
  take: 20
})

// Always check for errors
if (response.error) {
  console.error('Error:', response.error)
} else {
  console.log(`Found ${response.data.total_count} sets`)

  for (const set of response.data.sets) {
    console.log(`${set.name} - ${set.releaseName} (${set.releaseYear})`)
    console.log(`  Cards: ${set.cardCount}, Parallels: ${set.parallelCount}`)
  }
}
```

### Python
```python
from cardsightai import CardSightAI

client = CardSightAI(api_key='your-api-key')

response = client.catalog.sets.list(name='Base', year='2023', take=20)

print(f"Found {response.total_count} sets")
for set in response.sets:
    print(f"{set.name} - {set.card_count} cards")
```

## Direct API Call (cURL)
```bash
curl -X GET "https://api.cardsight.ai/v1/catalog/sets?name=Base&year=2023&take=20" \
  -H "X-Api-Key: your-api-key"
```

## Example Response
```json
{
  "sets": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Base Set",
      "description": "220-card base set",
      "cardCount": 220,
      "parallelCount": 15,
      "releaseId": "550e8400-e29b-41d4-a716-446655440001",
      "releaseName": "Topps Chrome Baseball",
      "releaseYear": "2023",
      "is_identifiable": true
    }
  ],
  "total_count": 1,
  "skip": 0,
  "take": 20
}
```

## Response Fields

| Field | Type | Description |
|-------|------|-------------|
| sets | array | Array of set objects |
| total_count | number | Total number of matching sets |
| skip | number | Number of results skipped |
| take | number | Number of results returned |

### Set Object

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| id | UUID | Yes | Unique set identifier |
| name | string | Yes | Name of the set |
| description | string | No | Additional details about the set |
| cardCount | number | Yes | Number of base cards in the set |
| parallelCount | number | Yes | Number of parallel types |
| releaseId | UUID | Yes | UUID of the parent release |
| releaseName | string | Yes | Name of the release |
| releaseYear | string | Yes | Year of the release |
| is_identifiable | boolean | Yes | Whether cards in this set can be identified by the CardSight AI identification service |

## Common Use Cases
- Find all sets with a specific name across releases
- Search for sets within a year range
- Browse sets by manufacturer
- Get set IDs for card queries

## Tips for AI Assistants
- **Working with IDs:** These UUIDs (`releaseId`, `setId`, and card `id`) let you look up catalog entities and chain calls together. Caching them briefly to fulfill a user's request is expected and fine — it's why the image and other free endpoints exist. If you need to save cards for the long term, add them to a **list or collection**: those are your own stable resources, purpose-built for holding cards. If you need a bulk or offline copy of catalog data, reach out to us at `support@cardsight.ai` so we can help with your use case.
- The SDK returns `{ data, error }` - always check for errors first
- Use `releaseId` to get all sets within a specific release
- `cardCount` and `parallelCount` help estimate set size
- Use Set Details endpoint to get full parallel information
- Use `is_identifiable` to filter sets that support AI card identification
- When `is_identifiable` is true, cards in that set can be identified via the `/v1/identify/card` endpoint
