Eilya Chat - Flutter SDK
Official Flutter/Dart SDK for Eilya Chat -- embed an AI-powered chat widget in your Flutter app.
Installation
Add to your pubspec.yaml:
dependencies:
eilya_chat: ^1.0.0
Then run:
flutter pub get
Quick Start
import 'package:eilya_chat/eilya_chat.dart';
// Initialize with your API key
final chat = EilyaChat.initialize(
apiKey: 'eck_live_your_api_key_here',
);
// Open the chat widget (creates session automatically)
final session = await chat.open(context);
print('Session started: ${session.sessionId}');
// Send a message
try {
final reply = await chat.sendMessage(content: 'Hello!');
print('Assistant: ${reply.content}');
} on SessionExpiredException {
print('Session expired. Create a new one.');
} on RateLimitedException catch (e) {
print('Rate limited. Retry after ${e.retryAfterSeconds}s');
}
Sandbox Mode
Use a test API key (prefix eck_test_) for development. In sandbox mode:
- Messages are processed but not billed
- Responses may use mock data
final chat = EilyaChat.initialize(
apiKey: 'eck_test_your_test_key_here',
);
Configuration
final chat = EilyaChat.initialize(
apiKey: 'eck_live_...',
config: EilyaChatConfig(
brandColor: '#6366F1',
position: WidgetPosition.bottomRight,
language: 'en',
systemPrompt: 'You are a helpful assistant.',
welcomeMessage: 'Hello! How can I help you?',
timeout: Duration(seconds: 30),
),
);
Listening for Messages
Use the onMessage stream to receive real-time assistant responses:
chat.onMessage.listen((message) {
print('${message.role}: ${message.content}');
});
API Reference
EilyaChat.initialize(apiKey, config?)
Creates a new SDK instance.
getWidgetConfig()
Fetches the widget configuration from the server.
createSession()
Creates a new chat session. Returns a Session.
sendMessage(sessionId?, content, type?)
Sends a message. Returns the assistant's reply Message.
open(context?)
Opens the chat widget. Creates a session if needed. Returns a Session.
close()
Closes the chat widget. Session remains active.
dispose()
Closes the HTTP client and releases all resources. Call when done.
Error Handling
All errors extend EilyaChatException:
| Exception | Code | When |
|---|---|---|
SessionNotFoundException |
SESSION_NOT_FOUND |
Invalid session ID |
SessionExpiredException |
SESSION_EXPIRED |
Session timed out |
InvalidMessageException |
INVALID_MESSAGE |
Content is invalid |
WidgetNotFoundException |
WIDGET_NOT_FOUND |
Widget not configured |
QuotaExceededException |
QUOTA_EXCEEDED |
Account quota reached |
RateLimitedException |
RATE_LIMITED |
Too many requests |
UnauthorizedException |
UNAUTHORIZED |
Invalid API key |
ForbiddenException |
FORBIDDEN |
Access denied |
NetworkException |
NETWORK_ERROR |
Connection failure |
License
MIT -- see LICENSE for details.
Libraries
- eilya_chat
- Official Flutter/Dart SDK for Eilya Chat.