base64_module.cpp— C++ extension: fast file → base64 encodersetup.py— builds the C++ extension into a Python-importable modulemain.py— Python script that calls the NVIDIA chat completions API, using the C++ extension for any file/image encoding
pip install pybind11
python setup.py build_ext --inplaceThis produces a fastb64*.so file in this directory that main.py imports
directly.
Do not put the key in the source code. Export it as an environment variable instead:
export NVIDIA_API_KEY="nvapi-..."(If you pasted a key into this chat earlier, treat it as compromised — revoke/regenerate it in your NVIDIA NGC account.)
python main.pyTo send an image with the prompt:
call_api("What's in this image?", image_path="photo.png")The C++ extension handles reading + base64-encoding the file; Python handles the HTTP request and JSON response.
Files added for this: Dockerfile, .dockerignore, requirements.txt,
worker.py, render.yaml.
worker.py calls the API on a loop (interval set by POLL_INTERVAL_SECONDS,
default 3600s) and shuts down cleanly on SIGTERM, which Render sends when
stopping or redeploying a worker.
Option A — Blueprint (render.yaml), one click:
- Push this folder to a GitHub/GitLab repo.
- In Render: New > Blueprint → pick the repo. Render reads
render.yamland creates the worker for you. - Go to the new service's Environment tab and set
NVIDIA_API_KEY(it's markedsync: falseso it isn't committed to your repo). - Deploy.
Option B — Manual:
- Push this folder to a repo.
- In Render: New > Background Worker → pick the repo.
- Runtime: Docker (Render will find the
Dockerfileautomatically). - Add environment variable
NVIDIA_API_KEY(and optionallyPOLL_INTERVAL_SECONDS) under the Environment tab. - Create the worker.
Render will build the Docker image (compiling the C++ extension during the
build step) and start worker.py. Check the Logs tab to confirm it's
polling successfully. Note that main.py checks for NVIDIA_API_KEY at
startup, so if it's missing the worker will exit immediately with a clear
error in the logs (and Render will keep restarting it) rather than running
with a broken key — set the env var and redeploy to fix.