Skip to content

Commit 99e081d

Browse files
langfuse-botlangfuse-bot
andauthored
feat(api): update API spec from langfuse/langfuse efe3532 (#1425)
Co-authored-by: langfuse-bot <[email protected]>
1 parent fbac841 commit 99e081d

File tree

10 files changed

+793
-12
lines changed

10 files changed

+793
-12
lines changed

langfuse/api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
OpenAiResponseUsageSchema,
135135
OpenAiUsage,
136136
OptionalObservationBody,
137+
OrganizationApiKey,
138+
OrganizationApiKeysResponse,
137139
OrganizationProject,
138140
OrganizationProjectsResponse,
139141
OtelAttribute,
@@ -378,6 +380,8 @@
378380
"OpenAiResponseUsageSchema",
379381
"OpenAiUsage",
380382
"OptionalObservationBody",
383+
"OrganizationApiKey",
384+
"OrganizationApiKeysResponse",
381385
"OrganizationProject",
382386
"OrganizationProjectsResponse",
383387
"OtelAttribute",

langfuse/api/reference.md

Lines changed: 225 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,13 +3608,15 @@ client.observations.get_many()
36083608

36093609
**filter:** `typing.Optional[str]`
36103610

3611-
JSON string containing an array of filter conditions. When provided, this takes precedence over legacy filter parameters (userId, name, sessionId, tags, version, release, environment, fromTimestamp, toTimestamp).
3611+
JSON string containing an array of filter conditions. When provided, this takes precedence over query parameter filters (userId, name, type, level, environment, fromStartTime, ...).
3612+
3613+
## Filter Structure
36123614
Each filter condition has the following structure:
36133615
```json
36143616
[
36153617
{
36163618
"type": string, // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "boolean", "null"
3617-
"column": string, // Required. Column to filter on
3619+
"column": string, // Required. Column to filter on (see available columns below)
36183620
"operator": string, // Required. Operator based on type:
36193621
// - datetime: ">", "<", ">=", "<="
36203622
// - string: "=", "contains", "does not contain", "starts with", "ends with"
@@ -3631,6 +3633,78 @@ Each filter condition has the following structure:
36313633
}
36323634
]
36333635
```
3636+
3637+
## Available Columns
3638+
3639+
### Core Observation Fields
3640+
- `id` (string) - Observation ID
3641+
- `type` (string) - Observation type (SPAN, GENERATION, EVENT)
3642+
- `name` (string) - Observation name
3643+
- `traceId` (string) - Associated trace ID
3644+
- `startTime` (datetime) - Observation start time
3645+
- `endTime` (datetime) - Observation end time
3646+
- `environment` (string) - Environment tag
3647+
- `level` (string) - Log level (DEBUG, DEFAULT, WARNING, ERROR)
3648+
- `statusMessage` (string) - Status message
3649+
- `version` (string) - Version tag
3650+
3651+
### Performance Metrics
3652+
- `latency` (number) - Latency in seconds (calculated: end_time - start_time)
3653+
- `timeToFirstToken` (number) - Time to first token in seconds
3654+
- `tokensPerSecond` (number) - Output tokens per second
3655+
3656+
### Token Usage
3657+
- `inputTokens` (number) - Number of input tokens
3658+
- `outputTokens` (number) - Number of output tokens
3659+
- `totalTokens` (number) - Total tokens (alias: `tokens`)
3660+
3661+
### Cost Metrics
3662+
- `inputCost` (number) - Input cost in USD
3663+
- `outputCost` (number) - Output cost in USD
3664+
- `totalCost` (number) - Total cost in USD
3665+
3666+
### Model Information
3667+
- `model` (string) - Provided model name
3668+
- `promptName` (string) - Associated prompt name
3669+
- `promptVersion` (number) - Associated prompt version
3670+
3671+
### Structured Data
3672+
- `metadata` (stringObject/numberObject/categoryOptions) - Metadata key-value pairs. Use `key` parameter to filter on specific metadata keys.
3673+
3674+
### Scores (requires join with scores table)
3675+
- `scores_avg` (number) - Average of numeric scores (alias: `scores`)
3676+
- `score_categories` (categoryOptions) - Categorical score values
3677+
3678+
### Associated Trace Fields (requires join with traces table)
3679+
- `userId` (string) - User ID from associated trace
3680+
- `traceName` (string) - Name from associated trace
3681+
- `traceEnvironment` (string) - Environment from associated trace
3682+
- `traceTags` (arrayOptions) - Tags from associated trace
3683+
3684+
## Filter Examples
3685+
```json
3686+
[
3687+
{
3688+
"type": "string",
3689+
"column": "type",
3690+
"operator": "=",
3691+
"value": "GENERATION"
3692+
},
3693+
{
3694+
"type": "number",
3695+
"column": "latency",
3696+
"operator": ">=",
3697+
"value": 2.5
3698+
},
3699+
{
3700+
"type": "stringObject",
3701+
"column": "metadata",
3702+
"key": "environment",
3703+
"operator": "=",
3704+
"value": "production"
3705+
}
3706+
]
3707+
```
36343708

36353709
</dd>
36363710
</dl>
@@ -4330,6 +4404,71 @@ client.organizations.get_organization_projects()
43304404
</dl>
43314405

43324406

4407+
</dd>
4408+
</dl>
4409+
</details>
4410+
4411+
<details><summary><code>client.organizations.<a href="src/langfuse/resources/organizations/client.py">get_organization_api_keys</a>()</code></summary>
4412+
<dl>
4413+
<dd>
4414+
4415+
#### 📝 Description
4416+
4417+
<dl>
4418+
<dd>
4419+
4420+
<dl>
4421+
<dd>
4422+
4423+
Get all API keys for the organization associated with the API key (requires organization-scoped API key)
4424+
</dd>
4425+
</dl>
4426+
</dd>
4427+
</dl>
4428+
4429+
#### 🔌 Usage
4430+
4431+
<dl>
4432+
<dd>
4433+
4434+
<dl>
4435+
<dd>
4436+
4437+
```python
4438+
from langfuse.client import FernLangfuse
4439+
4440+
client = FernLangfuse(
4441+
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
4442+
x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
4443+
x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
4444+
username="YOUR_USERNAME",
4445+
password="YOUR_PASSWORD",
4446+
base_url="https://yourhost.com/path/to/api",
4447+
)
4448+
client.organizations.get_organization_api_keys()
4449+
4450+
```
4451+
</dd>
4452+
</dl>
4453+
</dd>
4454+
</dl>
4455+
4456+
#### ⚙️ Parameters
4457+
4458+
<dl>
4459+
<dd>
4460+
4461+
<dl>
4462+
<dd>
4463+
4464+
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
4465+
4466+
</dd>
4467+
</dl>
4468+
</dd>
4469+
</dl>
4470+
4471+
43334472
</dd>
43344473
</dl>
43354474
</details>
@@ -7104,13 +7243,15 @@ client.trace.list()
71047243

71057244
**filter:** `typing.Optional[str]`
71067245

7107-
JSON string containing an array of filter conditions. When provided, this takes precedence over legacy filter parameters (userId, name, sessionId, tags, version, release, environment, fromTimestamp, toTimestamp).
7246+
JSON string containing an array of filter conditions. When provided, this takes precedence over query parameter filters (userId, name, sessionId, tags, version, release, environment, fromTimestamp, toTimestamp).
7247+
7248+
## Filter Structure
71087249
Each filter condition has the following structure:
71097250
```json
71107251
[
71117252
{
71127253
"type": string, // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "boolean", "null"
7113-
"column": string, // Required. Column to filter on
7254+
"column": string, // Required. Column to filter on (see available columns below)
71147255
"operator": string, // Required. Operator based on type:
71157256
// - datetime: ">", "<", ">=", "<="
71167257
// - string: "=", "contains", "does not contain", "starts with", "ends with"
@@ -7127,6 +7268,86 @@ Each filter condition has the following structure:
71277268
}
71287269
]
71297270
```
7271+
7272+
## Available Columns
7273+
7274+
### Core Trace Fields
7275+
- `id` (string) - Trace ID
7276+
- `name` (string) - Trace name
7277+
- `timestamp` (datetime) - Trace timestamp
7278+
- `userId` (string) - User ID
7279+
- `sessionId` (string) - Session ID
7280+
- `environment` (string) - Environment tag
7281+
- `version` (string) - Version tag
7282+
- `release` (string) - Release tag
7283+
- `tags` (arrayOptions) - Array of tags
7284+
- `bookmarked` (boolean) - Bookmark status
7285+
7286+
### Structured Data
7287+
- `metadata` (stringObject/numberObject/categoryOptions) - Metadata key-value pairs. Use `key` parameter to filter on specific metadata keys.
7288+
7289+
### Aggregated Metrics (from observations)
7290+
These metrics are aggregated from all observations within the trace:
7291+
- `latency` (number) - Latency in seconds (time from first observation start to last observation end)
7292+
- `inputTokens` (number) - Total input tokens across all observations
7293+
- `outputTokens` (number) - Total output tokens across all observations
7294+
- `totalTokens` (number) - Total tokens (alias: `tokens`)
7295+
- `inputCost` (number) - Total input cost in USD
7296+
- `outputCost` (number) - Total output cost in USD
7297+
- `totalCost` (number) - Total cost in USD
7298+
7299+
### Observation Level Aggregations
7300+
These fields aggregate observation levels within the trace:
7301+
- `level` (string) - Highest severity level (ERROR > WARNING > DEFAULT > DEBUG)
7302+
- `warningCount` (number) - Count of WARNING level observations
7303+
- `errorCount` (number) - Count of ERROR level observations
7304+
- `defaultCount` (number) - Count of DEFAULT level observations
7305+
- `debugCount` (number) - Count of DEBUG level observations
7306+
7307+
### Scores (requires join with scores table)
7308+
- `scores_avg` (number) - Average of numeric scores (alias: `scores`)
7309+
- `score_categories` (categoryOptions) - Categorical score values
7310+
7311+
## Filter Examples
7312+
```json
7313+
[
7314+
{
7315+
"type": "datetime",
7316+
"column": "timestamp",
7317+
"operator": ">=",
7318+
"value": "2024-01-01T00:00:00Z"
7319+
},
7320+
{
7321+
"type": "string",
7322+
"column": "userId",
7323+
"operator": "=",
7324+
"value": "user-123"
7325+
},
7326+
{
7327+
"type": "number",
7328+
"column": "totalCost",
7329+
"operator": ">=",
7330+
"value": 0.01
7331+
},
7332+
{
7333+
"type": "arrayOptions",
7334+
"column": "tags",
7335+
"operator": "all of",
7336+
"value": ["production", "critical"]
7337+
},
7338+
{
7339+
"type": "stringObject",
7340+
"column": "metadata",
7341+
"key": "customer_tier",
7342+
"operator": "=",
7343+
"value": "enterprise"
7344+
}
7345+
]
7346+
```
7347+
7348+
## Performance Notes
7349+
- Filtering on `userId`, `sessionId`, or `metadata` may enable skip indexes for better query performance
7350+
- Score filters require a join with the scores table and may impact query performance
71307351

71317352
</dd>
71327353
</dl>

langfuse/api/resources/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@
193193
MembershipResponse,
194194
MembershipRole,
195195
MembershipsResponse,
196+
OrganizationApiKey,
197+
OrganizationApiKeysResponse,
196198
OrganizationProject,
197199
OrganizationProjectsResponse,
198200
)
@@ -399,6 +401,8 @@
399401
"OpenAiResponseUsageSchema",
400402
"OpenAiUsage",
401403
"OptionalObservationBody",
404+
"OrganizationApiKey",
405+
"OrganizationApiKeysResponse",
402406
"OrganizationProject",
403407
"OrganizationProjectsResponse",
404408
"OtelAttribute",

0 commit comments

Comments
 (0)