Generate API

The generate endpoint allows easy integration of Large Language Models (LLM) like OpenAI or Claude into your app, enabling few-shot training and sending various prompts. It supports dynamic variables to send dynamic prompts.


POST/beta/generate

Generate a completion

Generate a completion by sending 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_calls
    Type
    array
    Description

    The tool calls array returned by the assistant

  • 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

Learn how to use function calling with the Generate API.

Generate API with stream on

POST
/beta/generate
curl https://api.langbase.com/beta/generate \
-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":"Hi"},"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":"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"}]}