Skip to content

Generate a Dart and Flutter SDK for your API

Octri generates a Dart package for your API with typed models for Flutter apps and Dart servers, publishes it to pub.dev under your package name, and regenerates it whenever your API changes.

Start from scratch

Or upload a file: OpenAPI 3.0 or 3.1, Swagger 2.0, Postman or AsyncAPI.

Install from pub.dev
flutter pub add acme_api

The Dart API client your users get

What your users write once the Dart package is installed.

Two call styles come out of the same generator. class-namespaced is the default: one client object with operations grouped by resource, the shape most popular SDKs use and the one your API reference already shows. functions is the alternative: no client object, one configure call, and each operation imported on its own. It is one setting per language, and nothing else about the client changes with it.

Parameters are named, and every call returns a Future or a Stream, so it drops into a FutureBuilder or a StreamBuilder in a Flutter widget without an adapter.

Published to pub.dev under your own publisher. The same package installs with dart pub add in a server or CLI and flutter pub add in an app.

Dart
import 'package:acme_api/acme_api.dart';

final acme = Acme(ClientConfig(
  baseUrl: 'https://api.acme.com/v1',
  auth: ClientAuthConfig(bearer: token),
));

// listPaginated is a lazy Stream. await for asks for the next page on demand.
await for (final user in acme.users.listPaginated(limit: 100)) {
  print(user.id);
}

final invoice = await acme.invoices.create(customerId: 'cus_123', amountCents: 4900);

The Dart SDK at a glance

What a developer checks before adding the Dart package to a project.

Runs on
Dart 3; Flutter on iOS, Android, macOS, Windows and Linux
Transport
dart:io HttpClient
Runtime dependencies
None
Models
Immutable classes with fromJson, no build_runner step
Pagination
Lazy Stream, consumed with await for
Ships to
pub.dev, for dart pub and flutter pub

When a call fails

Each common status is its own subclass, so on clauses read like the cases a screen has to handle. A declared error model is decoded onto e.data for an is check.

Typed errors
try {
  await acme.invoices.create(customerId: 'cus_123', amountCents: 4900);
} on SdkRateLimitError {
  // 429 after the built-in retries. Show a retry button.
} on SdkHttpError catch (e) {
  print('acme failed: ${e.statusCode} request ${e.requestId}');
}

Configure your Dart SDK

Dart has no engine or data-model setting. Models are plain Dart, so your users never run code generation of their own.

  • Client style

    class-namespaced (default), class, namespaced, functions

    A client object with a field per resource, easy to hand to a Provider or a Riverpod provider. Functions are top-level and read a global SdkConfig.

  • Argument style

    positional (default), object

    Named parameters, required where your API says required, which is the Dart idiom. Object collects them into a request class.

  • Doc comments

    full (default), minimal

    Full writes dartdoc, which feeds the documentation share of your pub points score. Keep it on full.

Method naming and namespacing work the same in every language: operations are grouped by your API’s tags or by path, and the namespace word is dropped from the method name unless you ask to keep the operationId whole.

Publishing to pub.dev: names are lowercase, underscored and permanent

Package names on pub.dev are global, use underscores (hyphens are not allowed) and stay yours for good. A version can be retracted within seven days, which discourages new resolution but does not free the number. Choose the name and check the first version on a device before you publish.

pub.dev package name
acme_api
  • Not possible: Put a hyphen in the name
  • Not possible: Reuse a version number
  • Still possible: Retract a version within seven days

Retries, pagination and typed errors, built in

The parts nobody wants to hand-write, and the parts a hand-written client usually skips.

  • Retries with exponential backoff and jitter, on the statuses that mean "try again", with a per-attempt timeout.
  • Idempotency keys on the methods that need them, so a retried write does not become two.
  • Auth wired in from your API’s security schemes, read from wherever your users keep secrets.
  • Typed errors split by cause: a failed constraint, an HTTP status, a network failure and a timeout are four different things.
  • Pagination that follows whichever style your API uses, cursor, offset, page number or next URL, without prefetching the collection.
  • Server-sent events as a native stream, for the operations that stream.
  • Error reporting to Octri’s monitoring, pre-wired and switched off until a consumer opts in.
  1. Add your API

    Upload an OpenAPI or Swagger file, paste a URL, connect the repository it lives in, or add endpoints in the editor.

  2. Read the audit

    Octri scores your API out of 10 on what a generator can do with it and names every missing schema and clashing operationId. 8 of the 14 rules come with a button that writes the fix.

  3. Shape the client

    Client style, argument style, namespacing, auth, retries and pagination, set once for the project and overridden per language or per endpoint.

  4. Generate and read it

    The package is generated, compiled and handed to you as source you can read before anyone installs it.

  5. Publish, then keep publishing

    Release to the registry under your own account. Every later change to your API regenerates the client, and the version number follows the version your API declares.

Dart SDK generator questions

OpenAPI Generator’s dart-dio generator makes a Dio client with built_value models by default, and swagger_dart_code_generator builds Chopper clients and json_serializable models through build_runner. Both leave the package and its pub.dev releases to you. Octri generates a Dart package on dart:io’s HttpClient with no runtime dependencies or build_runner step, publishes it to pub.dev, and regenerates it when your API changes.