Using LangChain
with the Bytez API
langchain_bytez
package to interact with
the Bytez API. It covers text generation
, chat models
(including multimodal),
image-text-to-text
, video-text-to-text
, audio-text-to-text
, streaming, async operations, and
provides examples to get you started."YOUR_BYTEZ_API_KEY"
with your actual API key.
BytezLLM
class allows you to use Bytez for text generation.
BytezChatModel
class provides a convenient way to interact with chat models.
BytezChatModel
also supports multimodal models by accepting a list of messages, where the content of each message can be text or image data.
streaming=True
in the constructor. This allows you to receive responses in real-time. The provided StreamingStdOutCallbackHandler is a simple way to see the streamed output.
BytezStdOutCallbackHandler
is provided as a utility, but you’re free to create your own for enhanced logging, metrics, or other custom behavior.
langchain_bytez
package also fully supports asynchronous operations using asyncio.
model_id (str)
: The Bytez model ID (required). Check the Bytez documentation for available models.api_key (str)
: Your Bytez API key (required).capacity (dict)
: Controls cluster scaling. Supports min, max, and desired keys.timeout (int)
: Timeout in minutes for cluster shutdown after the last inference (optional).streaming (bool)
: Enable streaming responses (default: False).params (dict)
: Parameters to pass to the Bytez API (optional), such as max_new_tokens.headers (dict)
: Custom headers to send with the API request (optional). Useful for authentication.http_timeout_s (float)
: Timeout in seconds for the HTTP request (default: 300 seconds).model_id
values with actual Bytez model IDs. Ensure that the model ID you select supports the media type that you provide.API_KEY
environment variable is correctly set.