DRF Views

djangosdk provides two pre-built Django REST Framework views for building AI endpoints.

Setup

Ensure djangorestframework is installed:

uv add "djangosdk[drf]"

ChatAPIView

ChatAPIView is a synchronous DRF APIView that accepts a message and returns the agent's response as JSON.

Usage

# myapp/views.py
from djangosdk.views.chat import ChatAPIView
from myapp.agents import SupportAgent

class SupportChatView(ChatAPIView):
    agent_class = SupportAgent
# myapp/urls.py
from django.urls import path
from myapp.views import SupportChatView

urlpatterns = [
    path("api/chat/", SupportChatView.as_view()),
]

Request Format

Response Format

StreamingChatAPIView

StreamingChatAPIView returns a Server-Sent Events stream.

Usage

Request Format

or

SSE Response

Authentication

Both views work with DRF's standard authentication and permission classes:

Customizing the Agent Per Request

Override get_agent() to create an agent based on request context:

URL Configuration

Include the SDK's pre-built URL patterns:

This mounts:

  • POST /ai/chat/ChatAPIView

  • GET /ai/chat/stream/StreamingChatAPIView

Last updated

Was this helpful?