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

# Get Usage

> Return usage metrics through the frontend API surface.

Retrieves usage statistics for agents within a specified date range.

### Request

**Method:** `GET`\
**Endpoint:** `/api/usage`\
**Headers:**

* `X-Authorization`: Your API key (required)

**Query Parameters:**

* `uid` (string, required): Your user ID
* `startDate` (string, required): Start date in YYYY-MM-DD format
* `endDate` (string, required): End date in YYYY-MM-DD format
* `agentId` (string, optional): Specific agent ID to get usage for (if not provided, returns usage for all accessible agents)

### Response

**Success Response (200):**

```json theme={null}
{
  "summary": {
    "totalCallCount": number,
    "totalCallMinutes": number,
    "agentCount": number,
    "orgCount": number
  },
  "agents": [
    {
      "agentId": "string",
      "agentName": "string",
      "callCount": number,
      "callMinutes": number,
      "orgId": "string",
      "orgName": "string"
    }
  ],
  "dateRange": {
    "startDate": "string",
    "endDate": "string"
  },
  "requestedAgentId": "string"
}
```

**Error Responses:**

* `400 Bad Request`: Missing required parameters, invalid date format, or invalid date range
* `401 Unauthorized`: Invalid or missing API key
* `404 Not Found`: User not found or agent not found/access denied
* `500 Internal Server Error`: Server error

### Example

```bash theme={null}
curl -X GET "https://app.phonely.ai/api/usage?uid=user123&startDate=2024-01-01&endDate=2024-01-31" \
  -H "X-Authorization: your-api-key"
```

### Notes

* Date range cannot exceed reasonable limits
* If no agents are found for the user, returns empty arrays with zero counts
* The `requestedAgentId` field is only included when filtering for a specific agent


## OpenAPI

````yaml GET /usage
openapi: 3.0.1
info:
  title: Phonely API
  description: API for Phonely services including agent management and call summaries
  version: 1.0.0
servers:
  - url: https://app.phonely.ai/api
security: []
paths:
  /usage:
    get:
      summary: Get usage data
      description: >-
        Retrieves usage data for all agents accessible by a user within a date
        range. If agentId is provided, returns data for that specific agent
        only. Requires X-Authorization header with valid API key.
      parameters:
        - name: uid
          in: query
          required: true
          schema:
            type: string
          description: User ID
        - name: startDate
          in: query
          required: true
          schema:
            type: string
            format: date
            pattern: ^\d{4}-\d{2}-\d{2}$
          description: Start date in YYYY-MM-DD format
        - name: endDate
          in: query
          required: true
          schema:
            type: string
            format: date
            pattern: ^\d{4}-\d{2}-\d{2}$
          description: End date in YYYY-MM-DD format
        - name: agentId
          in: query
          required: false
          schema:
            type: string
          description: Optional agent ID to filter data for specific agent
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageResponse'
        '400':
          description: Invalid request - Missing required parameters or invalid date format
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized - Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: User or agent not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    UsageResponse:
      type: object
      properties:
        summary:
          type: object
          properties:
            totalCallCount:
              type: integer
              description: Total number of calls
            totalCallMinutes:
              type: number
              description: Total call duration in minutes
            agentCount:
              type: integer
              description: Number of agents
            orgCount:
              type: integer
              description: Number of organizations
          required:
            - totalCallCount
            - totalCallMinutes
            - agentCount
            - orgCount
          description: Summary statistics for the usage data
        agents:
          type: array
          items:
            $ref: '#/components/schemas/AgentUsage'
          description: Usage data for each agent
        dateRange:
          type: object
          properties:
            startDate:
              type: string
              format: date
              description: Start date of the query range
            endDate:
              type: string
              format: date
              description: End date of the query range
          required:
            - startDate
            - endDate
          description: Date range for the usage data
        requestedAgentId:
          type: string
          description: >-
            Agent ID that was specifically requested (only present when agentId
            parameter was provided)
          nullable: true
      required:
        - summary
        - agents
        - dateRange
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error code or identifier
        message:
          type: string
          description: Detailed error message
    AgentUsage:
      type: object
      properties:
        agentId:
          type: string
          description: Agent ID
        agentName:
          type: string
          description: Agent name
        orgId:
          type: string
          description: Organization ID
          nullable: true
        orgName:
          type: string
          description: Organization name
          nullable: true
        callCount:
          type: integer
          description: Number of calls for this agent
        callMinutes:
          type: number
          description: Total call duration in minutes for this agent
      required:
        - agentId
        - agentName
        - callCount
        - callMinutes
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Authorization

````