> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abv.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Query Data via SDKs

You can query data via: [SDKs](./#sdks) and [API](/developer/platform/api-data-platform/public-api). For export functionality, see [Export Data](/developer/platform/api-data-platform/overview).

Common use cases:

* Train or [fine-tune](/developer/platform/api-data-platform/export-for-fine-tuning) models on the production traces in ABV. E.g. to create a small model after having used a large model in production for a specific use case.
* Collect few-shot examples to improve quality of output.
* Programmatically create [datasets](/developer/evaluations/datasets).

<Info>
  New data is typically available for querying within 15-30 seconds of ingestion, though processing times may vary at times. Please visit [status page](https://status.abv.dev/) if you encounter any issues.
</Info>

# SDKs

Via the [SDKs](/developer/sdks/overview) for Python and JS/TS you can easily query the API without having to write the HTTP requests yourself.

## Python SDK

```bash theme={null}
pip install abvdev
```

```python theme={null}
from abvdev import ABV

abv = ABV(
    api_key="sk-abv-...", # your api key here
    host="https://app.abv.dev", # host="https://eu.app.abv.dev", for EU region
)
```

The `api` namespace is auto-generated from the Public API (OpenAPI). Method names mirror REST resources and support filters and pagination.

### **Traces**

```python theme={null}
traces = abv.api.trace.list(limit=100, user_id="user_123", tags=["production"])  # pagination via cursor
trace = abv.api.trace.get("traceId")
```

### **Observations**

```python theme={null}
observations = abv.api.observations.get_many(trace_id="abcdef1234", type="GENERATION", limit=100)
observation = abv.api.observations.get("observationId")
```

### Sessions

```python theme={null}
sessions = abv.api.sessions.list(limit=50)
```

### Scores

```python theme={null}
abv.api.score_v_2.get(score_ids = "ScoreId")
```

### Prompts

Please refer to the [prompt management documentation](/developer/prompt-management/get-started) on fetching prompts.

### Datasets

```python theme={null}
# Namespaces:
# - abv.api.datasets.*
# - abv.api.dataset_items.*
# - abv.api.dataset_run_items.*
```

### Metrics

```python theme={null}
query = """
{
  "view": "traces",
  "metrics": [{"measure": "count", "aggregation": "count"}],
  "dimensions": [{"field": "name"}],
  "filters": [],
  "fromTimestamp": "2025-05-01T00:00:00Z",
  "toTimestamp": "2025-05-13T00:00:00Z"
}
"""
 
abv.api.metrics.metrics(query = query)
```

### Async equivalents

```python theme={null}
# All endpoints are also available as async under `async_api`:
trace = await abv.async_api.trace.get("traceId")
traces = await abv.async_api.trace.list(limit=100)
```

### Common filtering & pagination

* limit, cursor (pagination)
* time range filters (e.g., start\_time, end\_time)
* entity filters: user\_id, session\_id, trace\_id, type, name, tags, level, etc.

See the Public API for the exact parameters per resource.

## JS/TS SDK

<Info>
  The dedicated `fetch*` methods for core entities are covered by tests and semantic versioning. The methods on the `abv.api` are auto-generated from the API reference and cover all entities.
</Info>

```bash theme={null}
npm install @abvdev/client
```

**Environment variables**

Add your ABV credentials as environment variables, e.g. use .env file and dotenv package to load variable values.

```bash theme={null}
npm install dotenv
```

```bash title=".env" theme={null}
ABV_API_KEY="sk-abv-..."
ABV_BASEURL="https://app.abv.dev" # US region
# ABV_BASEURL="https://eu.app.abv.dev" # EU region
```

```typescript theme={null}
import { ABVClient } from "@abvdev/client";
 
const abv = new ABVClient();
```

**alternatively use Constructor parameters**

```typescript theme={null}
import { ABVClient } from "@abvdev/client";
 
const abv = new ABVClient({
  apiKey: "sk-abv-...",
  baseUrl: "https://app.abv.dev", // US region
  // baseUrl: "https://eu.app.abv.dev", // EU region
});
```

**Use api**

```typescript theme={null}
import { ABVClient } from "@abvdev/client";
import dotenv from "dotenv";
dotenv.config();
 
const abv = new ABVClient();
 
async function main() {
  // Fetch list of traces, supports filters and pagination
  const traces = await abv.api.trace.list();
    
  // Fetch a single trace by ID
  const trace = await abv.api.trace.get("traceId");
   
  // Fetch list of observations, supports filters and pagination
  const observations = await abv.api.observations.getMany();
    
  // Fetch a single observation by ID
  const observation = await abv.api.observations.get("observationId");
    
  // Fetch list of sessions
  const sessions = await abv.api.sessions.list();
    
  // Fetch a single session by ID
  const session = await abv.api.sessions.get("sessionId");
    
  // Fetch list of scores
  const scores = await abv.api.scoreV2.get();
    
  // Fetch a single score by ID
  const score = await abv.api.scoreV2.getById("scoreId");
    
  // Explore more entities via Intellisense
}
```

JS/TS SDK reference including all available filters:

* `fetchTraces()`
* `fetchTrace()`
* `fetchObservations()`
* `fetchObservation()`
* `fetchSessions()`
