async def api_logs(job: JobIDModel, token: bool = Depends(api_auth)):
    """
    Fetch logs for a given job.

    This endpoint retrieves logs for a specified job by its job ID. It first obtains a JWT token
    to authenticate the request and then fetches the logs from the Hugging Face API.

    Args:
        job (JobIDModel): The job model containing the job ID.
        token (bool, optional): Dependency injection for API authentication. Defaults to Depends(api_auth).

    Returns:
        JSONResponse: A JSON response containing the logs, success status, and a message.

    Raises:
        Exception: If there is an error fetching the logs, the exception message is returned in the response.
    """
    job_id = job.jid
    jwt_url = f"{constants.ENDPOINT}/api/spaces/{job_id}/jwt"
    response = get_session().get(jwt_url, headers=build_hf_headers(token=token))
    hf_raise_for_status(response)
    jwt_token = response.json()["token"]  # works for 24h (see "exp" field)

    # fetch the logs
    logs_url = f"https://api.hf.space/v1/{job_id}/logs/run"

    _logs = []
    try:
        with get_session().get(
            logs_url, headers=build_hf_headers(token=jwt_token), stream=True, timeout=3
        ) as response:
            hf_raise_for_status(response)
            for line in response.iter_lines():
                if not line.startswith(b"data: "):
                    continue
                line_data = line[len(b"data: ") :]
                try:
                    event = json.loads(line_data.decode())
                except json.JSONDecodeError:
                    continue  # ignore (for example, empty lines or `b': keep-alive'`)
                _logs.append((event["timestamp"], event["data"]))

        _logs = "\n".join([f"{timestamp}: {data}" for timestamp, data in _logs])
        return {"logs": _logs, "success": True, "message": "Logs fetched successfully"}
    except Exception as e:
        if "Read timed out" in str(e):
            _logs = "\n".join([f"{timestamp}: {data}" for timestamp, data in _logs])
            return {"logs": _logs, "success": True, "message": "Logs fetched successfully"}
        return {"logs": str(e), "success": False, "message": "Failed to fetch logs"}

    Fetch logs for a given job.

    This endpoint retrieves logs for a specified job by its job ID. It first obtains a JWT token
    to authenticate the request and then fetches the logs from the Hugging Face API.

    Args:
        job (JobIDModel): The job model containing the job ID.
        token (bool, optional): Dependency injection for API authentication. Defaults to Depends(api_auth).

    Returns:
        JSONResponse: A JSON response containing the logs, success status, and a message.

    Raises:
        Exception: If there is an error fetching the logs, the exception message is returned in the response.
    
src/autotrain/app/api_routes.py