Skip to main content
Most applications only need a small part of the package. The Inference and Embeddings facades provide a fluent, immutable interface that handles provider differences behind the scenes.

Inference

The Inference class is the main entry point for LLM interactions. It encapsulates provider complexities behind a unified, fluent interface. Namespace: Cognesy\Polyglot\Inference\Inference

Creating an Instance

Polyglot offers several ways to create an Inference instance depending on how much control you need:
You can also pass a custom driver registry to using() or fromConfig() if you have registered custom drivers:

Building a Request

All request methods return a new immutable instance, so you can safely branch configurations:
Available request methods:

Executing and Reading Results

Shortcuts execute the request and return results directly:
For lower-level control, create() returns a PendingInference without triggering execution:

Working with Responses

The InferenceResponse object provides access to all parts of the provider’s response:

Working with Streams

The InferenceStream provides several ways to consume streaming data:

Embeddings

The Embeddings class provides a unified interface for generating vector embeddings across providers. Namespace: Cognesy\Polyglot\Embeddings\Embeddings

Creating an Instance

Building a Request

Available request methods:

Executing and Reading Results

For lower-level control, create() returns a PendingEmbeddings:

Working with Responses

The EmbeddingsResponse object provides access to the embedding vectors:

Registering Custom Drivers

Inference Drivers

Custom inference drivers are registered through the InferenceDriverRegistry and passed to the runtime:

Embeddings Drivers

Custom embeddings drivers are registered through the EmbeddingsDriverRegistry and passed to the runtime:
See the Providers page for details on driver registration and factory patterns.