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

# Create subscription

> Creates a new subscription to a data stream. Once created, data collection
begins immediately. You can export collected data using the Exports API.

The `spans` array in the response is always empty on create. To retrieve the
initial active span, call `GET /v1/subscriptions/{id}/spans`.




## OpenAPI

````yaml post /v1/subscriptions
openapi: 3.1.0
info:
  title: Ticksupply API
  version: 1.0.0
  description: >
    The Ticksupply API provides programmatic access to cryptocurrency market
    data.

    Subscribe to real-time data streams, manage subscriptions, and export
    historical data.
  contact:
    name: Ticksupply Support
    email: support@ticksupply.com
  termsOfService: https://ticksupply.com/terms
  license:
    name: Proprietary
    url: https://ticksupply.com/terms
servers:
  - url: https://api.ticksupply.com
    description: Production API
security:
  - ApiKeyAuth: []
tags:
  - name: Catalog
    description: Browse available exchanges, instruments, and data streams
  - name: Subscriptions
    description: Manage data stream subscriptions
  - name: Exports
    description: Export historical data to downloadable files
  - name: Availability
    description: Query data availability for specific streams
  - name: Export Schemas
    description: Manage export column schemas for customized CSV output
  - name: Billing
    description: Inspect your plan, access status, and usage for the current billing period
paths:
  /v1/subscriptions:
    post:
      tags:
        - Subscriptions
      summary: Create subscription
      description: >
        Creates a new subscription to a data stream. Once created, data
        collection

        begins immediately. You can export collected data using the Exports API.


        The `spans` array in the response is always empty on create. To retrieve
        the

        initial active span, call `GET /v1/subscriptions/{id}/spans`.
      operationId: createSubscription
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSubscriptionRequest'
            example:
              datastream_id: 123
      responses:
        '201':
          description: Subscription created successfully
          headers:
            Location:
              description: URL of the created subscription resource
              schema:
                type: string
                example: /v1/subscriptions/sub_019478a23c5f7b8e9d12abcdef012345
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubscriptionResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '408':
          $ref: '#/components/responses/RequestTimeout'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      x-codeSamples:
        - lang: python
          label: Python (ticksupply library)
          source: |
            # pip install ticksupply
            from ticksupply import Client

            client = Client(api_key="<api-key>")
            sub = client.subscriptions.create(datastream_id=123)
            print(sub)
        - lang: rust
          label: Rust (ticksupply crate)
          source: |
            // cargo add ticksupply
            // cargo add tokio --features full
            use ticksupply::Client;

            #[tokio::main]
            async fn main() -> ticksupply::Result<()> {
                let client = Client::with_api_key("<api-key>")?;
                let sub = client.subscriptions().create(123).send().await?;
                println!("{sub:#?}");
                Ok(())
            }
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >
        Unique key for idempotent requests. If you retry a request with the same
        key,

        you'll receive the original response without the operation being
        performed again.


        Must be a valid UUID (any version — v4 recommended for uniqueness), up
        to 128 characters.
      schema:
        type: string
        format: uuid
        maxLength: 128
  schemas:
    CreateSubscriptionRequest:
      type: object
      required:
        - datastream_id
      properties:
        datastream_id:
          type: integer
          format: int64
          description: Datastream ID to subscribe to
    SubscriptionResponse:
      type: object
      required:
        - id
        - status
        - datastream
        - created_at
        - spans
      properties:
        id:
          type: string
          pattern: ^sub_[a-f0-9]{32}$
          description: >-
            Prefixed subscription ID (e.g.,
            sub_550e8400e29b41d4a716446655440000)
          example: sub_550e8400e29b41d4a716446655440000
        status:
          $ref: '#/components/schemas/SubscriptionStatus'
        datastream:
          $ref: '#/components/schemas/DatastreamInfo'
        created_at:
          type: string
          format: date-time
          description: When the subscription was created
        spans:
          type: array
          description: >
            Active and historical collection spans for the subscription. Always
            empty

            on the create response — call `GET /v1/subscriptions/{id}/spans` to
            retrieve

            the initial active span.
          items:
            $ref: '#/components/schemas/SubscriptionSpan'
    SubscriptionStatus:
      type: string
      enum:
        - active
        - paused
        - deleted
      description: Current subscription status
    DatastreamInfo:
      type: object
      description: Simplified datastream information for catalog queries
      required:
        - datastream_id
        - exchange
        - instrument
        - stream_type
        - wire_format
      properties:
        datastream_id:
          type: integer
          format: int64
          description: Unique identifier for subscriptions and exports
          example: 123
        exchange:
          type: string
          description: Exchange code
          example: binance
        instrument:
          type: string
          description: Instrument symbol
          example: BTCUSDT
        stream_type:
          type: string
          description: Stream type code
          example: trades
        wire_format:
          type: string
          description: Wire format code
          example: json
    SubscriptionSpan:
      type: object
      required:
        - id
        - started_at
      properties:
        id:
          type: string
          pattern: ^spn_[a-f0-9]{32}$
          description: Prefixed span ID (e.g., spn_0194a1b2c3d4e5f6a7b8c9d0e1f2a3b4)
          example: spn_0194a1b2c3d4e5f6a7b8c9d0e1f2a3b4
        started_at:
          type: string
          format: date-time
          description: When data collection started
        ended_at:
          type: string
          format: date-time
          nullable: true
          description: When data collection ended (null if ongoing)
    ApiError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Error code for programmatic handling
              enum:
                - invalid_argument
                - unauthenticated
                - permission_denied
                - not_found
                - already_exists
                - request_timeout
                - rate_limited
                - payment_required
                - internal
                - unavailable
            message:
              type: string
              description: Human-readable error message
            details:
              type: object
              description: Additional error details (optional)
  responses:
    BadRequest:
      description: Invalid request parameters
      headers:
        X-Request-Id:
          description: Unique request identifier for support inquiries
          schema:
            type: string
            example: req_abc123def456
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error:
              code: invalid_argument
              message: 'Invalid datastream_id: must be a positive integer'
    Unauthorized:
      description: Missing or invalid API key
      headers:
        X-Request-Id:
          description: Unique request identifier for support inquiries
          schema:
            type: string
            example: req_abc123def456
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error:
              code: unauthenticated
              message: Invalid or missing API key
    PaymentRequired:
      description: >
        Billing-related denial — the plan does not allow this action, or a trial
        cap has been reached.

        Possible triggers include accounts that are suspended for non-payment,
        accounts in a billing

        grace period, and trial accounts that have reached their stream or
        export size limits.
      headers:
        X-Request-Id:
          description: Unique request identifier for support inquiries
          schema:
            type: string
            example: req_abc123def456
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error:
              code: payment_required
              message: >-
                You have reached the export limit for your trial period. Your
                full plan limits will be available when your trial ends.
    RequestTimeout:
      description: |
        Request did not complete within the 10-second deadline. Retry with
        exponential backoff. If you see this consistently on a particular
        endpoint, contact support.
      headers:
        X-Request-Id:
          description: Unique request identifier for support inquiries
          schema:
            type: string
            example: req_abc123def456
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error:
              code: request_timeout
              message: Request exceeded 10s deadline
    Conflict:
      description: Resource already exists
      headers:
        X-Request-Id:
          description: Unique request identifier for support inquiries
          schema:
            type: string
            example: req_abc123def456
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error:
              code: already_exists
              message: Subscription already exists with status active
    RateLimited:
      description: Rate limit exceeded
      headers:
        X-Request-Id:
          description: Unique request identifier for support inquiries
          schema:
            type: string
            example: req_abc123def456
        Retry-After:
          description: Seconds to wait before retrying
          schema:
            type: integer
        X-RateLimit-Limit-Minute:
          description: Maximum requests allowed per minute
          schema:
            type: integer
        X-RateLimit-Remaining-Minute:
          description: Requests remaining in the current minute window
          schema:
            type: integer
        X-RateLimit-Reset-Minute:
          description: >-
            Unix timestamp (seconds) when the minute window next has capacity.
            Included only when the minute bucket is exhausted.
          schema:
            type: integer
        X-RateLimit-Limit-Hour:
          description: Maximum requests allowed per hour
          schema:
            type: integer
        X-RateLimit-Remaining-Hour:
          description: Requests remaining in the current hour window
          schema:
            type: integer
        X-RateLimit-Reset-Hour:
          description: >-
            Unix timestamp (seconds) when the hour window next has capacity.
            Included only when the hour bucket is exhausted.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error:
              code: rate_limited
              message: Rate limit exceeded. Retry after 30 seconds.
    InternalError:
      description: Internal server error
      headers:
        X-Request-Id:
          description: Unique request identifier for support inquiries
          schema:
            type: string
            example: req_abc123def456
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error:
              code: internal
              message: An internal error occurred
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key
      description: >-
        Your API key. Get one from the dashboard at
        https://app.ticksupply.com/api-keys

````