The graph result
substrate.run
returns a "graph result" mapping node IDs to node outputs:
The raw response.json
can be a useful way to inspect and debug the outputs of a graph.
But typically, you'll use response.get
to retrieve the output of a node:
Node configuration
Customizing the graph result
When inspecting the graph result, you can name and hide nodes to make the result easier to work with:
id
: Name a node by settingid
to a custom ID.hide
: Hide a node's output from the graph result.
Caching and retries
When building out a graph, it can be useful to cache the result of a node as you iterate on subsequent setups:
_cache_age
: How long to cache the result, in seconds._cache_keys
: A list of specific output keys to cache. Other keys will not be cached.
When running custom code, it can be useful to retry the code automatically (e.g. when using an unreliable service).
_max_retries
: The max number of retries to attempt.
Storing outputs
store
: When using nodes that output media (images (opens in a new tab), audio (opens in a new tab), or video (opens in a new tab)), you can opt-in to hosting their output (on Substrate, or your own storage provider) using thestore
parameter.- When generating embeddings (opens in a new tab), you can store them in Substrate's built-in vector storage.
# Returns image dataGenerateImage(prompt="your prompt")# Returns an image URLGenerateImage( prompt="your prompt", store="hosted",)
Learn more
- Use
store: "hosted"
to host the image on Substrate. - Use
store: "s3://..."
to host on your own storage. See External files to learn more.
Without the store
parameter:
- Nodes with image output return base 64-encoded JPEG data
"image_uri": "data:image/jpeg;base64,/9j/4kZJRBAQYABAAD/4QYRXhpZgAA0AKAA1IBEAAAPEAAAAASg..."
- Nodes with audio output return base 64-encoded WAV data
"audio_uri": "data:audio/wav;base64,/9j/4QSkZJRgABAQEAYAAAD/BYRXhpZgAATU0A1ABIBAAAFAAAASg..."
Shaping outputs
To shape an output, or combine the outputs of multiple nodes into a single response, you can use a Box
:
You can also stream outputs.