# Pipeline API

Use the Pipeline REST API to run the brand ingestion and enrichment processes: 

 - **Brand ingestion** analyzes documents uploaded to your [brand kit](https://doc.sitecore.com/stream/en/users/sitecore-stream/brand-kits.html) using the [Documents REST API](https://api-docs.sitecore.com/ai-skills/ai-document-management-rest-api). The system analyzes each document page by page, extracts brand information, and breaks it down into smaller pieces called *knowledge chunks*. These chunks are then organized, vectorized, and stored as your [brand knowledge](https://doc.sitecore.com/stream/en/users/sitecore-stream/brand-knowledge.html).

 - **Enrichment** uses existing brand knowledge to automatically populate or update content in brand kit sections and subsections. You don’t need to reingest brand documents to enrich content. 

 This REST API lets you interact with:

 - The pipeline object. A pipeline is a structured process that performs a series of tasks automatically. In this context, pipelines are used to run the [brand ingestion](https://doc.sitecore.com/stream/en/users/sitecore-stream/brand-knowledge.html) and [ enrichment](https://doc.sitecore.com/stream/en/users/sitecore-stream/review-or-refine-a-brand-kit-section.html#enrich-content-using-brand-knowledge) processes.

 The resulting brand knowledge and enriched content are made available to Sitecore copilots and other AI agents enabling them to generate consistent, brand-aligned output.

Note the following:

 - To use this REST API, you must authenticate your API requests.

 - All API requests are made in your production environment.

For more information, see the [official Sitecore documentation](https://doc.sitecore.com/).

# Authorization
The Pipeline REST API uses the OAuth 2.0 standard with [JSON web tokens](https://doc.sitecore.com/stream/en/users/sitecore-stream/generate-a-json-web-token--jwt-.html) to authorize REST API requests.
### Create Client ID and Client Secret
  1. In the Sitecore Cloud Portal, open Stream.
  2. Click **Admin** > **AI APIs keys** > **Create credential**.
  3. In the **​Create New Client​​** dialog, enter a name and description for the client. Then click **Create**. The ​Client ID and Client Secret​​ display.
  4. Copy the Client ID and Client Secret because you won't be able to view them again in Stream. You'll use them to request an access token.

### Request an access token
Run the following cURL command to request an access token. Replace the placeholder values with your Client ID and Client Secret.
```curl
  curl -X POST 'https://auth.sitecorecloud.io/oauth/token' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'client_id={YOUR_API_KEY}' \
  --data-urlencode 'client_secret={YOUR_API_SECRET}' \
  --data-urlencode 'grant_type=client_credentials' \
  --data-urlencode 'audience=https://api.sitecorecloud.io'
```
In the response, the `access_token` key contains the access token:
```json
  {
    "access_token": "{YOUR_ACCESS_TOKEN}",
    "scope": "ai.org.brd:w ai.org.brd:r ai.org.docs:w ai.org.docs:r ai.org:admin",
    "expires_in": 86400,
    "token_type": "Bearer"
  }
```
Access tokens expire in 24 hours. If your requests unexpectedly return a response with status `401 Unauthorized`, request a new access token by repeating this `POST` request.

We recommend that you cache the access token for 24 hours to avoid repeating this `POST` request while the access token is still valid.
### Include the access token in the request header
You can now start making REST API requests. You must include the access token in the request header of every request. For example:

  ```curl
  curl -X GET '{YOUR_BASE_URL}/v2/...' \
  -H 'Authorization: Bearer {YOUR_ACCESS_TOKEN}' \
  -H 'Accept: application/json'
  ```


Version: 0.1.0
License: Closed source
Metadata:
  - product: AI skills

## Servers

Production server
```
https://edge-platform.sitecorecloud.io/stream/ai-pipeline-api
```

Production server
```
https://edge-platform.sitecorecloud.io/ai/ai-pipeline-api
```

## Security

### HTTPBearer

Type: http
Scheme: bearer
Bearer Format: JWT

## Download OpenAPI description

[Pipeline API](https://api-docs.sitecore.com/_bundle/ai-skills/ai-pipeline-rest-api/index.yaml)

## Pipeline

The Pipeline API lets you run the  brand ingestion  process to analyze uploaded brand documents, break them into  knowledge chunks, and store them as brand knowledge. It also supports the enrichment process, which uses brand knowledge to populate brand kit sections and subsections.

### Create a pipeline run for brand ingestion

 - [POST /api/data/v1/organizations/{organizationId}/pipeline/BrandIngestionPipeline](https://api-docs.sitecore.com/ai-skills/ai-pipeline-rest-api/pipeline/create_pipeline_run_brand_ingestion_api_data_v1_organizations__organizationid__pipeline_brandingestionpipeline_post.md): Creates a new pipeline to run the brand ingestion process. Through this process, brand documents uploaded to a brand kit are processed, analyzed, and chunked into knowledge pieces to create brand knowledge.

To use this endpoint, make sure to upload and process at least one document before running the brand ingestion pipeline.

The brand ingestion process might take a few minutes depending on the file size.

### Create a pipeline run for enrichment

 - [POST /api/data/v1/organizations/{organizationId}/pipeline/EnrichSectionsPipeline](https://api-docs.sitecore.com/ai-skills/ai-pipeline-rest-api/pipeline/create_pipeline_run_enrich_sections_api_data_v1_organizations__organizationid__pipeline_enrichsectionspipeline_post.md): Creates a new pipeline to run the enrichment process. This pipeline automatically retrieves information from your existing brand knowledge to generate or update the content of your brand kit sections and subsections.

To use this endpoint, make sure to upload and process at least one document before enriching the brand kit. If no brand knowledge is available, enrichment won’t run.

 Additionally, if the subsection you want to enrich is marked as non AI editable, the content will not be modified.

