The Run API allows you to execute any pipe and receive its response. It supports all use cases of Pipes, including chat interactions, single generation tasks, and function calls.
Note
The /run API consolidates the functionality of the previously separate /generate and /chat endpoints, providing a unified interface. As a result, we will soon be deprecating both /generate and /chat in favor of /run.
The Run API supports:
Single generation requests for straightforward tasks.
Dynamic variables to create adaptable prompts in real-time.
Thread management for handling multi-turn conversations.
Seamless conversation continuation, ensuring smooth transitions across interactions.
If needed, Langbase can store messages and conversation threads, allowing for persistent conversation history for chat use cases.
import{ Langbase }from'langbase';const langbase =newLangbase({apiKey:'<LANGBASE_API_KEY>'// User/Org API key});const response =await langbase.pipe.run({apiKey:'<PIPE-API-KEY>',// Replace with your pipe API key.messages:[{role:'user',content:'Who is an AI Engineer?'}]});
CopyCopied!
Response Headers
Name
lb-thread-id
Type
string
Description
The ID of the new/existing thread. If you want to continue conversation in this thread, send it as threadId in the next request.
{"completion":"AI Engineer is a person who designs, builds, and maintains AI systems.","raw":{"id":"chatcmpl-123","object":"chat.completion","created":1720131129,"model":"gpt-4o-mini","choices":[{"index":0,"message":{"role":"assistant","content":"AI Engineer is a person who designs, builds, and maintains AI systems."},"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":28,"completion_tokens":36,"total_tokens":64},"system_fingerprint":"fp_123"}}
CopyCopied!
RunResponseStream type with stream true
// A stream chunk looks like this …{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1719848588,"model":"gpt-4o-mini","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{"content":"Hi"},"logprobs":null,"finish_reason":null}]}// More chunks as they come in...{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1719848588,"model":"gpt-4o-mini","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{"content":"there"},"logprobs":null,"finish_reason":null}]}…{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1719848588,"model":"gpt-4o-mini","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}