API - Providers

Provider API view for the Dashboard prompt passthrough feature.

This module exposes a JSON API endpoint used by the prompt passthrough React frontend to retrieve the LLM providers that the currently authenticated user has read permission for. The provider list is serialised with ProviderMiniSerializer and returned as a JSON response.

Classes:
ProviderApiView: Authenticated API view that returns the list of accessible

LLM providers for the requesting user.

Example

Wire up the view in your URL configuration:

from smarter.apps.dashboard.views.passthrough.api.providers import ProviderApiView

urlpatterns = [
    path("providers/", ProviderApiView.as_view(), name="api_providers"),
]
class smarter.apps.dashboard.views.passthrough.api.providers.ProviderApiView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Authenticated JSON API view that returns LLM providers accessible to the requesting user.

Extends SmarterAuthenticatedNeverCachedWebView to enforce authentication and prevent response caching.

On a POST request the view resolves the authenticated user via get_resolved_user(), queries Provider for all records the user has read permission for, and returns them serialised as a JSON object.

Response shape:

{
    "providers": [
        {
            "id": 1,
            "name": "OpenAI",
            "base_url": "https://api.openai.com/v1"
        }
    ]
}

Additional provider objects may appear in the providers array.

dispatch(request, *args, **kwargs)

Dispatch the request, redirecting to login if the user is anonymous.

Parameters:

request (HttpRequest) – The HTTP request object.

Returns:

An HttpResponse object.

Return type:

HttpResponse

property formatted_class_name: str

Returns a formatted string of the class name for logging purposes.

post(request, *args, **kwargs)[source]

Handle POST requests to retrieve LLM providers accessible to the authenticated user.

Parameters:
  • request (HttpRequest) – The incoming HTTP POST request from the client.

  • args – Additional positional arguments forwarded by the URL dispatcher.

  • kwargs – Additional keyword arguments forwarded by the URL dispatcher.

Returns:

A JSON response containing the list of accessible LLM providers.

Return type:

JsonResponse