LangStream Documentation
Langstream.aiLangStream GitHub RepoChangelog
  • LangStream Documentation
  • ❤️Langstream.ai
  • ⭐LangStream GitHub Repo
  • 📜Changelog
  • about
    • What is LangStream?
    • License
  • Get Started
  • installation
    • LangStream CLI
    • Docker
    • Minikube (mini-langstream)
    • Kubernetes
    • Build and install from source
  • Building Applications
    • Vector Databases
    • Application structure
      • Pipelines
      • Instances
      • Configuration
      • Topics
      • Assets
      • Secrets
      • YAML templating
      • Error Handling
      • Stateful agents
      • .langstreamignore
    • Sample App
    • Develop, test and deploy
    • Application Lifecycle
    • Expression Language
    • API Gateways
      • Websocket
      • HTTP
      • Message filtering
      • Gateway authentication
    • API Reference
      • Agents
      • Resources
      • Assets
  • LangStream CLI
    • CLI Commands
    • CLI Configuration
    • Web interface
  • Integrations
    • Large Language Models (LLMs)
      • OpenAI
      • Hugging Face
      • Google Vertex AI
      • Amazon Bedrock
      • Ollama
    • Data storage
      • Astra Vector DB
      • Astra
      • Cassandra
      • Pinecone
      • Milvus
      • Solr
      • JDBC
      • OpenSearch
    • Integrations
      • Apache Kafka Connect
      • Apache Camel
    • LangServe
  • Pipeline Agents
    • Agent Messaging
    • Builtin agents
      • Input & Output
        • webcrawler-source
        • s3-source
        • azure-blob-storage-source
        • sink
        • vector-db-sink
        • camel-source
      • AI Agents
        • ai-chat-completions
        • ai-text-completions
        • compute-ai-embeddings
        • flare-controller
      • Text Processors
        • document-to-json
        • language-detector
        • query
        • query-vector-db
        • re-rank
        • text-normaliser
        • text-extractor
        • text-splitter
        • http-request
      • Data Transform
        • cast
        • compute
        • drop
        • drop-fields
        • merge-key-value
        • unwrap-key-value
      • Flow control
        • dispatch
        • timer-source
        • trigger-event
    • Custom Agents
      • Python sink
      • Python source
      • Python processor
      • Python service
    • Agent Developer Guide
      • Agent Types
      • Agent Creation
      • Configuration and Testing
      • Environment variables
  • Messaging
    • Messaging
      • Apache Pulsar
      • Apache Kafka
      • Pravega.io
  • Patterns
    • RAG pattern
    • FLARE pattern
  • Examples
    • LangServe chatbot
    • LlamaIndex Cassandra sink
Powered by GitBook
On this page
  • Produce messages
  • Produce messages and wait for a message
  • Proxy service agent requests
Edit on GitHub
  1. Building Applications
  2. API Gateways

HTTP

You connect to a gateway via standard HTTP 1.1. While connecting to a gateway, the path holds pointers to the type of gateway, the tenant, the application id, and the gateway name.

The URL structure is http://<control-plane-domain>:<api-gateway-port>/api/gateways/<gateway-type>/<tenant-name>/<application-id>/<gateway-id>.

Authentication (credentials,test-credentials), options (option:) and parameters (param:) are expected to be in the query string. HTTP headers are ignored by the API Gateway service.

Produce messages

To produce messages via HTTP, configure a produce gateway:


gateways:
  - id: "user-input"
    type: produce
    topic: "questions-topic"
    parameters:
    - sessionId

Once a gateway is configured, you can use whatever HTTP client you prefer to connect. This is an example with Curl:

curl -X POST -d "Hello" "http://localhost:8091/api/gateways/produce/my-tenant/my-app/user-input?param:sessionId=12543yusi1"

or if you would like to add the record key, headers or a structured value you can pass the body as JSON setting Content-Type: application/json

curl -X POST -d '{"value": {"question": "hello"}, "key": "k1", headers: {"h1": "v1"}}' -H 'Content-Type: application/json' "http://localhost:8091/api/gateways/produce/my-tenant/my-app/user-input?param:sessionId=12543yusi1"

You can also use the LangStream CLI:

langstream gateway produce my-app user-input --protocol http -v '{"value": "hello"}' -p sessionId=12543yusi1

Produce messages and wait for a message

To produce messages via HTTP and wait for a message, configure a service gateway:


gateways:
  - id: "user-input-await"
    type: service
    parameters:
    - sessionId
    service-options:
        input-topic: inputs
        output-topic: results

Once a gateway is configured, you can use whatever HTTP client you prefer to connect. This is an example with Curl:

curl -X POST -d '{"value": "hello"}' -H 'Content-Type: application/json' "http://localhost:8091/api/gateways/service/my-tenant/my-app/user-input-await"

The timeout of the wait is the TCP timeout of the connection, which is usually 30 seconds (may vary depending on the http client).

Proxy service agent requests

To proxy requests to a specific service agent via HTTP, configure a service gateway:

gateways:
  - id: "my-service"
    type: service
    parameters:
    - sessionId
    service-options:
        agent-id: my-service-agent
     

A service agent might look like this in the pipeline configuration:

pipeline:
  - name: "Start my service"
    id: my-service-agent
    type: "python-service"
    configuration:
      className: example.ChatBotService

Once a gateway is configured, you can use whatever HTTP client you prefer to connect. This is an example with Curl:

curl -X POST \
    -d '{"value": "hello"}' \
    -H 'Authorization: Bearer XXX' \
    -H 'Content-Type: application/json' \
    "http://localhost:8091/api/gateways/service/my-tenant/my-app/my-service/the/custom/path?service-param-1=yes"

The final part of the URL, query string, HTTP method, and headers will be sent to the service agent.

In the above case, the agent service will receive an equivalent request of:

curl -X POST \
    -d '{"value": "hello"}' \
    -H 'Authorization: Bearer XXX' \
    -H 'Content-Type: application/json' \
    "http://localhost:8000/the/custom/path?service-param-1=yes"

The credentials, test-credentials, option:xx, param:xx are stripped out from the routed requests. If the gateway has authentication enabled, it will be performed as for other gateways.

POST, GET, DELETE and PUT are all supported.

Leveraging the API gateway to expose your service solves authentication, HTTPS, high-availability, and scalability out of the box.

PreviousWebsocketNextMessage filtering

Last updated 1 year ago