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

# List credits

> Get all credits

export const ListAPIInfo = ({info: {query_fields, allowed_combinations, search_fields, sort_fields, default_sort}, show_filter_combinations}) => {
  return <AccordionGroup>
    {query_fields != null && query_fields.length > 0 ? <Accordion title="Query Parameters">
      {query_fields.map(field => <ParamField key={field} query={field.name} type={field.type}>
            {field.description}
          </ParamField>)}
    </Accordion> : ''}

    {allowed_combinations != null && allowed_combinations.length > 0 ? <Accordion title="Filterable Fields">
      {[...new Set(allowed_combinations.flat())].map(field => <ParamField key={field} query={field} type="string" />)}
      {show_filter_combinations ? <>
        <h3 style={{
    marginTop: "0em"
  }}>Allowed filter combinations</h3>
        <ul>
          {allowed_combinations.map(comb => <li key="a">
              {comb.map((e, i) => <><code>{e}</code>{i != comb.length - 1 ? ", " : ""}</>)}
            </li>)}
        </ul>
        </> : ''}
    </Accordion> : ''}

    {search_fields != null && search_fields.length > 0 ? <Accordion title="Searchable Fields">
      Fields that can be searched on using <code>_search</code> query param
      {search_fields.map(field => <ParamField key={field} query={field.name} type={field.type}>
            {field.description}
          </ParamField>)}
    </Accordion> : ''}

    {sort_fields != null && sort_fields.length > 0 ? <Accordion title="Sortable Fields">
      Fields with which the list response can be sorted using <code>_sort</code> query param
      {sort_fields.map(field => <ParamField key={field} query={field.name} type={field.type}>
            {field.description}
          </ParamField>)}
      {default_sort ? <Note>
            Default sort order:<code>{Object.entries(default_sort).map(e => e[0] + " " + e[1]).join(', ')}</code>
          </Note> : ''}
    </Accordion> : ''}

      
  </AccordionGroup>;
};

export const listCreditsQueryFields = {
  query_fields: [{
    name: "id",
    type: "string",
    description: "Unique identifier of the credit"
  }, {
    name: "account_id",
    type: "string",
    description: "Unique identifier of the account associated with the credit"
  }, {
    name: "status",
    type: "enum",
    description: "Status of the credit"
  }, {
    name: "created_at",
    type: "string",
    description: "Creation date of the credit"
  }],
  allowed_combinations: [["id"], ["account_id"], ["account_id", "status"], ["account_id", "status", "created_at"], ["account_id", "created_at"]],
  search_fields: [{
    name: "id",
    type: "string",
    description: "Unique identifier of the credits"
  }],
  sort_fields: [{
    name: "created_at",
    type: "string",
    description: ""
  }, {
    name: "id",
    type: "string",
    description: ""
  }],
  default_sort: {
    "created_at": "DESC",
    "id": "ASC"
  }
};

<ListAPIInfo info={listCreditsQueryFields} show_filter_combinations />


## OpenAPI

````yaml get /credits
openapi: 3.0.3
info:
  version: '1.0'
  title: Togai Apis
  contact:
    email: engg@togai.com
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  description: APIs for Togai App
servers:
  - description: Api endpoint
    url: https://api.togai.com/
  - description: Sandbox api endpoint
    url: https://sandbox-api.togai.com/
security:
  - bearerAuth: []
tags:
  - name: Customers
    description: Customer level calls
  - name: Accounts
    description: Account level calls
  - name: Event Schemas
    description: Event Schema level calls
  - name: Usage Meters
    description: Usage Meter level calls
  - name: Price Plans
    description: (DEPRECATED) Price Plan level calls
  - name: PricePlanV2
    description: Price Plan V2 level calls
  - name: Schedules
    description: Account Schedule level calls
  - name: Pricing Rules
    description: Pricing Rules level calls
  - name: Settings
    description: Settings
  - name: Price Experimentation
    description: Price Experimentation apis
  - name: InvoiceGroups
    description: Invoice Group level calls
  - name: Organization
    description: Organization level calls
  - name: FileStorage
    description: File Storage level calls
  - name: Aliases
    description: Alias level calls
  - name: Reports
    description: Report level calls
  - name: ReportTemplates
    description: Report Template level calls
  - name: Customer Portal
    description: Portal level calls
  - name: Alerts
    description: Alert level calls
  - name: Event Management
    description: APIs for getting events ingested in Togai
    externalDocs:
      description: docs
      url: https://togai.com/docs/billing/events
  - name: Metrics
    description: APIs for getting Togai metrics
    externalDocs:
      description: docs
      url: https://togai.com/docs/metrics
  - name: Licenses
    description: APIs for getting or updating license records in Togai
  - name: Entitlements
    description: APIs related to entitlements
  - name: Invoices
    description: Invoices API
  - name: Credits
    description: Credits API
  - name: Wallet
    description: Wallet API
  - name: InvoiceTemplates
    description: InvoiceTemplates API
  - name: InvoiceSequence
    description: InvoiceSequence API
  - name: Payments
    description: Payments API
  - name: Authentication
    description: Authentication API
externalDocs:
  description: Find out more about Togai
  url: https://docs.togai.com/docs
paths:
  /credits:
    get:
      tags:
        - Credits
      summary: List credits
      description: Get all credits
      operationId: listCredits
      parameters:
        - $ref: '#/components/parameters/filter_next_page_token'
        - $ref: '#/components/parameters/filter_status'
        - $ref: '#/components/parameters/filter_account_id'
        - $ref: '#/components/parameters/filter_credit_id'
        - $ref: '#/components/parameters/filter_page_size'
      responses:
        '200':
          $ref: '#/components/responses/ListCreditsResponse'
        '400':
          $ref: '#/components/responses/ErrorResponse'
        '401':
          $ref: '#/components/responses/ErrorResponse'
        '403':
          $ref: '#/components/responses/ErrorResponse'
        '404':
          $ref: '#/components/responses/ErrorResponse'
        '429':
          $ref: '#/components/responses/ErrorResponse'
        default:
          $ref: '#/components/responses/ErrorResponse'
components:
  parameters:
    filter_next_page_token:
      in: query
      description: Pagination token used as a marker to get records from next page.
      name: nextToken
      required: false
      schema:
        type: string
        example: >-
          eyJsYXN0SXRlbUlkIjogInN0cmluZyIsICJwYWdlU2l6ZSI6IDEyMywgInNvcnRPcmRlciI6ICJhc2MifQ==
    filter_status:
      in: query
      description: Filter option to filter by status.
      name: status
      required: false
      schema:
        type: string
      examples:
        processed:
          value: PROCESSED
        in_progress:
          value: IN_PROGRESS
    filter_account_id:
      in: query
      description: Filter option to filter based on account id.
      name: account_id
      required: false
      schema:
        type: string
        example: '1234'
    filter_credit_id:
      in: query
      description: Filter option to filter based on credit id.
      name: id
      required: false
      schema:
        type: string
        example: cred.1znpoFlsI3U.zmg85
    filter_page_size:
      in: query
      description: |-
        Maximum page size expected by client to return the record list. 

         NOTE: Max page size cannot be more than 50. Also 50 is the default page size if no value is provided.
      name: pageSize
      required: false
      schema:
        type: integer
        example: 10
  responses:
    ListCreditsResponse:
      description: Response for Get invoice requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ListCreditsResponse'
          examples:
            ListCreditsResponse:
              $ref: '#/components/examples/ListCreditsResponse'
    ErrorResponse:
      description: Error response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            ErrorResponse:
              summary: Error message
              value:
                message: <Reason message>
  schemas:
    ListCreditsResponse:
      description: List credits response
      type: object
      additionalProperties: false
      required:
        - data
      properties:
        data:
          type: array
          minItems: 0
          maxItems: 50
          items:
            $ref: '#/components/schemas/Credit'
        nextToken:
          type: string
          maxLength: 500
          example: >-
            eyJsYXN0SXRlbUlkIjogInN0cmluZyIsICJwYWdlU2l6ZSI6IDEyMywgInNvcnRPcmRlciI6ICJhc2MifQ==
    ErrorResponse:
      type: object
      additionalProperties: false
      required:
        - message
      properties:
        message:
          type: string
          description: error description
          maxLength: 500
    Credit:
      allOf:
        - $ref: '#/components/schemas/CreditRequest'
        - type: object
          additionalProperties: false
          required:
            - id
            - customerId
            - status
            - createdAt
          properties:
            id:
              description: Identifier of credits
              type: string
              maxLength: 50
              example: cred.1znqBOVcai0.0tBFz
            customerId:
              type: string
              example: 7VcRw9xZDIqsC5E
            status:
              type: string
              enum:
                - ACTIVE
                - CONSUMED
                - EXPIRED
                - VOIDED
              example: ACTIVE
            creditUnit:
              type: string
              example: USD
            holdAmount:
              type: number
              example: 500
            consumedAmount:
              type: number
              example: 400
            createdAt:
              type: string
              format: date-time
            updatedAt:
              type: string
              format: date-time
    CreditRequest:
      description: Payload to grant Credits
      type: object
      additionalProperties: false
      required:
        - accountId
        - effectiveFrom
        - priority
        - purpose
      properties:
        accountId:
          type: string
          example: ACC001
        purpose:
          type: string
          example: PREPAID_CREDIT
        applicableEntityIds:
          description: >
            List of entity ids for which the credit is applicable. If null or
            empty, the credit is applicable to all ids. This list can accept
            special values like: - ALL_USAGE_METER_RATE_CARDS: To apply the
            credit to all usage meter rate cards - ALL_FIXED_FEE_RATE_CARDS: To
            apply the credit to all fixed fee rate cards
          type: array
          uniqueItems: true
          items:
            type: string
            example:
              - umg.1znQx9jiIXw.r44fc
              - ALL_USAGE_METER_RATE_CARDS
              - ALL_FIXED_FEE_RATE_CARDS
        effectiveFrom:
          type: string
          format: date
          example: '2020-07-04'
        effectiveUntil:
          type: string
          format: date
          example: '2021-07-04'
        creditAmount:
          type: number
          example: 1000
        priority:
          type: integer
          example: 1
        grantorId:
          description: The entity through which the credit has been granted
          type: string
        idempotencyKey:
          description: The idempotency key for uniqueness of the credit record
          type: string
  examples:
    ListCreditsResponse:
      summary: A sample Credits List
      value:
        data:
          - id: creds.1znQx9jiIXw.r44fc
            customerId: 7VcRw9xZDIqsC5E
            accountId: ACC001
            purpose: Prepaid Credit
            effectiveFrom: '2020-07-04'
            effectiveUntil: '2021-07-04'
            status: ACTIVE
            creditAmount: 1000
            creditUnit: USD
            holdAmount: 500
            consumedAmount: 400
            priority: 1
            createdAt: '2020-07-04T12:00:00.000Z'
        nextToken: >-
          eyJsYXN0SXRlbUlkIjogInN0cmluZyIsICJwYWdlU2l6ZSI6IDEyMywgInNvcnRPcmRlciI6ICJhc2MifQ==
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Bearer <credential>

````