ai_clients 0.3.0 copy "ai_clients: ^0.3.0" to clipboard
ai_clients: ^0.3.0 copied to clipboard

A Dart package providing a unified interface for interacting with various AI models through different clients.

AI Clients Package #

pub package

A Dart package providing a unified interface for interacting with various AI models (OpenAI, Baseten, Together) through simple, consistent clients.


Features #

  • Unified interface for multiple AI providers (OpenAI, Baseten, Together)
  • Simple, async API for chat/completion models
  • Easy integration with your Dart or Flutter projects
  • Supports custom API endpoints and models
  • Extensible: add your own AI client by implementing the interface

Getting Started #

Installation #

Add ai_clients to your pubspec.yaml dependencies:

dependencies:
  ai_clients: ^0.1.0

Then run:

dart pub get

Usage #

Import the package and create an instance of the desired client. Each client requires an API key, which can be provided as a constructor argument or via environment variable.

Example: Baseten #

import 'package:ai_clients/ai_clients.dart';

void main() async {
  var client = AiClients.baseten(); // Uses BASETEN_API_KEY from env by default
  var response = await client.query(prompt: 'Hello, how are you?');
  print(response);
}

Example: Together #

import 'package:ai_clients/ai_clients.dart';

void main() async {
  var client = AiClients.together(); // Uses TOGETHER_API_KEY from env by default
  var response = await client.query(prompt: 'Hello, how are you?');
  print(response);
}

Example: OpenAI #

import 'package:ai_clients/ai_clients.dart';

void main() async {
  var client = AiClients.openAi(apiKey: 'YOUR_OPENAI_API_KEY');
  var response = await client.query(
    prompt: 'Hello, how are you?',
    model: 'gpt-4.1', // Optional, defaults to 'gpt-4.1'
  );
  print(response);
}

API Reference #

All clients implement the following interface:

Future<String> query({
  required String prompt,
  String? system,   // Optional system message (role)
  String? context,  // Optional context to append
  String model,     // Model name (default varies by client)
});
  • prompt: The user message to send to the model.
  • system: (Optional) System or developer message for context/instructions.
  • context: (Optional) Additional context appended to the prompt.
  • model: (Optional) Model name. Each client has a sensible default.

API Key Environment Variables #

  • BasetenClient: BASETEN_API_KEY
  • OpenAiClient: OPENAI_API_KEY
  • TogetherClient: TOGETHER_API_KEY

You can also pass the API key directly to the client constructor.


Available Clients #

  • BasetenClient (default model: meta-llama/Llama-4-Maverick-17B-128E-Instruct)
  • OpenAiClient (default model: gpt-4.1)
  • TogetherClient (default model: meta-llama/Llama-3.3-70B-Instruct-Turbo-Free)

Contributing #

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.


Author #

👤 Martin Jablečník


Show your support #

Give a ⭐️ if this project helped you!


📝 License #

Copyright © 2025 Martin Jablečník. This project is MIT License licensed.

0
likes
0
points
21
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package providing a unified interface for interacting with various AI models through different clients.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio

More

Packages that depend on ai_clients