# Python

### Create podcast

Sample code to create a NotebookLM podcast using Python

```python
import time
import requests

# Replace with your actual token
token = 'YOUR_TOKEN_HERE'

create_url = 'https://api.autocontentapi.com/Content/Create'
status_base_url = 'https://api.autocontentapi.com/content/status/'
poll_interval = 5  # Poll every 5 seconds

# The request data to create the content
request_data = {
    "resources": [
        { "content": "https://autocontentapi.com", "type": "website" },
        { "content": "74% of businesses expect AI to increase productivity", "type": "text" }
    ],
    "text": "Explain why automating with AutoContent API is a game changer for any business",
    "outputType": "audio"
}

def create_content():
    headers = {
        'Authorization': f'Bearer {token}',
        'Content-Type': 'application/json',
        'accept': 'text/plain'
    }
    response = requests.post(create_url, json=request_data, headers=headers)
    response.raise_for_status()
    return response.json()

def poll_status(request_id):
    headers = {
        'Authorization': f'Bearer {token}',
        'Content-Type': 'application/json',
        'accept': 'application/json'
    }
    url = f'{status_base_url}{request_id}'

    while True:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        data = response.json()

        status = data.get('status')
        error_message = data.get('error_message')
        audio_url = data.get('audio_url')
        audio_title = data.get('audio_title')

        if error_message:
            print('Error from status check:', error_message)
            return

        if status == 100:
            print('Content creation complete!')
            print('Audio URL:', audio_url)
            print('Audio Title:', audio_title)
            return

        print(f'Current status: {status}. Waiting for 100...')
        time.sleep(poll_interval)

def main():
    try:
        create_response = create_content()
        request_id = create_response.get('request_id')
        error_message = create_response.get('error_message')

        if error_message or not request_id:
            print('Error from create request:', error_message)
            return

        print('Request initiated. Request ID:', request_id)
        poll_status(request_id)

    except requests.HTTPError as http_err:
        print('HTTP error:', http_err)
    except Exception as err:
        print('Error:', err)

if __name__ == '__main__':
    main()

```

Need specific payloads? Check the [podcast examples](/code-samples/podcasts/python.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.autocontentapi.com/code-samples/language-quickstarts/python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
