From 11b80e4df5449bd6ba4502c7066c435b8fbe553a Mon Sep 17 00:00:00 2001 From: "promptless[bot]" Date: Tue, 3 Nov 2026 01:37:19 +0000 Subject: [PATCH] docs(sdk): document JSON remote values and deployed runtime credentials --- sdk/apps/deploy.mdx | 17 ++++++++++++++--- sdk/apps/dev-sessions.mdx | 13 ++++++++++++- sdk/configuration/parameters.mdx | 18 ++++++++++++++++++ sdk/configuration/storage.mdx | 2 ++ serverless/workers/handler-functions.mdx | 4 ++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/sdk/apps/deploy.mdx b/sdk/apps/deploy.mdx index cf36e7a6d..f4c9a4ec4 100644 --- a/sdk/apps/deploy.mdx +++ b/sdk/apps/deploy.mdx @@ -10,7 +10,7 @@ When your app works in a [dev session](/sdk/apps/dev-sessions), deploy it to cre rp flash deploy ``` -The command finds every app in the current directory, builds an artifact for each one, uploads it, and creates or updates the endpoints in the target environment. When it finishes, it prints a link to each endpoint. +The command finds every app in the current directory, builds an artifact for each one, uploads it, and creates or updates the endpoints in the target environment. When it finishes, it lists every resource in the app. Queue and API resources show a link to their endpoint. Tasks show as registered, because each task call provisions its own Pod. To deploy a different directory, pass it as an argument: `rp flash deploy path/to/project`. @@ -64,7 +64,7 @@ These paths are left out of every artifact, and negation patterns can't re-inclu ## Call deployed resources -From another codebase, use `runpod.Queue` and `runpod.Api` to call resources in a deployed app by name: +From another codebase, use `runpod.Queue`, `runpod.Api`, and `runpod.Task` to call resources in a deployed app by name: ```python import runpod @@ -74,9 +74,20 @@ result = transcribe.remote(audio_url="https://example.com/audio.mp3") inference = runpod.Api(app="media", name="inference") response = inference.post("/generate", {"prompt": "hi"}) + +train = runpod.Task(app="media", name="train") +job = train.spawn(steps=500) # Use train.remote(...) to wait for the result ``` -Both target the `default` environment unless you pass `env=`. +Each stub targets the `default` environment unless you pass `env=`. Arguments and results must be JSON-compatible. See [Arguments and return values](/sdk/apps/dev-sessions#arguments-and-return-values). + +From your machine, these calls use your account credentials from `rp login` or `RUNPOD_API_KEY`, so they can reach any app that your API key has permission to call. + +### Calls from deployed workers + +Deployed workers don't receive your API key. Runpod issues each endpoint and task Pod its own runtime credentials, and the SDK uses them for calls the worker makes to other resources. With these credentials, a deployed worker can call only resources in its own app and environment. This applies to `.remote()` calls on your resources and to `runpod.Queue`, `runpod.Api`, and `runpod.Task` stubs. A call to another app or environment fails. + +Because Runpod sets these credentials, your resources can't use some environment variable names. See [env](/sdk/configuration/parameters#env). You can also call a deployed queue endpoint by ID with the [endpoint client](/sdk/overview#endpoint-client), or send HTTP requests to it directly. See [Send API requests](/serverless/endpoints/send-requests). diff --git a/sdk/apps/dev-sessions.mdx b/sdk/apps/dev-sessions.mdx index efa45d4c9..c1a1a6a4f 100644 --- a/sdk/apps/dev-sessions.mdx +++ b/sdk/apps/dev-sessions.mdx @@ -37,7 +37,7 @@ The command exits with an error if the entrypoint fails, so you can use it as a ## Python version -In a dev session, and for every task call, the SDK sends your function to the worker as a serialized payload produced by your local Python. The worker must run the same Python version, so your local interpreter must be one of the supported versions: 3.10, 3.11, 3.12, 3.13, or 3.14. An unsupported version fails with an error before anything is provisioned. +In a dev session, and for task calls from your machine, the SDK sends your function's source code to the worker. The worker runs the same Python version as your machine so that syntax and language behavior match. Your local interpreter must be one of the supported versions: 3.10, 3.11, 3.12, 3.13, or 3.14. An unsupported version fails with an error before anything is provisioned. ## Write code that works in a session @@ -60,6 +60,17 @@ Inside an entrypoint, call your resources in whichever way suits the work: `remote()` and `job.wait()` don't impose an execution timeout by default. +### Arguments and return values + +Remote calls send arguments, return values, and stream chunks as JSON. Use JSON-compatible values: strings, numbers, booleans, `None`, lists, and dictionaries. The SDK converts values the way Python's `json` module does, including when a function calls another function on the same worker: + +- Tuples arrive as lists. +- Dictionary keys that are numbers, booleans, or `None` arrive as strings. + +Bytes, custom objects such as NumPy arrays or tensors, circular references, and `NaN` or infinite floats make the call fail with an error. Convert them before you pass or return them, for example with `tensor.tolist()`. For large binary data, such as model weights or images, write the data to a [volume](/sdk/configuration/storage) and return its path. + +`fn.local(...)` is a direct Python call, so it accepts and returns any Python value. + ### Spawned tasks Calling `.spawn()` on a task returns a job that owns its Pod: diff --git a/sdk/configuration/parameters.mdx b/sdk/configuration/parameters.mdx index 9012b51bb..d6b9d0d52 100644 --- a/sdk/configuration/parameters.mdx +++ b/sdk/configuration/parameters.mdx @@ -194,6 +194,24 @@ def infer(): ... Create secrets with `rp secret add`. Secret values never pass through the SDK. +Runpod sets runtime identity and credential variables on deployed workers, so `rp flash deploy` fails if `env` uses a reserved name. Queue and API resources can't use these names: + +- Credentials: `RUNPOD_API_KEY` and `RUNPOD_AI_API_KEY`. +- Worker identity: `RUNPOD_ENDPOINT_ID`, `RUNPOD_POD_ID`, `RUNPOD_BUILD_ID`, and `RUNPOD_RUNTIME_KIND`. +- App identity: `FLASH_APP_NAME`, `FLASH_ENVIRONMENT`, `FLASH_RESOURCE_NAME`, and `FLASH_BUILD_ARTIFACT_PATH`. +- Task and dev session internals: `RUNPOD_TASK_TOKEN`, `RUNPOD_TASK_PORT`, `RUNPOD_DEV_APP`, `RUNPOD_DEV_RESOURCE`, and `RUNPOD_DEV_SESSION`. + +Tasks can't use any name that starts with `RUNPOD_` or `FLASH_`, in any letter case. They also can't use `PYTHONPATH`, `PYTHONHOME`, or `LD_PRELOAD`. + +If your code needs its own Runpod API key, store it as a secret under a name that isn't reserved: + +```python +@app.queue(cpu="cpu3c-1-2", env={"MY_RUNPOD_API_KEY": runpod.Secret("runpod-api-key")}) +def manage(): ... +``` + +To call other resources in the same app, you don't need a key. See [Calls from deployed workers](/sdk/apps/deploy#calls-from-deployed-workers). + Values in a local `.env` file aren't sent to workers, and `.env` files are always left out of deployments. Pass every variable your workers need through `env`. diff --git a/sdk/configuration/storage.mdx b/sdk/configuration/storage.mdx index e71c01596..c0d79e9c3 100644 --- a/sdk/configuration/storage.mdx +++ b/sdk/configuration/storage.mdx @@ -58,6 +58,8 @@ runpod.GlobalVolume(name_or_id, create=True) | `@app.queue` and `@app.api` | One volume | `/runpod-volume` | | `@app.task` | One network volume and one global volume | Any paths that don't overlap | +When you deploy an app, a task's mount paths also can't overlap paths that the runtime reserves: `/root/.runpod`, `/runpod-volume`, `/proc`, `/sys`, and `/dev`. A mount path overlaps when it equals a reserved path, contains one, or sits inside one. + Global volumes require GPU compute for both tasks and endpoints. ## Read the mount path in your code diff --git a/serverless/workers/handler-functions.mdx b/serverless/workers/handler-functions.mdx index 5862243d3..d42a0f7cc 100644 --- a/serverless/workers/handler-functions.mdx +++ b/serverless/workers/handler-functions.mdx @@ -200,6 +200,10 @@ runpod.serverless.start({"handler": handler}) Exercise caution when using `try/except` blocks to avoid unintentionally suppressing errors. Either return the error for a graceful failure or raise it to flag the job as `FAILED`. +### Results that aren't valid JSON + +Job results travel as JSON. Your handler's return value, and each chunk a streaming handler yields, must be JSON-serializable with finite numbers. If a result contains a value such as bytes, a NumPy array, or `NaN`, the job fails. The SDK marks it as `FAILED` and returns the serialization error in the job results. Convert these values before you return them, for example with `array.tolist()`. Upload binary data to cloud storage and return a link instead. + ## Advanced handler controls Use these features to fine-tune your Serverless applications for specific use cases.