API Reference

The Proxy passthrough endpoint, /api/v1/proxy/<name>/<path>, and the list of the Proxies that a caller may use, /api/v1/proxy/. They are enabled when SMARTER_ENABLE_PROXY is true, which is the default.

Proxy api/v1/proxy views: the Proxy passthrough.

  • GET proxy/: the Proxies that the caller may use.

  • <METHOD> proxy/<name>/<path>: forward the request to the Proxy’s provider, at <baseUrl><path>, with the provider’s API key, and return the provider’s response.

The caller authenticates with a Smarter API key, in any of the headers that LLM SDKs use. See smarter.apps.proxy.authentication.

class smarter.apps.proxy.api.v1.views.ProxyListView(**kwargs)[source]

Bases: ProxyApiViewBase

The Proxies that the caller may use, with their URLs.

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

Return the Proxies that the caller may use, ordered by name.

Parameters:

request (Request) – The authenticated request.

Returns:

A ProxyApiProxies document, as JSON.

class smarter.apps.proxy.api.v1.views.ProxyPassthroughView(**kwargs)[source]

Bases: ProxyApiViewBase

Forward a request to a Proxy’s provider, and return its response, as it is.

Errors of Smarter’s own, e.g. an unknown Proxy, are JSON, in the shape that the OpenAI and Anthropic SDKs report: {"error": {"message": ..., "type": "smarter_proxy_error", "code": ...}}.

delete(request, name, path='', *args, **kwargs)[source]

Forward a DELETE request: see passthrough().

Parameters:
  • request (Request) – The request.

  • name (str) – The Proxy’s name.

  • path (str) – The provider API path.

Returns:

The provider’s response.

get(request, name, path='', *args, **kwargs)[source]

Forward a GET request: see passthrough().

Parameters:
  • request (Request) – The request.

  • name (str) – The Proxy’s name.

  • path (str) – The provider API path.

Returns:

The provider’s response.

http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options']
passthrough(request, name, path='')[source]

Forward the request to the named Proxy’s provider, and return the provider’s response.

Parameters:
  • request (Request) – The authenticated request, whose method, query string, headers and body are forwarded.

  • name (str) – The Proxy’s name, from the url.

  • path (str) – The provider API path after the Proxy’s name, from the url.

Return type:

HttpResponseBase

Returns:

The provider’s response, or a JSON error response when the Proxy cannot be resolved or the forward fails with a ProxyError.

patch(request, name, path='', *args, **kwargs)[source]

Forward a PATCH request: see passthrough().

Parameters:
  • request (Request) – The request.

  • name (str) – The Proxy’s name.

  • path (str) – The provider API path.

Returns:

The provider’s response.

post(request, name, path='', *args, **kwargs)[source]

Forward a POST request: see passthrough().

Parameters:
  • request (Request) – The request.

  • name (str) – The Proxy’s name.

  • path (str) – The provider API path.

Returns:

The provider’s response.

put(request, name, path='', *args, **kwargs)[source]

Forward a PUT request: see passthrough().

Parameters:
  • request (Request) – The request.

  • name (str) – The Proxy’s name.

  • path (str) – The provider API path.

Returns:

The provider’s response.

URL configuration for the Proxy passthrough.

These are mounted at /api/v1/proxy/, if SMARTER_ENABLE_PROXY is true. See smarter.apps.proxy.api.v1.views.

class smarter.apps.proxy.api.v1.urls.ProxyApiV1ReverseViews[source]

Bases: object

Reverse view names for the Proxy passthrough.

Example

from django.urls import reverse
url = reverse(
    f"{ProxyApiV1ReverseViews.namespace}:{ProxyApiV1ReverseViews.passthrough}",
    kwargs={"name": "openai", "path": "chat/completions"},
)
list_view = 'proxy_list_view'
namespace = 'api:v1:proxy'
passthrough = 'proxy_passthrough_view'
passthrough_root = 'proxy_passthrough_view_root'