Introduction to SDK Reference
Welcome to the Confident AI SDK reference.
What is the Confident AI SDK?
The Confident AI SDK is the official Python and TypeScript client for the Confident API. It wraps every endpoint in typed methods, so you work with objects in your own language instead of building requests by hand. It allows you to:
- Run evaluations, pull datasets, and version prompts from inside your application code
- Ingest LLM traces and spans, and read them back for debugging and monitoring
- Manage metrics, annotations, alerts, and the rest of your project data programmatically
- Administer your organization — projects, members, roles, and API keys
Every SDK method maps onto a documented API endpoint, so anything you can do over HTTP you can do here in your native language.
Prerequisites
- Python 3.9+ or Node.js 18+
- A Confident AI account. If you don't have one, sign up here.
- A project or organization API key
Install the SDK
Install the Confident AI SDK package for your language.
pip install confident-ainpm install confident-aiSet your API key
There are two kinds of API key, and which one you need depends on the resource you are reaching for. Get them from Confident AI, then set them as environment variables in the shell.
export CONFIDENT_PROJ_API_KEY="<PROJECT-API-KEY>" export CONFIDENT_ORG_API_KEY="<ORGANIZATION-API-KEY>"$env:CONFIDENT_PROJ_API_KEY = "<PROJECT-API-KEY>" $env:CONFIDENT_ORG_API_KEY = "<ORGANIZATION-API-KEY>"A project API key authenticates everything scoped to one project — datasets, prompts, traces, metrics, test runs, and the rest. An organization API key authenticates organization administration only:
organizationandprojects. Most code needs the project key alone.Create a client
One client serves every resource. It reads both environment variables when it is constructed, and each method reaches for whichever key it needs.
from confident_ai import ConfidentAI client = ConfidentAI()import { ConfidentAI } from "confident-ai"; const client = new ConfidentAI();
Resources
A resource maps to a single feature or entity in Confident AI — a dataset, metric, trace, etc. The SDK provides various methods for each resource under its own name on the client: client.datasets, client.metrics, client.traces. The SDK reference documents each resource's methods, parameters, and types in detail with examples on how to use them.
Resources come in two shapes, stateless and stateful, and the shape decides how you call them.
Stateless resources
Stateless resources offer methods that are a one-time operation. You can pass the required arguments to the method and get the result back without storing any data in memory.
annotations = client.annotations.list(page=1, page_size=25)
metric = client.metrics.get(metric_id="<METRIC-ID>")
trace = client.traces.get(trace_uuid="<TRACE-UUID>")const annotations = await client.annotations.list({ page: 1, pageSize: 25 });
const metric = await client.metrics.get("<METRIC-ID>");
const trace = await client.traces.get("<TRACE-UUID>");Stateful resources
Stateful resources are objects you can create and mutate in code. They hold the data in memory, and you can call methods directly on the object.
Here's an example of how you can create a stateful dataset and edit it in memory using the Confident AI SDK and push the changes back to the platform:
dataset = client.dataset(alias="my-dataset")
dataset.pull() # fills the object's fields from the platform
dataset.create_golden(...) # no dataset_id argument needed
dataset.push() # sends the fields the object is holdingconst dataset = client.dataset(undefined, { alias: "my-dataset" });
await dataset.pull(); // fills the object's fields from the platform
await dataset.createGolden(...); // no datasetId argument needed
await dataset.push(); // sends the fields the object is holdingThe Confident AI SDK supports three stateful resources:
| Resource | Object | Open with |
|---|---|---|
| Datasets | Dataset | client.dataset(), by id or alias |
| Prompts | Prompt | client.prompt(), by id or alias |
| Projects | Project | client.project(), by id |
These are the only resources that support stateful operations, they also provide stateless methods to perform the same operations on different entities without having to create an object for each one.
Stateful vs stateless resources
Use the stateless methods when you want a single operation or you are working across records, like listing them or creating one before you have an id. Use the stateful object when you want to make several calls against the same record, or when a method sends the fields the object is holding, like push.
You can tell the two apart by the name. The stateless methods sit under the plural name, and the stateful object comes from the singular one.
client.datasets.list() # across datasets
client.dataset(alias="my-dataset").pull() # within one datasetclient.datasets.list(); // across datasets
client.dataset(undefined, { alias: "my-dataset" }).pull(); // within one datasetAsynchronous methods
Every method is available asynchronously. In Python each method has an a_-prefixed twin that you can await for async operations. TypeScript is natively asynchronous, so every method already returns a promise.
result = await client.annotations.a_list(page=1)
await dataset.a_pull()const result = await client.annotations.list({ page: 1 });
await dataset.pull();FAQs
How is the SDK different from the Confident API?
The SDK is a typed client over the same API — same authentication, same objects, same behaviour. Reach for the SDK when you are writing Python or TypeScript, and for the API directly when you are in another language or need control over the HTTP request itself.
Which API key do I need?
The project API key, in almost every case. The organization key is only for administering the organization itself — creating and deleting projects, managing members, roles, and API keys. A client can hold both at once, and each method uses the one its resource requires.
When should I use a stateful object instead of the client?
Use an object when you are making several calls against one dataset, prompt, or project, or when a method sends stored fields rather than arguments — push is the clearest case, since it sends what the object is holding. For a single call where you already have the id, the stateless client is more direct.
Last updated on