Skip to main content

Basic API Server

from langchat.api.app import create_app
from langchat.config import LangChatConfig
import uvicorn

# Create configuration
config = LangChatConfig.from_env()

# Create FastAPI app (auto-generates interface and Dockerfile)
app = create_app(
    config=config,
    auto_generate_interface=True,
    auto_generate_docker=True
)

if __name__ == "__main__":
    print(f"🚀 Starting LangChat API server on port {config.server_port}")
    print(f"📱 Chat interface: http://localhost:{config.server_port}/frontend")
    print(f"📡 API endpoint: http://localhost:{config.server_port}/chat")
    uvicorn.run(app, host="0.0.0.0", port=config.server_port)

API Endpoints

POST /chat

Send a chat message. Request:
Content-Type: application/x-www-form-urlencoded

query=Hello!
userId=user123
domain=general
Response:
{
  "response": "Hello! How can I help you?",
  "user_id": "user123",
  "timestamp": "2024-01-01T12:00:00Z",
  "status": "success",
  "response_time": 1.23
}

GET /frontend

Access the chat interface.

GET /health

Health check endpoint.

POST /feedback

Submit feedback on responses.

Next Steps