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

# Get Text-to-Speech Task Status

> Retrieves the current status of a Text-to-Speech task using the specified `task_id`.

<Card icon="lightbulb" cta="Go to streaming Text-to-Speech" href="create-tts-stream">
  This route is the legacy status check that pairs with deprecated `POST /tts`. For greenfield work, prefer streaming: call `POST /tts-stream` and let audio flow continuously instead of polling here.
</Card>

This endpoint allows you to check on the progress of your Text-to-Speech tasks. When you submit a text-to-speech request, our system begins processing your audio in the background. This endpoint lets you monitor that process from start to finish, keeping you informed about when your audio will be ready.

## How to Use This Endpoint

To check the status of your Text-to-Speech task, simply send a `GET` request to this endpoint with the `task_id` you received when you submitted your original request. The system will respond with detailed information about where your task stands in the processing pipeline.

## Understanding the Response

When you call this endpoint, you'll receive a status response that includes several key pieces of information:

* **Status Code**: Indicates whether the task is still processing, has completed successfully, or encountered an error.
* **Result Information**: For completed tasks, includes the `run_id` needed to download your finished audio file.

### Status Types Explained

Your text-to-speech task will pass through different states as our system processes it. Understanding these status codes will help you properly handle each situation in your application:

| Status             | Description                                                  | Next Step                                                                                                                                |
| :----------------- | :----------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
| `SUCCESS`          | Your audio generation has completed successfully             | Use the `run_id` to download your finished audio                                                                                         |
| `PENDING`          | Your task is currently being processed by our system.        | Continue polling until completion.                                                                                                       |
| `TIMEOUT`          | The processing time exceeded the allowed limit.              | Consider breaking text into smaller segments.                                                                                            |
| `ERROR`            | Something went wrong during processing.                      | Check error details and try submitting again.                                                                                            |
| `PAYMENT_REQUIRED` | Your account requires additional credits for this operation. | Add credits to your account or upgrade your plan by heading to the [billing page](https://studio.camb.ai/billing) and retry the request. |

## Example Code

```python [expandable] theme={null}
import requests
import time

# Your API authentication
headers = {
    "x-api-key": "your-api-key",  # Replace with your actual API key
}

# The task_id you received when submitting your TTS request
task_id = "your_task_id"  # Replace with your actual task ID

# Function to check status and wait for completion
def check_tts_status(task_id):
    print("Checking task status...")

    # Set up polling interval (in seconds)
    polling_interval = 5

    while True:
        # Make the status request
        response = requests.get(
            f"https://client.camb.ai/apis/tts/{task_id}",
            headers=headers
        )

        # Check if the request was successful
        response.raise_for_status()

        # Parse the response
        status_data = response.json()
        print(f"Current status: {status_data['status']}")

        # Use match-case statement to handle different status types
        match status_data['status']:
            case 'SUCCESS':
                print("Task complete!")
                run_id = status_data['run_id']
                print(f"Your audio is ready for download using run_id: {run_id}")
                return run_id

            case 'PENDING':
                print("Task still processing...")
                # Continue to next iteration of while loop

            case 'TIMEOUT':
                print("Task timed out. Consider using shorter text segments.")
                return None

            case 'ERROR':
                print(f"Task failed with error: {status_data.get('error', 'Unknown error')}")
                return None

            case 'PAYMENT_REQUIRED':
                print("Additional credits required to process this request.")
                return None

            case _:  # Default case for any unexpected status values
                print(f"Unexpected status: {status_data['status']}")
                return None

        # If still pending, wait and check again
        if status_data['status'] == 'PENDING':
            print(f"Task still in progress. Checking again in {polling_interval} seconds...")
            time.sleep(polling_interval)
        else:
            # Exit the loop for non-pending statuses after handling them above
            break

# Call the function to monitor your task
run_id = check_tts_status(task_id)

# If task completed successfully, download the audio
if run_id:
    print("Proceed to download the audio file using the run_id!")
```

This polling mechanism gives you flexibility to build applications that can provide real-time feedback to users about their text-to-speech conversions. You can adjust the polling interval based on your specific needs, checking more frequently for time-sensitive applications or less frequently for background tasks.

## Next Steps

Once your task shows a status of `SUCCESS`, you'll receive a `run_id` in the response. This `run_id` is your key to accessing the generated audio. Take this identifier and use it with the [`/tts-result/{run_id}`](get-tts-run-info) endpoint to download your finished audio file and put it to work in your application.


## OpenAPI

````yaml get /tts/{task_id}
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://client.camb.ai/apis
security: []
paths:
  /tts/{task_id}:
    get:
      tags:
        - Apis
        - Text-to-Speech
      summary: Get Tts Result
      operationId: get_tts_result_tts__id__get
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/TaskIDParam'
            description: >-
              A unique identifier for the task. This is used to query the status
              of the text to speech task that is running. It is returned when a
              create request is made for a text to speech.
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrchestratorPipelineResult'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    TaskIDParam:
      type: string
      title: Task ID
      description: >-
        This parameter represents a unique identifier for a task. It is used in
        various API endpoints to query the status or result of a specific task.
        The `task_id` is typically returned when a task is created.
    OrchestratorPipelineResult:
      properties:
        status:
          $ref: '#/components/schemas/TaskStatus'
        run_id:
          type:
            - integer
            - 'null'
          title: Run ID
      type: object
      title: OrchestratorPipelineResult
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    TaskStatus:
      type: string
      enum:
        - SUCCESS
        - PENDING
        - TIMEOUT
        - ERROR
        - PAYMENT_REQUIRED
      title: TaskStatus
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        The `x-api-key` is a custom header required for authenticating requests
        to our API. Include this header in your request with the appropriate API
        key value to securely access our endpoints. You can find your API key(s)
        in the 'API' section of our studio website.

````