Run Pipe API

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.


POST/beta/pipes/run

Run a pipe

Run a pipe by sending the required data with the request. For basic request, send a messages array inside request body.

Required headers

  • Name
    Content-Type
    Type
    string
    Description

    Request content type. Needs to be application/json

  • Name
    Authorization
    Type
    string
    Description

    Replace PIPE_API_KEY with your Pipe API key

Required attributes

  • Name
    messages
    Type
    array
    Description

    An array containing message objects

  • Name
    messages[0].role
    Type
    string
    Description

    The role of the message, i.e., system | user | assistant | tool

  • Name
    messages[0].content
    Type
    string
    Description

    The content of the message

Optional attributes

  • Name
    messages[0].tool_call_id
    Type
    string
    Description

    The id of the called LLM tool if the role is tool

  • Name
    messages[0].name
    Type
    string
    Description

    The name of the called tool if the role is tool

    • Name
      variables
      Type
      array
      Description

      An array containing different variable objects

    • Name
      variables[0].name
      Type
      string
      Description

      The name of the variable

    • Name
      variables[0].value
      Type
      string
      Description

      The value of the variable

  • Name
    threadId
    Type
    string
    Description

    The ID of an existing chat thread. The conversation will continue in this thread.

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.

Learn how to use function calling with this API.

Basic request without streaming

POST
/beta/pipes/run
curl https://api.langbase.com/beta/pipes/run \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer PIPE_API_KEY' \
-d '{
  "messages": [
    {
      "role": "user",
      "content": "Hello!"
    }
  ]
}'

Response

{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1719848588,"model":"gpt-4o-mini","system_fingerprint":"fp_44709d6fcb","choices":[{"index":0,"delta":{"role":"assistant","content":""},"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":{"content":"Hello"},"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"}]}

Response Header

HTTP/2 200
lb-thread-id: "…-…-…-…-… ID of the thread"
… … … rest of the headers … : … … …