DIAL SDK reference
DIAL SDK is a Python framework for building Custom Apps and model adapters that plug into the DIAL platform. It wraps FastAPI and handles the Unified API contract — streaming, error formatting, auth header propagation, and telemetry — so you can focus on application logic.
In this section
- DIALApp — register handlers, configure middleware, and serve the application
- Chat completion — completion handlers, requests, responses, choices, and stages
- Embeddings — implement and serve an embedding handler
- Telemetry — emit OpenTelemetry traces, metrics, and logs
Installation
Install the base package:
pip install aidial-sdk
To include OpenTelemetry support for traces, metrics, and logs:
pip install "aidial-sdk[telemetry]"
Python version: 3.10 or later.
What the SDK handles for you
You implement one method. The SDK takes care of the contract around it:
- The Unified API surface — it creates the routes DIAL Core calls, parses incoming requests, and serializes what you produce, whether the client asked for a streamed or a single response. See DIALApp and Chat completion.
- Auth propagation — calls your app makes back to DIAL Core can carry the caller's key, so downstream deployments see the original user. See DIALApp.
- Telemetry — optional OpenTelemetry traces, metrics, and logs. See Telemetry.
Quick example
A minimal echo app that repeats the user's last message:
import uvicorn
from aidial_sdk import DIALApp
from aidial_sdk.chat_completion import ChatCompletion, Request, Response
class EchoApplication(ChatCompletion):
async def chat_completion(
self, request: Request, response: Response
) -> None:
last_message = request.messages[-1]
with response.create_single_choice() as choice:
choice.append_content(last_message.text())
app = DIALApp()
app.add_chat_completion("echo", EchoApplication())
if __name__ == "__main__":
uvicorn.run(app, port=5000)
Source repository
The SDK source code and additional examples are available at github.com/epam/ai-dial-sdk.