How to deploy and get a live working link via Github Repository through Render API

:rocket: Automatically Deploy GitHub Repo to Render Using Render API

Hi Render Community! :waving_hand:

I’m working on a project where I need to automate the deployment of my chatbot app hosted on GitHub. The repo already contains everything needed—requirements.txt, frontend.py, etc.

My goal:
:backhand_index_pointing_right: With a single script (using the Render API), I want to trigger deployment from GitHub and get back the live public URL of the deployed service.
No manual clicks on the Render dashboard — just full automation!


:red_question_mark:What I’ve Tried

Here’s the Python script I wrote. It does the following:

  1. Gets the Render owner ID
  2. Creates a new web service using a given GitHub repo
  3. Waits for the deployment to complete
  4. Returns the public live URL
import requests
import time
import os
import uuid

def get_owner_id(render_api_key):
    headers = {
        "Authorization": f"Bearer {render_api_key}",
        "Accept": "application/json"
    }
    response = requests.get("https://api.render.com/v1/owners", headers=headers)
    response.raise_for_status()
    owners = response.json()

    if not owners:
        raise Exception("No owners found.")
    return owners[0]["owner"]["id"]

def create_web_service(github_repo, service_name, render_api_key, owner_id):
    headers = {
        "Authorization": f"Bearer {render_api_key}",
        "Content-Type": "application/json"
    }

    payload = {
        "type": "web_service",
        "name": service_name,
        "ownerId": owner_id,
        "repo": github_repo,
        "branch": "main",
        "plan": "free",
        "region": "oregon",
        "serviceDetails": {
            "env": "python",
            "envSpecificDetails": {
                "pythonVersion": "3.11",
                "buildCommand": "pip install -r requirements.txt",
                "startCommand": "streamlit run frontend.py --server.port $PORT"
            }
        }
    }

    response = requests.post("https://api.render.com/v1/services", json=payload, headers=headers)
    response.raise_for_status()
    return response.json()["id"]

def wait_for_deployment(service_id, render_api_key, timeout=300):
    headers = {
        "Authorization": f"Bearer {render_api_key}"
    }
    url = f"https://api.render.com/v1/services/{service_id}/deploys"

    start_time = time.time()
    while time.time() - start_time < timeout:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        data = response.json()
        if data and data[0]['deploy']['status'] == "live":
            return True
        time.sleep(10)
    return False

def get_public_url(service_id, render_api_key):
    headers = {
        "Authorization": f"Bearer {render_api_key}"
    }
    url = f"https://api.render.com/v1/services/{service_id}"
    response = requests.get(url, headers=headers)
    response.raise_for_status()
    return response.json()["service"]["url"]

def deploy_to_render(github_repo_url, render_api_key=None):
    if render_api_key is None:
        render_api_key = os.getenv("RENDER_API_KEY")

    if not render_api_key:
        raise Exception("Missing RENDER_API_KEY.")

    owner_id = get_owner_id(render_api_key)
    service_name = f"chatbot-{uuid.uuid4().hex[:6]}"
    service_id = create_web_service(github_repo_url, service_name, render_api_key, owner_id)

    if not wait_for_deployment(service_id, render_api_key):
        raise Exception("Deployment timed out or failed.")

    return get_public_url(service_id, render_api_key)

:white_check_mark: Inputs:

  • GitHub repo with all necessary files (e.g., frontend.py, requirements.txt)
  • Streamlit app for a chatbot
  • Python 3.11 as environment
  • Public link expected after deployment

:red_exclamation_mark:Problem:

While the script seems to run and give back service creation info, I don’t consistently get a working URL or it doesn’t fully deploy the app.
Is there something wrong with my API payload, structure, or maybe missing a step to trigger a deploy manually?


:folded_hands: Any Help Would Be Great!

If you’ve successfully used the Render API to deploy a web service from GitHub, please share what worked for you or point out what I might be missing.

Thanks in advance :raising_hands: