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

# Create a collection

> This operation creates a Pinecone collection.

Serverless indexes do not support collections.


<RequestExample>
  ```python Python theme={null}
  # pip install "pinecone[grpc]"
  from pinecone.grpc import PineconeGRPC as Pinecone

  pc = Pinecone(api_key="API_KEY")
  pc.create_collection("example-collection", "docs-example")
  ```

  ```javascript JavaScript theme={null}
  // npm install @pinecone-database/pinecone
  import { Pinecone } from '@pinecone-database/pinecone'

  const pc = new Pinecone({
    apiKey: 'YOUR_API_KEY'
  });

  await pc.createCollection({
    name: "example-collection",
    source: "docs-example",
  });
  ```

  ```java Java theme={null}
  import io.pinecone.clients.Pinecone;

  public class CreateCollectionExample {
      public static void main(String[] args) {
          Pinecone pc = new Pinecone.Builder("YOUR_API_KEY").build();

          pc.createCollection("example-collection", "docs-example");
      }
  }
  ```

  ```shell curl theme={null}
  PINECONE_API_KEY="YOUR_API_KEY"

  curl -s "https://api.pinecone.io/collections" \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    -H "Api-Key: $PINECONE_API_KEY" \
    -H "X-Pinecone-Api-Version: 2024-04" \
    -d '{
          "name": "example-collection",
          "source": "docs-example"
    }'
  ```
</RequestExample>


## OpenAPI

````yaml https://raw.githubusercontent.com/pinecone-io/pinecone-api/refs/heads/main/2024-04/control_2024-04.oas.yaml post /collections
openapi: 3.0.3
info:
  title: Pinecone Control Plane API
  description: >-
    Pinecone is a vector database that makes it easy to search and retrieve
    billions of high-dimensional vectors.
  version: 2024-04
  contact:
    name: Pinecone Support
    url: https://support.pinecone.io
    email: support@pinecone.io
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
servers:
  - url: https://api.pinecone.io
    description: Production API endpoints
security:
  - ApiKeyAuth: []
tags:
  - name: Manage Indexes
    description: Actions that manage indexes
externalDocs:
  description: More Pinecone.io API docs
  url: https://docs.pinecone.io/introduction
paths:
  /collections:
    servers:
      - url: https://api.pinecone.io
    post:
      tags:
        - Manage Indexes
      summary: Create a collection
      description: |
        This operation creates a Pinecone collection.

        Serverless indexes do not support collections.
      operationId: create_collection
      requestBody:
        description: The desired configuration for the collection.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCollectionRequest'
            examples:
              creating-collection:
                summary: Creating a collection
                value:
                  name: example-collection
                  source: example-source-index
      responses:
        '201':
          description: The collection has been successfully created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CollectionModel'
        '400':
          $ref: '#/components/responses/400BadRequest'
        '401':
          $ref: '#/components/responses/401Unauthorized'
        '403':
          $ref: '#/components/responses/403CollectionsQuotaExceeded'
        '409':
          description: Collection of given name already exists.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                collection-name-already-exists:
                  summary: Collection name needs to be unique.
                  value:
                    status: 409
                    error:
                      code: ALREADY_EXISTS
                      message: Resource already exists.
        '422':
          $ref: '#/components/responses/422UnprocessableEntity'
        '500':
          $ref: '#/components/responses/500InternalServerError'
components:
  schemas:
    CreateCollectionRequest:
      type: object
      description: The configuration needed to create a Pinecone collection.
      required:
        - name
        - source
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 45
          description: >
            The name of the collection to be created. Resource name must be 1-45
            characters long, start and end with an alphanumeric character, and
            consist only of lower case alphanumeric characters or '-'.
        source:
          type: string
          description: The name of the index to be used as the source for the collection.
          example: example-source-index
    CollectionModel:
      type: object
      description: >-
        The CollectionModel describes the configuration and status of a Pinecone
        collection.
      required:
        - name
        - status
        - environment
      properties:
        name:
          type: string
          description: The name of the collection.
          example: example-collection
        size:
          type: integer
          description: The size of the collection in bytes.
          example: 10000000
          format: int64
        status:
          type: string
          description: The status of the collection.
          enum:
            - Initializing
            - Ready
            - Terminating
          example: Initializing
        dimension:
          type: integer
          description: >-
            The dimension of the vectors stored in each record held in the
            collection.
          example: 1536
          minimum: 1
          maximum: 2000
          format: int32
        vector_count:
          type: integer
          example: 120000
          format: int32
          description: The number of records stored in the collection.
        environment:
          type: string
          description: The environment where the collection is hosted.
          example: us-east1-gcp
    ErrorResponse:
      type: object
      description: The response shape used for all error responses.
      required:
        - status
        - error
      properties:
        status:
          type: integer
          description: The HTTP status code of the error.
          example: 500
        error:
          type: object
          description: Detailed information about the error that occurred.
          required:
            - code
            - message
          properties:
            code:
              type: string
              enum:
                - OK
                - UNKNOWN
                - INVALID_ARGUMENT
                - DEADLINE_EXCEEDED
                - QUOTA_EXCEEDED
                - NOT_FOUND
                - ALREADY_EXISTS
                - PERMISSION_DENIED
                - UNAUTHENTICATED
                - RESOURCE_EXHAUSTED
                - FAILED_PRECONDITION
                - ABORTED
                - OUT_OF_RANGE
                - UNIMPLEMENTED
                - INTERNAL
                - UNAVAILABLE
                - DATA_LOSS
                - FORBIDDEN
            message:
              type: string
              example: >-
                Index name must contain only lowercase alphanumeric characters
                or hyphens, and must not begin or end with a hyphen.
            details:
              description: >-
                Additional information about the error. This field is not
                guaranteed to be present.
              type: object
          example:
            code: INVALID_ARGUMENT
            message: >-
              Index name must contain only lowercase alphanumeric characters or
              hyphens, and must not begin or end with a hyphen.
      example:
        status: 429
        error:
          code: QUOTA_EXCEEDED
          message: >-
            The index exceeds the project quota of 5 pods by 2 pods. Upgrade
            your account or change the project settings to increase the quota.
  responses:
    400BadRequest:
      description: Bad request. The request body included invalid request parameters.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            index-metric-validation-error:
              summary: Validation error on metric.
              value:
                status: 400
                error:
                  code: INVALID_ARGUMENT
                  message: Metric must be cosine, euclidean, or dotproduct.
    401Unauthorized:
      description: 'Unauthorized. Possible causes: Invalid API key.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            unauthorized:
              summary: Unauthorized
              value:
                status: 401
                error:
                  code: UNAUTHENTICATED
                  message: Invalid API key.
    403CollectionsQuotaExceeded:
      description: You've exceed your collections quota.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            unauthorized:
              summary: Forbidden
              value:
                status: 403
                error:
                  code: FORBIDDEN
                  message: >-
                    Collection exceeds quota. Maximum allowed on your account is
                    1. Currently have 1.
    422UnprocessableEntity:
      description: Unprocessable entity. The request body could not be deserialized.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missing-field:
              summary: Unprocessable entity
              value:
                status: 422
                error:
                  code: INVALID_ARGUMENT
                  message: >-
                    Failed to deserialize the JSON body into the target type:
                    missing field `metric` at line 1 column 16
    500InternalServerError:
      description: Internal server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            internal-server-error:
              summary: Internal server error
              value:
                status: 500
                error:
                  code: UNKNOWN
                  message: Internal server error
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      name: Api-Key
      description: >-
        An API Key is required to call Pinecone APIs. Get yours from the
        [console](https://app.pinecone.io/).
      in: header

````