diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 365891bd..b261bffc 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,19 +1,19 @@ lockVersion: 2.0.0 id: c48cf606-fb42-4a45-9c23-8f0555307828 management: - docChecksum: e5a84141836f41ab3cfa8f0985b48b10 + docChecksum: 66ead69cb87d4e99eb39c9cd7fb430d8 docVersion: 1.0.0 speakeasyVersion: 1.787.0 generationVersion: 2.914.0 - releaseVersion: 1.1.68 - configChecksum: 4152a0e0c25d7bc564c080709f7d66af + releaseVersion: 1.1.69 + configChecksum: 3ebeede390eb7630c0577043ba9fcc8d repoURL: https://github.com/OpenRouterTeam/python-sdk.git installationURL: https://github.com/OpenRouterTeam/python-sdk.git published: true persistentEdits: - generation_id: 967e12a4-0f46-45ca-b11a-71dd32cb068b - pristine_commit_hash: 77b0b4ba30336bbd09b0e7e531ff7de39df32ada - pristine_tree_hash: bc609fedc5c5fecbfe46eb7b6b73d141edf97427 + generation_id: c30f667c-3a6f-463e-80a7-b3c79189080a + pristine_commit_hash: ed707642d7c21d53bdd56099f5fb01907acae638 + pristine_tree_hash: b0b009b2f83449213836d1a490902659f5411f39 features: python: acceptHeaders: 3.0.0 @@ -7138,8 +7138,8 @@ trackedFiles: pristine_git_object: f265978fdb338b412232349476bf1e874833c9f8 docs/sdks/analytics/README.mdx: id: 281aa5320be1 - last_write_checksum: sha1:1a3d4c929ad50c2b7f24ced91d0646e6cc9f7d1b - pristine_git_object: 18befad2161aca4ee4359420ba14b7affccf7ec9 + last_write_checksum: sha1:057c1d5bb828df9d8006c27e9fdde1122c0242db + pristine_git_object: c1634706646332455817340f5891b4b5c9c6d16c docs/sdks/apikeys/README.mdx: id: 27fcaae1c346 last_write_checksum: sha1:b8bd517a7a2960d003ab350130008b402927af6b @@ -7148,10 +7148,6 @@ trackedFiles: id: 5b483a6770ba last_write_checksum: sha1:885b70fcbd2be60f51a2f58e133fd6452eb21600 pristine_git_object: 5026ac2a283240480026d80d2f77d5528ae8bdc8 - docs/sdks/betaanalytics/README.mdx: - id: 239279ebf01b - last_write_checksum: sha1:5a76d28d77f68efe34ebbcb72850e6a87c74d3b1 - pristine_git_object: 6e4b06ff97f02da5d31d78f478094db32dfdaa6f docs/sdks/betaresponses/README.mdx: id: 8a1e987c9840 last_write_checksum: sha1:da17b27cff3d9a1d9a82e6a270fe2acce62ec028 @@ -7258,8 +7254,8 @@ trackedFiles: pristine_git_object: 3e38f1a929f7d6b1d6de74604aa87e3d8f010544 pyproject.toml: id: 5d07e7d72637 - last_write_checksum: sha1:1129f51029e6ef9115ee477f4842379091278622 - pristine_git_object: 0fab43d82de5817438199b28da34301274d8f6ec + last_write_checksum: sha1:426f3411cd419d756ebbab88f015e6e10552b221 + pristine_git_object: 6b21ff40c675a234c89d4bb9f986a46326e8f13b scripts/prepare_readme.py: id: e0c5957a6035 last_write_checksum: sha1:77f44b60b98bc126557ec27391f91dfba764bb54 @@ -7286,12 +7282,12 @@ trackedFiles: pristine_git_object: 86713cfea633e09d33b3d4e65281071fe20e6137 src/openrouter/_version.py: id: d8d15ad6c586 - last_write_checksum: sha1:88df9bb9f5ff147542e70dab5210a04529c08d11 - pristine_git_object: 211121c2e78927b4c01979bf40690afef6d18adc + last_write_checksum: sha1:1d207c6f701041fcec19305a1e0e492ea64b6638 + pristine_git_object: 65183dd35e706d54c02feec510777db21bbb55c0 src/openrouter/analytics.py: id: cb406b5aaabb - last_write_checksum: sha1:3ea0f1c73fb9c101b7bc5719da4dd7bf62ff469a - pristine_git_object: ddd0b3f6c78a94ed829bb1c6dbf30bbacce7e517 + last_write_checksum: sha1:1e0004d8d1d5d797e2b54cd1cabeb7f9489d08e9 + pristine_git_object: 9587309db4d5e25a00131a48788456139c25e4c0 src/openrouter/api_keys.py: id: 876fac88fff6 last_write_checksum: sha1:ada03aff96976f0570e594a3143595c25ca05f18 @@ -7306,12 +7302,8 @@ trackedFiles: pristine_git_object: f163fcbb9c21fc1327d6c9a1eefcc60cbf9091ea src/openrouter/beta.py: id: fffdf54fd8f5 - last_write_checksum: sha1:4e34fb96ffe38673ca72e0f8576a8eddd4134d4b - pristine_git_object: 6def81a950b22cb1245b0b6b76c05a8d81fedaf8 - src/openrouter/beta_analytics.py: - id: 81988b170188 - last_write_checksum: sha1:517ca1b0d4b94343e7728f156230e653f43c4641 - pristine_git_object: 1b01f0c081ffc8a42fa56d335f95ec3121e4b5e6 + last_write_checksum: sha1:21fb1d65cd9800c65c7a2ae520619002976e37cd + pristine_git_object: aa95a65cf560fd7edb0c3c6f5fed707ca5015da3 src/openrouter/beta_responses.py: id: 001eaf848bf1 last_write_checksum: sha1:cf864ff8c66d5177ac5b73ca38ddafdd77f69755 @@ -10342,8 +10334,8 @@ trackedFiles: pristine_git_object: f6ad93a8202863708520f9fdb7043eeb4f1f1fc6 src/openrouter/sdk.py: id: ee9846c4c9c5 - last_write_checksum: sha1:8bf6e1e1ddf2593219cdd9aa964a017ec68a0748 - pristine_git_object: b00e07cd484d49e193c7bfe5fb822dbf4fe95406 + last_write_checksum: sha1:78519ae3116f7cdc82ed2c757f019a663f216baa + pristine_git_object: 4dca8972da6ac87832ef3c3c8dcca9001256197e src/openrouter/sdkconfiguration.py: id: 55773bb98d7c last_write_checksum: sha1:c01826125c31a8b8bc99d9d679782c8758fae001 @@ -12183,4 +12175,9 @@ examples: "500": application/json: {"error": {"code": 500, "message": "Internal Server Error"}} examplesVersion: 1.0.2 -releaseNotes: "## Python SDK Changes:\n* `open_router.beta.responses.send()`: \n * `request.input.union(Array<>)[].union(ReasoningItem).format.enum(bedrock_xai_responses_v1)` **Added**\n * `response` **Changed**\n* `open_router.chat.send()`: \n * `request.messages[].union(assistant).reasoning_details[].union(reasoning.server_tool_call).format.enum(bedrock_xai_responses_v1)` **Added**\n * `response` **Changed**\n* `open_router.presets.create_presets_chat_completions()`: \n * `request.messages[].union(assistant).reasoning_details[].union(reasoning.summary).format.enum(bedrock_xai_responses_v1)` **Added**\n* `open_router.presets.create_presets_responses()`: \n * `request.input.union(Array<>)[].union(ReasoningItem).format.enum(bedrock_xai_responses_v1)` **Added**\n* `open_router.responses.send()`: \n * `request.input.union(Array<>)[].union(class (8)).format.enum(bedrock_xai_responses_v1)` **Added**\n * `response` **Changed**\n" +releaseNotes: | + ## Python SDK Changes: + * `open_router.analytics.get_analytics_meta()`: **Added** + * `open_router.analytics.query_analytics()`: **Added** + * `open_router.beta.analytics.get_analytics_meta()`: **Removed** (Breaking ⚠️) + * `open_router.beta.analytics.query_analytics()`: **Removed** (Breaking ⚠️) diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index d44f0ad5..34dd9dfe 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -36,7 +36,7 @@ generation: documentation: mintlify preApplyUnionDiscriminators: true python: - version: 1.1.68 + version: 1.1.69 additionalDependencies: dev: {} main: {} diff --git a/.speakeasy/out.openapi.yaml b/.speakeasy/out.openapi.yaml index cc48cfcc..904d87a4 100644 --- a/.speakeasy/out.openapi.yaml +++ b/.speakeasy/out.openapi.yaml @@ -26945,7 +26945,7 @@ paths: description: 'Internal Server Error - Unexpected server error' summary: 'Get available analytics metrics and dimensions' tags: - - 'beta.Analytics' + - 'Analytics' parameters: - $ref: "#/components/parameters/AppIdentifier" - $ref: "#/components/parameters/AppDisplayName" @@ -27228,7 +27228,7 @@ paths: description: 'Internal Server Error - Unexpected server error' summary: 'Query analytics data' tags: - - 'beta.Analytics' + - 'Analytics' parameters: - $ref: "#/components/parameters/AppIdentifier" - $ref: "#/components/parameters/AppDisplayName" @@ -39501,8 +39501,6 @@ tags: name: 'Video Generation' - description: 'Workspaces endpoints' name: 'Workspaces' - - description: 'beta.Analytics endpoints' - name: 'beta.Analytics' - name: beta.responses deprecated: true description: Deprecated alias for responses endpoints. Use responses instead. Scheduled for removal (sunset date TBD). diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index c755c66d..1da3317c 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -2,8 +2,8 @@ speakeasyVersion: 1.787.0 sources: OpenRouter API: sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:d08cdef4608b7c5dd9f20c684a6787f5a14d39ff9560563bcff8bcf3ab076801 - sourceBlobDigest: sha256:f260ae75660108165f0acd3765ff407373c8771cd584a8126fe3253fa98a8452 + sourceRevisionDigest: sha256:e536fc1c3b7c04a2658aaf8c04d463b1551f3a0f4fd7e9cc2fa971fea8d1f355 + sourceBlobDigest: sha256:10c4cd7804672e0d6af7e44b5aaae19596fe24e7432e829ddbad15c0d88ed5cd tags: - latest - 1.0.0 @@ -11,10 +11,10 @@ targets: open-router: source: OpenRouter API sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:d08cdef4608b7c5dd9f20c684a6787f5a14d39ff9560563bcff8bcf3ab076801 - sourceBlobDigest: sha256:f260ae75660108165f0acd3765ff407373c8771cd584a8126fe3253fa98a8452 + sourceRevisionDigest: sha256:e536fc1c3b7c04a2658aaf8c04d463b1551f3a0f4fd7e9cc2fa971fea8d1f355 + sourceBlobDigest: sha256:10c4cd7804672e0d6af7e44b5aaae19596fe24e7432e829ddbad15c0d88ed5cd codeSamplesNamespace: open-router-python-code-samples - codeSamplesRevisionDigest: sha256:2773d5a61873cfd717736da5f244c65d4f6d0d1a678b2d3e1cb246be78fbc485 + codeSamplesRevisionDigest: sha256:53fdb413e77445b07c5791391f3a5a3cf21c1d10c43f8eb755f382d3a6d6125c workflow: workflowVersion: 1.0.0 speakeasyVersion: 1.787.0 diff --git a/RELEASES.md b/RELEASES.md index 6ea03f32..8d56b350 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1469,4 +1469,14 @@ Based on: ### Generated - [python v1.1.68] . ### Releases -- [PyPI v1.1.68] https://pypi.org/project/openrouter/1.1.68 - . \ No newline at end of file +- [PyPI v1.1.68] https://pypi.org/project/openrouter/1.1.68 - . + +## 2026-08-20 18:12:08 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.787.0 (2.914.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.1.69] . +### Releases +- [PyPI v1.1.69] https://pypi.org/project/openrouter/1.1.69 - . \ No newline at end of file diff --git a/docs/docs.json b/docs/docs.json index 918adb36..0e245732 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -13,7 +13,6 @@ "sdks/analytics/README", "sdks/apikeys/README", "sdks/benchmarks/README", - "sdks/betaanalytics/README", "sdks/betaresponses/README", "sdks/byok/README", "sdks/chat/README", diff --git a/docs/sdks/analytics/README.mdx b/docs/sdks/analytics/README.mdx index 18befad2..c1634706 100644 --- a/docs/sdks/analytics/README.mdx +++ b/docs/sdks/analytics/README.mdx @@ -10,6 +10,8 @@ Analytics and usage endpoints ### Available Operations * [get_user_activity](#get_user_activity) - Get user activity grouped by endpoint +* [get_analytics_meta](#get_analytics_meta) - Get available analytics metrics and dimensions +* [query_analytics](#query_analytics) - Query analytics data ## get_user_activity @@ -56,4 +58,118 @@ with OpenRouter( | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | +| errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | + +## get_analytics_meta + +Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint. [Management key](/docs/guides/overview/auth/management-api-keys) required. + +### Example Usage + +```python +from openrouter import OpenRouter +import os + + +with OpenRouter( + http_referer="", + x_open_router_title="", + x_open_router_categories="", + api_key=os.getenv("OPENROUTER_API_KEY", ""), +) as open_router: + + res = open_router.analytics.get_analytics_meta() + + # Handle response + print(res) + +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | +| `http_referer` | *Optional[str]* | :heavy_minus_sign: | The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
| +| `x_open_router_title` | *Optional[str]* | :heavy_minus_sign: | The app display name allows you to customize how your app appears in OpenRouter's dashboard.
| +| `x_open_router_categories` | *Optional[str]* | :heavy_minus_sign: | Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
| +| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.mdx) | :heavy_minus_sign: | Configuration to override the default retry behavior of the client. | + +### Response + +**[operations.GetAnalyticsMetaResponse](../../operations/getanalyticsmetaresponse.mdx)** + +### Errors + +| Error Type | Status Code | Content Type | +| ---------------------------------- | ---------------------------------- | ---------------------------------- | +| errors.UnauthorizedResponseError | 401 | application/json | +| errors.ForbiddenResponseError | 403 | application/json | +| errors.InternalServerResponseError | 500 | application/json | +| errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | + +## query_analytics + +Execute an analytics query with specified metrics, dimensions, filters, and time range. [Management key](/docs/guides/overview/auth/management-api-keys) required. + +### Example Usage + +```python +from openrouter import OpenRouter +from openrouter.utils import parse_datetime +import os + + +with OpenRouter( + http_referer="", + x_open_router_title="", + x_open_router_categories="", + api_key=os.getenv("OPENROUTER_API_KEY", ""), +) as open_router: + + res = open_router.analytics.query_analytics(metrics=[ + "request_count", + ], dimensions=[ + "model", + ], granularity="day", limit=100, time_range={ + "end": parse_datetime("2025-01-08T00:00:00Z"), + "start": parse_datetime("2025-01-01T00:00:00Z"), + }) + + # Handle response + print(res) + +``` + +### Parameters + +| Parameter | Type | Required | Description | Example | +| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `metrics` | List[*str*] | :heavy_check_mark: | N/A | | +| `http_referer` | *Optional[str]* | :heavy_minus_sign: | The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
| | +| `x_open_router_title` | *Optional[str]* | :heavy_minus_sign: | The app display name allows you to customize how your app appears in OpenRouter's dashboard.
| | +| `x_open_router_categories` | *Optional[str]* | :heavy_minus_sign: | Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
| | +| `classifier_dimensions` | [Optional[operations.ClassifierDimensions]](../../operations/classifierdimensions.mdx) | :heavy_minus_sign: | Group results by custom classifier tags, breaking down metrics by the specified dimension values. Requires an active classifier on the workspace. | | +| `classifier_filters` | [Optional[operations.ClassifierFilters]](../../operations/classifierfilters.mdx) | :heavy_minus_sign: | Filter results to generations with specific classifier tag values. Can be combined with classifier_dimensions (must use the same classifier_id) or used independently with standard dimensions. | | +| `dimensions` | List[*str*] | :heavy_minus_sign: | N/A | | +| `filters` | List[[operations.Filter](../../operations/filter_.mdx)] | :heavy_minus_sign: | N/A | | +| `granularity` | *Optional[str]* | :heavy_minus_sign: | Time granularity | day | +| `group_limit` | *Optional[int]* | :heavy_minus_sign: | Maximum rows per distinct combination of dimensions. When omitted on time-series queries (granularity + dimensions), auto-computed to avoid truncating time windows. Explicit values override the default and may truncate time buckets if set lower than the number of buckets in the range. Ignored when no dimensions are specified. | 100 | +| `limit` | *Optional[int]* | :heavy_minus_sign: | Maximum total rows returned. Defaults to 1000. On time-series queries with dimensions and no explicit group_limit, the server may raise this to accommodate the expected number of unique time-bucket/dimension combinations. | | +| `order_by` | [Optional[operations.OrderBy]](../../operations/orderby.mdx) | :heavy_minus_sign: | N/A | | +| `time_range` | [Optional[operations.TimeRange]](../../operations/timerange.mdx) | :heavy_minus_sign: | N/A | | +| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.mdx) | :heavy_minus_sign: | Configuration to override the default retry behavior of the client. | | + +### Response + +**[operations.QueryAnalyticsResponse](../../operations/queryanalyticsresponse.mdx)** + +### Errors + +| Error Type | Status Code | Content Type | +| ---------------------------------- | ---------------------------------- | ---------------------------------- | +| errors.BadRequestResponseError | 400 | application/json | +| errors.UnauthorizedResponseError | 401 | application/json | +| errors.ForbiddenResponseError | 403 | application/json | +| errors.RequestTimeoutResponseError | 408 | application/json | +| errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/docs/sdks/betaanalytics/README.mdx b/docs/sdks/betaanalytics/README.mdx deleted file mode 100644 index 6e4b06ff..00000000 --- a/docs/sdks/betaanalytics/README.mdx +++ /dev/null @@ -1,127 +0,0 @@ ---- -title: "Beta.Analytics" -description: "beta.Analytics endpoints" ---- - -## Overview - -beta.Analytics endpoints - -### Available Operations - -* [get_analytics_meta](#get_analytics_meta) - Get available analytics metrics and dimensions -* [query_analytics](#query_analytics) - Query analytics data - -## get_analytics_meta - -Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint. [Management key](/docs/guides/overview/auth/management-api-keys) required. - -### Example Usage - -```python -from openrouter import OpenRouter -import os - - -with OpenRouter( - http_referer="", - x_open_router_title="", - x_open_router_categories="", - api_key=os.getenv("OPENROUTER_API_KEY", ""), -) as open_router: - - res = open_router.beta.analytics.get_analytics_meta() - - # Handle response - print(res) - -``` - -### Parameters - -| Parameter | Type | Required | Description | -| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | -| `http_referer` | *Optional[str]* | :heavy_minus_sign: | The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
| -| `x_open_router_title` | *Optional[str]* | :heavy_minus_sign: | The app display name allows you to customize how your app appears in OpenRouter's dashboard.
| -| `x_open_router_categories` | *Optional[str]* | :heavy_minus_sign: | Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
| -| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.mdx) | :heavy_minus_sign: | Configuration to override the default retry behavior of the client. | - -### Response - -**[operations.GetAnalyticsMetaResponse](../../operations/getanalyticsmetaresponse.mdx)** - -### Errors - -| Error Type | Status Code | Content Type | -| ---------------------------------- | ---------------------------------- | ---------------------------------- | -| errors.UnauthorizedResponseError | 401 | application/json | -| errors.ForbiddenResponseError | 403 | application/json | -| errors.InternalServerResponseError | 500 | application/json | -| errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | - -## query_analytics - -Execute an analytics query with specified metrics, dimensions, filters, and time range. [Management key](/docs/guides/overview/auth/management-api-keys) required. - -### Example Usage - -```python -from openrouter import OpenRouter -from openrouter.utils import parse_datetime -import os - - -with OpenRouter( - http_referer="", - x_open_router_title="", - x_open_router_categories="", - api_key=os.getenv("OPENROUTER_API_KEY", ""), -) as open_router: - - res = open_router.beta.analytics.query_analytics(metrics=[ - "request_count", - ], dimensions=[ - "model", - ], granularity="day", limit=100, time_range={ - "end": parse_datetime("2025-01-08T00:00:00Z"), - "start": parse_datetime("2025-01-01T00:00:00Z"), - }) - - # Handle response - print(res) - -``` - -### Parameters - -| Parameter | Type | Required | Description | Example | -| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `metrics` | List[*str*] | :heavy_check_mark: | N/A | | -| `http_referer` | *Optional[str]* | :heavy_minus_sign: | The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
| | -| `x_open_router_title` | *Optional[str]* | :heavy_minus_sign: | The app display name allows you to customize how your app appears in OpenRouter's dashboard.
| | -| `x_open_router_categories` | *Optional[str]* | :heavy_minus_sign: | Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
| | -| `classifier_dimensions` | [Optional[operations.ClassifierDimensions]](../../operations/classifierdimensions.mdx) | :heavy_minus_sign: | Group results by custom classifier tags, breaking down metrics by the specified dimension values. Requires an active classifier on the workspace. | | -| `classifier_filters` | [Optional[operations.ClassifierFilters]](../../operations/classifierfilters.mdx) | :heavy_minus_sign: | Filter results to generations with specific classifier tag values. Can be combined with classifier_dimensions (must use the same classifier_id) or used independently with standard dimensions. | | -| `dimensions` | List[*str*] | :heavy_minus_sign: | N/A | | -| `filters` | List[[operations.Filter](../../operations/filter_.mdx)] | :heavy_minus_sign: | N/A | | -| `granularity` | *Optional[str]* | :heavy_minus_sign: | Time granularity | day | -| `group_limit` | *Optional[int]* | :heavy_minus_sign: | Maximum rows per distinct combination of dimensions. When omitted on time-series queries (granularity + dimensions), auto-computed to avoid truncating time windows. Explicit values override the default and may truncate time buckets if set lower than the number of buckets in the range. Ignored when no dimensions are specified. | 100 | -| `limit` | *Optional[int]* | :heavy_minus_sign: | Maximum total rows returned. Defaults to 1000. On time-series queries with dimensions and no explicit group_limit, the server may raise this to accommodate the expected number of unique time-bucket/dimension combinations. | | -| `order_by` | [Optional[operations.OrderBy]](../../operations/orderby.mdx) | :heavy_minus_sign: | N/A | | -| `time_range` | [Optional[operations.TimeRange]](../../operations/timerange.mdx) | :heavy_minus_sign: | N/A | | -| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.mdx) | :heavy_minus_sign: | Configuration to override the default retry behavior of the client. | | - -### Response - -**[operations.QueryAnalyticsResponse](../../operations/queryanalyticsresponse.mdx)** - -### Errors - -| Error Type | Status Code | Content Type | -| ---------------------------------- | ---------------------------------- | ---------------------------------- | -| errors.BadRequestResponseError | 400 | application/json | -| errors.UnauthorizedResponseError | 401 | application/json | -| errors.ForbiddenResponseError | 403 | application/json | -| errors.RequestTimeoutResponseError | 408 | application/json | -| errors.InternalServerResponseError | 500 | application/json | -| errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 0fab43d8..6b21ff40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openrouter" -version = "1.1.68" +version = "1.1.69" description = "Official Python Client SDK for OpenRouter." authors = [{ name = "OpenRouter" },] readme = "README-PYPI.md" diff --git a/src/openrouter/_version.py b/src/openrouter/_version.py index 211121c2..65183dd3 100644 --- a/src/openrouter/_version.py +++ b/src/openrouter/_version.py @@ -3,10 +3,10 @@ import importlib.metadata __title__: str = "openrouter" -__version__: str = "1.1.68" +__version__: str = "1.1.69" __openapi_doc_version__: str = "1.0.0" __gen_version__: str = "2.914.0" -__user_agent__: str = "speakeasy-sdk/python 1.1.68 2.914.0 1.0.0 openrouter" +__user_agent__: str = "speakeasy-sdk/python 1.1.69 2.914.0 1.0.0 openrouter" try: if __package__ is not None: diff --git a/src/openrouter/analytics.py b/src/openrouter/analytics.py index ddd0b3f6..9587309d 100644 --- a/src/openrouter/analytics.py +++ b/src/openrouter/analytics.py @@ -6,7 +6,7 @@ from openrouter.types import BaseModel, OptionalNullable, UNSET from openrouter.utils import get_security_from_env from openrouter.utils.unmarshal_json_response import unmarshal_json_response -from typing import Any, Mapping, Optional, Union, cast +from typing import Any, Iterable, List, Mapping, Optional, Union, cast class Analytics(BaseSDK): @@ -267,3 +267,651 @@ async def get_user_activity_async( ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) + + def get_analytics_meta( + self, + *, + http_referer: Optional[str] = None, + x_open_router_title: Optional[str] = None, + x_open_router_categories: Optional[str] = None, + retries: OptionalNullable[utils.RetryConfig] = UNSET, + server_url: Optional[str] = None, + timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, + ) -> operations.GetAnalyticsMetaResponse: + r"""Get available analytics metrics and dimensions + + Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint. [Management key](/docs/guides/overview/auth/management-api-keys) required. + + :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. + This is used to track API usage per application. + + :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. + + :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. + + :param retries: Override the default retry configuration for this method + :param server_url: Override the default server URL for this method + :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. + """ + base_url = None + url_variables = None + if timeout_ms is None: + timeout_ms = self.sdk_configuration.timeout_ms + + if server_url is not None: + base_url = server_url + else: + base_url = self._get_url(base_url, url_variables) + + request = operations.GetAnalyticsMetaRequest( + http_referer=http_referer, + x_open_router_title=x_open_router_title, + x_open_router_categories=x_open_router_categories, + ) + + req = self._build_request( + method="GET", + path="/analytics/meta", + base_url=base_url, + url_variables=url_variables, + request=request, + request_body_required=False, + request_has_path_params=False, + request_has_query_params=True, + user_agent_header="user-agent", + accept_header_value="application/json", + http_headers=http_headers, + _globals=operations.GetAnalyticsMetaGlobals( + http_referer=self.sdk_configuration.globals.http_referer, + x_open_router_title=self.sdk_configuration.globals.x_open_router_title, + x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, + ), + security=self.sdk_configuration.security, + allow_empty_value=None, + timeout_ms=timeout_ms, + ) + + if retries == UNSET: + if self.sdk_configuration.retry_config is not UNSET: + retries = self.sdk_configuration.retry_config + else: + retries = utils.RetryConfig( + "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True + ) + + retry_config = None + if isinstance(retries, utils.RetryConfig): + retry_config = (retries, ["5XX"]) + + http_res = self.do_request( + hook_ctx=HookContext( + config=self.sdk_configuration, + base_url=base_url or "", + operation_id="getAnalyticsMeta", + oauth2_scopes=None, + security_source=get_security_from_env( + self.sdk_configuration.security, components.Security + ), + tags=["Analytics"], + extensions=None, + ), + request=req, + is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c), + retry_config=retry_config, + ) + + response_data: Any = None + if utils.match_response(http_res, "200", "application/json"): + return unmarshal_json_response( + operations.GetAnalyticsMetaResponse, http_res + ) + if utils.match_response(http_res, "401", "application/json"): + response_data = unmarshal_json_response( + errors.UnauthorizedResponseErrorData, http_res + ) + raise errors.UnauthorizedResponseError(response_data, http_res) + if utils.match_response(http_res, "403", "application/json"): + response_data = unmarshal_json_response( + errors.ForbiddenResponseErrorData, http_res + ) + raise errors.ForbiddenResponseError(response_data, http_res) + if utils.match_response(http_res, "500", "application/json"): + response_data = unmarshal_json_response( + errors.InternalServerResponseErrorData, http_res + ) + raise errors.InternalServerResponseError(response_data, http_res) + if utils.match_response(http_res, "4XX", "*"): + http_res_text = utils.stream_to_text(http_res) + raise errors.OpenRouterDefaultError( + "API error occurred", http_res, http_res_text + ) + if utils.match_response(http_res, "5XX", "*"): + http_res_text = utils.stream_to_text(http_res) + raise errors.OpenRouterDefaultError( + "API error occurred", http_res, http_res_text + ) + + raise errors.OpenRouterDefaultError("Unexpected response received", http_res) + + async def get_analytics_meta_async( + self, + *, + http_referer: Optional[str] = None, + x_open_router_title: Optional[str] = None, + x_open_router_categories: Optional[str] = None, + retries: OptionalNullable[utils.RetryConfig] = UNSET, + server_url: Optional[str] = None, + timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, + ) -> operations.GetAnalyticsMetaResponse: + r"""Get available analytics metrics and dimensions + + Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint. [Management key](/docs/guides/overview/auth/management-api-keys) required. + + :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. + This is used to track API usage per application. + + :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. + + :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. + + :param retries: Override the default retry configuration for this method + :param server_url: Override the default server URL for this method + :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. + """ + base_url = None + url_variables = None + if timeout_ms is None: + timeout_ms = self.sdk_configuration.timeout_ms + + if server_url is not None: + base_url = server_url + else: + base_url = self._get_url(base_url, url_variables) + + request = operations.GetAnalyticsMetaRequest( + http_referer=http_referer, + x_open_router_title=x_open_router_title, + x_open_router_categories=x_open_router_categories, + ) + + req = self._build_request_async( + method="GET", + path="/analytics/meta", + base_url=base_url, + url_variables=url_variables, + request=request, + request_body_required=False, + request_has_path_params=False, + request_has_query_params=True, + user_agent_header="user-agent", + accept_header_value="application/json", + http_headers=http_headers, + _globals=operations.GetAnalyticsMetaGlobals( + http_referer=self.sdk_configuration.globals.http_referer, + x_open_router_title=self.sdk_configuration.globals.x_open_router_title, + x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, + ), + security=self.sdk_configuration.security, + allow_empty_value=None, + timeout_ms=timeout_ms, + ) + + if retries == UNSET: + if self.sdk_configuration.retry_config is not UNSET: + retries = self.sdk_configuration.retry_config + else: + retries = utils.RetryConfig( + "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True + ) + + retry_config = None + if isinstance(retries, utils.RetryConfig): + retry_config = (retries, ["5XX"]) + + http_res = await self.do_request_async( + hook_ctx=HookContext( + config=self.sdk_configuration, + base_url=base_url or "", + operation_id="getAnalyticsMeta", + oauth2_scopes=None, + security_source=get_security_from_env( + self.sdk_configuration.security, components.Security + ), + tags=["Analytics"], + extensions=None, + ), + request=req, + is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c), + retry_config=retry_config, + ) + + response_data: Any = None + if utils.match_response(http_res, "200", "application/json"): + return unmarshal_json_response( + operations.GetAnalyticsMetaResponse, http_res + ) + if utils.match_response(http_res, "401", "application/json"): + response_data = unmarshal_json_response( + errors.UnauthorizedResponseErrorData, http_res + ) + raise errors.UnauthorizedResponseError(response_data, http_res) + if utils.match_response(http_res, "403", "application/json"): + response_data = unmarshal_json_response( + errors.ForbiddenResponseErrorData, http_res + ) + raise errors.ForbiddenResponseError(response_data, http_res) + if utils.match_response(http_res, "500", "application/json"): + response_data = unmarshal_json_response( + errors.InternalServerResponseErrorData, http_res + ) + raise errors.InternalServerResponseError(response_data, http_res) + if utils.match_response(http_res, "4XX", "*"): + http_res_text = await utils.stream_to_text_async(http_res) + raise errors.OpenRouterDefaultError( + "API error occurred", http_res, http_res_text + ) + if utils.match_response(http_res, "5XX", "*"): + http_res_text = await utils.stream_to_text_async(http_res) + raise errors.OpenRouterDefaultError( + "API error occurred", http_res, http_res_text + ) + + raise errors.OpenRouterDefaultError("Unexpected response received", http_res) + + def query_analytics( + self, + *, + metrics: Iterable[str], + http_referer: Optional[str] = None, + x_open_router_title: Optional[str] = None, + x_open_router_categories: Optional[str] = None, + classifier_dimensions: Optional[ + Union[ + operations.ClassifierDimensions, + operations.ClassifierDimensionsTypedDict, + ] + ] = None, + classifier_filters: Optional[ + Union[operations.ClassifierFilters, operations.ClassifierFiltersTypedDict] + ] = None, + dimensions: Optional[Iterable[str]] = None, + filters: Optional[ + Union[Iterable[operations.Filter], Iterable[operations.FilterTypedDict]] + ] = None, + granularity: Optional[str] = None, + group_limit: Optional[int] = None, + limit: Optional[int] = None, + order_by: Optional[ + Union[operations.OrderBy, operations.OrderByTypedDict] + ] = None, + time_range: Optional[ + Union[operations.TimeRange, operations.TimeRangeTypedDict] + ] = None, + retries: OptionalNullable[utils.RetryConfig] = UNSET, + server_url: Optional[str] = None, + timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, + ) -> operations.QueryAnalyticsResponse: + r"""Query analytics data + + Execute an analytics query with specified metrics, dimensions, filters, and time range. [Management key](/docs/guides/overview/auth/management-api-keys) required. + + :param metrics: + :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. + This is used to track API usage per application. + + :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. + + :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. + + :param classifier_dimensions: Group results by custom classifier tags, breaking down metrics by the specified dimension values. Requires an active classifier on the workspace. + :param classifier_filters: Filter results to generations with specific classifier tag values. Can be combined with classifier_dimensions (must use the same classifier_id) or used independently with standard dimensions. + :param dimensions: + :param filters: + :param granularity: Time granularity + :param group_limit: Maximum rows per distinct combination of dimensions. When omitted on time-series queries (granularity + dimensions), auto-computed to avoid truncating time windows. Explicit values override the default and may truncate time buckets if set lower than the number of buckets in the range. Ignored when no dimensions are specified. + :param limit: Maximum total rows returned. Defaults to 1000. On time-series queries with dimensions and no explicit group_limit, the server may raise this to accommodate the expected number of unique time-bucket/dimension combinations. + :param order_by: + :param time_range: + :param retries: Override the default retry configuration for this method + :param server_url: Override the default server URL for this method + :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. + """ + base_url = None + url_variables = None + if timeout_ms is None: + timeout_ms = self.sdk_configuration.timeout_ms + + if server_url is not None: + base_url = server_url + else: + base_url = self._get_url(base_url, url_variables) + + request = operations.QueryAnalyticsRequest( + http_referer=http_referer, + x_open_router_title=x_open_router_title, + x_open_router_categories=x_open_router_categories, + request_body=operations.QueryAnalyticsRequestBody( + classifier_dimensions=utils.get_pydantic_model( + classifier_dimensions, Optional[operations.ClassifierDimensions] + ), + classifier_filters=utils.get_pydantic_model( + classifier_filters, Optional[operations.ClassifierFilters] + ), + dimensions=utils.unmarshal(dimensions, Optional[List[str]]), + filters=utils.get_pydantic_model( + filters, Optional[List[operations.Filter]] + ), + granularity=granularity, + group_limit=group_limit, + limit=limit, + metrics=utils.unmarshal(metrics, List[str]), + order_by=utils.get_pydantic_model( + order_by, Optional[operations.OrderBy] + ), + time_range=utils.get_pydantic_model( + time_range, Optional[operations.TimeRange] + ), + ), + ) + + req = self._build_request( + method="POST", + path="/analytics/query", + base_url=base_url, + url_variables=url_variables, + request=request, + request_body_required=True, + request_has_path_params=False, + request_has_query_params=True, + user_agent_header="user-agent", + accept_header_value="application/json", + http_headers=http_headers, + _globals=operations.QueryAnalyticsGlobals( + http_referer=self.sdk_configuration.globals.http_referer, + x_open_router_title=self.sdk_configuration.globals.x_open_router_title, + x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, + ), + security=self.sdk_configuration.security, + get_serialized_body=lambda: utils.serialize_request_body( + request.request_body, + False, + False, + "json", + operations.QueryAnalyticsRequestBody, + ), + allow_empty_value=None, + timeout_ms=timeout_ms, + ) + + if retries == UNSET: + if self.sdk_configuration.retry_config is not UNSET: + retries = self.sdk_configuration.retry_config + else: + retries = utils.RetryConfig( + "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True + ) + + retry_config = None + if isinstance(retries, utils.RetryConfig): + retry_config = (retries, ["5XX"]) + + http_res = self.do_request( + hook_ctx=HookContext( + config=self.sdk_configuration, + base_url=base_url or "", + operation_id="queryAnalytics", + oauth2_scopes=None, + security_source=get_security_from_env( + self.sdk_configuration.security, components.Security + ), + tags=["Analytics"], + extensions=None, + ), + request=req, + is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c), + retry_config=retry_config, + ) + + response_data: Any = None + if utils.match_response(http_res, "200", "application/json"): + return unmarshal_json_response(operations.QueryAnalyticsResponse, http_res) + if utils.match_response(http_res, "400", "application/json"): + response_data = unmarshal_json_response( + errors.BadRequestResponseErrorData, http_res + ) + raise errors.BadRequestResponseError(response_data, http_res) + if utils.match_response(http_res, "401", "application/json"): + response_data = unmarshal_json_response( + errors.UnauthorizedResponseErrorData, http_res + ) + raise errors.UnauthorizedResponseError(response_data, http_res) + if utils.match_response(http_res, "403", "application/json"): + response_data = unmarshal_json_response( + errors.ForbiddenResponseErrorData, http_res + ) + raise errors.ForbiddenResponseError(response_data, http_res) + if utils.match_response(http_res, "408", "application/json"): + response_data = unmarshal_json_response( + errors.RequestTimeoutResponseErrorData, http_res + ) + raise errors.RequestTimeoutResponseError(response_data, http_res) + if utils.match_response(http_res, "500", "application/json"): + response_data = unmarshal_json_response( + errors.InternalServerResponseErrorData, http_res + ) + raise errors.InternalServerResponseError(response_data, http_res) + if utils.match_response(http_res, "4XX", "*"): + http_res_text = utils.stream_to_text(http_res) + raise errors.OpenRouterDefaultError( + "API error occurred", http_res, http_res_text + ) + if utils.match_response(http_res, "5XX", "*"): + http_res_text = utils.stream_to_text(http_res) + raise errors.OpenRouterDefaultError( + "API error occurred", http_res, http_res_text + ) + + raise errors.OpenRouterDefaultError("Unexpected response received", http_res) + + async def query_analytics_async( + self, + *, + metrics: Iterable[str], + http_referer: Optional[str] = None, + x_open_router_title: Optional[str] = None, + x_open_router_categories: Optional[str] = None, + classifier_dimensions: Optional[ + Union[ + operations.ClassifierDimensions, + operations.ClassifierDimensionsTypedDict, + ] + ] = None, + classifier_filters: Optional[ + Union[operations.ClassifierFilters, operations.ClassifierFiltersTypedDict] + ] = None, + dimensions: Optional[Iterable[str]] = None, + filters: Optional[ + Union[Iterable[operations.Filter], Iterable[operations.FilterTypedDict]] + ] = None, + granularity: Optional[str] = None, + group_limit: Optional[int] = None, + limit: Optional[int] = None, + order_by: Optional[ + Union[operations.OrderBy, operations.OrderByTypedDict] + ] = None, + time_range: Optional[ + Union[operations.TimeRange, operations.TimeRangeTypedDict] + ] = None, + retries: OptionalNullable[utils.RetryConfig] = UNSET, + server_url: Optional[str] = None, + timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, + ) -> operations.QueryAnalyticsResponse: + r"""Query analytics data + + Execute an analytics query with specified metrics, dimensions, filters, and time range. [Management key](/docs/guides/overview/auth/management-api-keys) required. + + :param metrics: + :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. + This is used to track API usage per application. + + :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. + + :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. + + :param classifier_dimensions: Group results by custom classifier tags, breaking down metrics by the specified dimension values. Requires an active classifier on the workspace. + :param classifier_filters: Filter results to generations with specific classifier tag values. Can be combined with classifier_dimensions (must use the same classifier_id) or used independently with standard dimensions. + :param dimensions: + :param filters: + :param granularity: Time granularity + :param group_limit: Maximum rows per distinct combination of dimensions. When omitted on time-series queries (granularity + dimensions), auto-computed to avoid truncating time windows. Explicit values override the default and may truncate time buckets if set lower than the number of buckets in the range. Ignored when no dimensions are specified. + :param limit: Maximum total rows returned. Defaults to 1000. On time-series queries with dimensions and no explicit group_limit, the server may raise this to accommodate the expected number of unique time-bucket/dimension combinations. + :param order_by: + :param time_range: + :param retries: Override the default retry configuration for this method + :param server_url: Override the default server URL for this method + :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. + """ + base_url = None + url_variables = None + if timeout_ms is None: + timeout_ms = self.sdk_configuration.timeout_ms + + if server_url is not None: + base_url = server_url + else: + base_url = self._get_url(base_url, url_variables) + + request = operations.QueryAnalyticsRequest( + http_referer=http_referer, + x_open_router_title=x_open_router_title, + x_open_router_categories=x_open_router_categories, + request_body=operations.QueryAnalyticsRequestBody( + classifier_dimensions=utils.get_pydantic_model( + classifier_dimensions, Optional[operations.ClassifierDimensions] + ), + classifier_filters=utils.get_pydantic_model( + classifier_filters, Optional[operations.ClassifierFilters] + ), + dimensions=utils.unmarshal(dimensions, Optional[List[str]]), + filters=utils.get_pydantic_model( + filters, Optional[List[operations.Filter]] + ), + granularity=granularity, + group_limit=group_limit, + limit=limit, + metrics=utils.unmarshal(metrics, List[str]), + order_by=utils.get_pydantic_model( + order_by, Optional[operations.OrderBy] + ), + time_range=utils.get_pydantic_model( + time_range, Optional[operations.TimeRange] + ), + ), + ) + + req = self._build_request_async( + method="POST", + path="/analytics/query", + base_url=base_url, + url_variables=url_variables, + request=request, + request_body_required=True, + request_has_path_params=False, + request_has_query_params=True, + user_agent_header="user-agent", + accept_header_value="application/json", + http_headers=http_headers, + _globals=operations.QueryAnalyticsGlobals( + http_referer=self.sdk_configuration.globals.http_referer, + x_open_router_title=self.sdk_configuration.globals.x_open_router_title, + x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, + ), + security=self.sdk_configuration.security, + get_serialized_body=lambda: utils.serialize_request_body( + request.request_body, + False, + False, + "json", + operations.QueryAnalyticsRequestBody, + ), + allow_empty_value=None, + timeout_ms=timeout_ms, + ) + + if retries == UNSET: + if self.sdk_configuration.retry_config is not UNSET: + retries = self.sdk_configuration.retry_config + else: + retries = utils.RetryConfig( + "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True + ) + + retry_config = None + if isinstance(retries, utils.RetryConfig): + retry_config = (retries, ["5XX"]) + + http_res = await self.do_request_async( + hook_ctx=HookContext( + config=self.sdk_configuration, + base_url=base_url or "", + operation_id="queryAnalytics", + oauth2_scopes=None, + security_source=get_security_from_env( + self.sdk_configuration.security, components.Security + ), + tags=["Analytics"], + extensions=None, + ), + request=req, + is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c), + retry_config=retry_config, + ) + + response_data: Any = None + if utils.match_response(http_res, "200", "application/json"): + return unmarshal_json_response(operations.QueryAnalyticsResponse, http_res) + if utils.match_response(http_res, "400", "application/json"): + response_data = unmarshal_json_response( + errors.BadRequestResponseErrorData, http_res + ) + raise errors.BadRequestResponseError(response_data, http_res) + if utils.match_response(http_res, "401", "application/json"): + response_data = unmarshal_json_response( + errors.UnauthorizedResponseErrorData, http_res + ) + raise errors.UnauthorizedResponseError(response_data, http_res) + if utils.match_response(http_res, "403", "application/json"): + response_data = unmarshal_json_response( + errors.ForbiddenResponseErrorData, http_res + ) + raise errors.ForbiddenResponseError(response_data, http_res) + if utils.match_response(http_res, "408", "application/json"): + response_data = unmarshal_json_response( + errors.RequestTimeoutResponseErrorData, http_res + ) + raise errors.RequestTimeoutResponseError(response_data, http_res) + if utils.match_response(http_res, "500", "application/json"): + response_data = unmarshal_json_response( + errors.InternalServerResponseErrorData, http_res + ) + raise errors.InternalServerResponseError(response_data, http_res) + if utils.match_response(http_res, "4XX", "*"): + http_res_text = await utils.stream_to_text_async(http_res) + raise errors.OpenRouterDefaultError( + "API error occurred", http_res, http_res_text + ) + if utils.match_response(http_res, "5XX", "*"): + http_res_text = await utils.stream_to_text_async(http_res) + raise errors.OpenRouterDefaultError( + "API error occurred", http_res, http_res_text + ) + + raise errors.OpenRouterDefaultError("Unexpected response received", http_res) diff --git a/src/openrouter/beta.py b/src/openrouter/beta.py index 6def81a9..aa95a65c 100644 --- a/src/openrouter/beta.py +++ b/src/openrouter/beta.py @@ -2,14 +2,11 @@ from .basesdk import BaseSDK from .sdkconfiguration import SDKConfiguration -from openrouter.beta_analytics import BetaAnalytics from openrouter.beta_responses import BetaResponses from typing import Optional class Beta(BaseSDK): - analytics: BetaAnalytics - r"""beta.Analytics endpoints""" responses: BetaResponses r"""Deprecated alias for responses endpoints. Use responses instead. Scheduled for removal (sunset date TBD).""" @@ -21,9 +18,6 @@ def __init__( self._init_sdks() def _init_sdks(self): - self.analytics = BetaAnalytics( - self.sdk_configuration, parent_ref=self.parent_ref - ) self.responses = BetaResponses( self.sdk_configuration, parent_ref=self.parent_ref ) diff --git a/src/openrouter/beta_analytics.py b/src/openrouter/beta_analytics.py deleted file mode 100644 index 1b01f0c0..00000000 --- a/src/openrouter/beta_analytics.py +++ /dev/null @@ -1,661 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" - -from .basesdk import BaseSDK -from openrouter import components, errors, operations, utils -from openrouter._hooks import HookContext -from openrouter.types import OptionalNullable, UNSET -from openrouter.utils import get_security_from_env -from openrouter.utils.unmarshal_json_response import unmarshal_json_response -from typing import Any, Iterable, List, Mapping, Optional, Union - - -class BetaAnalytics(BaseSDK): - r"""beta.Analytics endpoints""" - - def get_analytics_meta( - self, - *, - http_referer: Optional[str] = None, - x_open_router_title: Optional[str] = None, - x_open_router_categories: Optional[str] = None, - retries: OptionalNullable[utils.RetryConfig] = UNSET, - server_url: Optional[str] = None, - timeout_ms: Optional[int] = None, - http_headers: Optional[Mapping[str, str]] = None, - ) -> operations.GetAnalyticsMetaResponse: - r"""Get available analytics metrics and dimensions - - Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint. [Management key](/docs/guides/overview/auth/management-api-keys) required. - - :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. - This is used to track API usage per application. - - :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. - - :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. - - :param retries: Override the default retry configuration for this method - :param server_url: Override the default server URL for this method - :param timeout_ms: Override the default request timeout configuration for this method in milliseconds - :param http_headers: Additional headers to set or replace on requests. - """ - base_url = None - url_variables = None - if timeout_ms is None: - timeout_ms = self.sdk_configuration.timeout_ms - - if server_url is not None: - base_url = server_url - else: - base_url = self._get_url(base_url, url_variables) - - request = operations.GetAnalyticsMetaRequest( - http_referer=http_referer, - x_open_router_title=x_open_router_title, - x_open_router_categories=x_open_router_categories, - ) - - req = self._build_request( - method="GET", - path="/analytics/meta", - base_url=base_url, - url_variables=url_variables, - request=request, - request_body_required=False, - request_has_path_params=False, - request_has_query_params=True, - user_agent_header="user-agent", - accept_header_value="application/json", - http_headers=http_headers, - _globals=operations.GetAnalyticsMetaGlobals( - http_referer=self.sdk_configuration.globals.http_referer, - x_open_router_title=self.sdk_configuration.globals.x_open_router_title, - x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, - ), - security=self.sdk_configuration.security, - allow_empty_value=None, - timeout_ms=timeout_ms, - ) - - if retries == UNSET: - if self.sdk_configuration.retry_config is not UNSET: - retries = self.sdk_configuration.retry_config - else: - retries = utils.RetryConfig( - "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True - ) - - retry_config = None - if isinstance(retries, utils.RetryConfig): - retry_config = (retries, ["5XX"]) - - http_res = self.do_request( - hook_ctx=HookContext( - config=self.sdk_configuration, - base_url=base_url or "", - operation_id="getAnalyticsMeta", - oauth2_scopes=None, - security_source=get_security_from_env( - self.sdk_configuration.security, components.Security - ), - tags=["beta.Analytics"], - extensions=None, - ), - request=req, - is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c), - retry_config=retry_config, - ) - - response_data: Any = None - if utils.match_response(http_res, "200", "application/json"): - return unmarshal_json_response( - operations.GetAnalyticsMetaResponse, http_res - ) - if utils.match_response(http_res, "401", "application/json"): - response_data = unmarshal_json_response( - errors.UnauthorizedResponseErrorData, http_res - ) - raise errors.UnauthorizedResponseError(response_data, http_res) - if utils.match_response(http_res, "403", "application/json"): - response_data = unmarshal_json_response( - errors.ForbiddenResponseErrorData, http_res - ) - raise errors.ForbiddenResponseError(response_data, http_res) - if utils.match_response(http_res, "500", "application/json"): - response_data = unmarshal_json_response( - errors.InternalServerResponseErrorData, http_res - ) - raise errors.InternalServerResponseError(response_data, http_res) - if utils.match_response(http_res, "4XX", "*"): - http_res_text = utils.stream_to_text(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - if utils.match_response(http_res, "5XX", "*"): - http_res_text = utils.stream_to_text(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - - raise errors.OpenRouterDefaultError("Unexpected response received", http_res) - - async def get_analytics_meta_async( - self, - *, - http_referer: Optional[str] = None, - x_open_router_title: Optional[str] = None, - x_open_router_categories: Optional[str] = None, - retries: OptionalNullable[utils.RetryConfig] = UNSET, - server_url: Optional[str] = None, - timeout_ms: Optional[int] = None, - http_headers: Optional[Mapping[str, str]] = None, - ) -> operations.GetAnalyticsMetaResponse: - r"""Get available analytics metrics and dimensions - - Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint. [Management key](/docs/guides/overview/auth/management-api-keys) required. - - :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. - This is used to track API usage per application. - - :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. - - :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. - - :param retries: Override the default retry configuration for this method - :param server_url: Override the default server URL for this method - :param timeout_ms: Override the default request timeout configuration for this method in milliseconds - :param http_headers: Additional headers to set or replace on requests. - """ - base_url = None - url_variables = None - if timeout_ms is None: - timeout_ms = self.sdk_configuration.timeout_ms - - if server_url is not None: - base_url = server_url - else: - base_url = self._get_url(base_url, url_variables) - - request = operations.GetAnalyticsMetaRequest( - http_referer=http_referer, - x_open_router_title=x_open_router_title, - x_open_router_categories=x_open_router_categories, - ) - - req = self._build_request_async( - method="GET", - path="/analytics/meta", - base_url=base_url, - url_variables=url_variables, - request=request, - request_body_required=False, - request_has_path_params=False, - request_has_query_params=True, - user_agent_header="user-agent", - accept_header_value="application/json", - http_headers=http_headers, - _globals=operations.GetAnalyticsMetaGlobals( - http_referer=self.sdk_configuration.globals.http_referer, - x_open_router_title=self.sdk_configuration.globals.x_open_router_title, - x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, - ), - security=self.sdk_configuration.security, - allow_empty_value=None, - timeout_ms=timeout_ms, - ) - - if retries == UNSET: - if self.sdk_configuration.retry_config is not UNSET: - retries = self.sdk_configuration.retry_config - else: - retries = utils.RetryConfig( - "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True - ) - - retry_config = None - if isinstance(retries, utils.RetryConfig): - retry_config = (retries, ["5XX"]) - - http_res = await self.do_request_async( - hook_ctx=HookContext( - config=self.sdk_configuration, - base_url=base_url or "", - operation_id="getAnalyticsMeta", - oauth2_scopes=None, - security_source=get_security_from_env( - self.sdk_configuration.security, components.Security - ), - tags=["beta.Analytics"], - extensions=None, - ), - request=req, - is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c), - retry_config=retry_config, - ) - - response_data: Any = None - if utils.match_response(http_res, "200", "application/json"): - return unmarshal_json_response( - operations.GetAnalyticsMetaResponse, http_res - ) - if utils.match_response(http_res, "401", "application/json"): - response_data = unmarshal_json_response( - errors.UnauthorizedResponseErrorData, http_res - ) - raise errors.UnauthorizedResponseError(response_data, http_res) - if utils.match_response(http_res, "403", "application/json"): - response_data = unmarshal_json_response( - errors.ForbiddenResponseErrorData, http_res - ) - raise errors.ForbiddenResponseError(response_data, http_res) - if utils.match_response(http_res, "500", "application/json"): - response_data = unmarshal_json_response( - errors.InternalServerResponseErrorData, http_res - ) - raise errors.InternalServerResponseError(response_data, http_res) - if utils.match_response(http_res, "4XX", "*"): - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - if utils.match_response(http_res, "5XX", "*"): - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - - raise errors.OpenRouterDefaultError("Unexpected response received", http_res) - - def query_analytics( - self, - *, - metrics: Iterable[str], - http_referer: Optional[str] = None, - x_open_router_title: Optional[str] = None, - x_open_router_categories: Optional[str] = None, - classifier_dimensions: Optional[ - Union[ - operations.ClassifierDimensions, - operations.ClassifierDimensionsTypedDict, - ] - ] = None, - classifier_filters: Optional[ - Union[operations.ClassifierFilters, operations.ClassifierFiltersTypedDict] - ] = None, - dimensions: Optional[Iterable[str]] = None, - filters: Optional[ - Union[Iterable[operations.Filter], Iterable[operations.FilterTypedDict]] - ] = None, - granularity: Optional[str] = None, - group_limit: Optional[int] = None, - limit: Optional[int] = None, - order_by: Optional[ - Union[operations.OrderBy, operations.OrderByTypedDict] - ] = None, - time_range: Optional[ - Union[operations.TimeRange, operations.TimeRangeTypedDict] - ] = None, - retries: OptionalNullable[utils.RetryConfig] = UNSET, - server_url: Optional[str] = None, - timeout_ms: Optional[int] = None, - http_headers: Optional[Mapping[str, str]] = None, - ) -> operations.QueryAnalyticsResponse: - r"""Query analytics data - - Execute an analytics query with specified metrics, dimensions, filters, and time range. [Management key](/docs/guides/overview/auth/management-api-keys) required. - - :param metrics: - :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. - This is used to track API usage per application. - - :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. - - :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. - - :param classifier_dimensions: Group results by custom classifier tags, breaking down metrics by the specified dimension values. Requires an active classifier on the workspace. - :param classifier_filters: Filter results to generations with specific classifier tag values. Can be combined with classifier_dimensions (must use the same classifier_id) or used independently with standard dimensions. - :param dimensions: - :param filters: - :param granularity: Time granularity - :param group_limit: Maximum rows per distinct combination of dimensions. When omitted on time-series queries (granularity + dimensions), auto-computed to avoid truncating time windows. Explicit values override the default and may truncate time buckets if set lower than the number of buckets in the range. Ignored when no dimensions are specified. - :param limit: Maximum total rows returned. Defaults to 1000. On time-series queries with dimensions and no explicit group_limit, the server may raise this to accommodate the expected number of unique time-bucket/dimension combinations. - :param order_by: - :param time_range: - :param retries: Override the default retry configuration for this method - :param server_url: Override the default server URL for this method - :param timeout_ms: Override the default request timeout configuration for this method in milliseconds - :param http_headers: Additional headers to set or replace on requests. - """ - base_url = None - url_variables = None - if timeout_ms is None: - timeout_ms = self.sdk_configuration.timeout_ms - - if server_url is not None: - base_url = server_url - else: - base_url = self._get_url(base_url, url_variables) - - request = operations.QueryAnalyticsRequest( - http_referer=http_referer, - x_open_router_title=x_open_router_title, - x_open_router_categories=x_open_router_categories, - request_body=operations.QueryAnalyticsRequestBody( - classifier_dimensions=utils.get_pydantic_model( - classifier_dimensions, Optional[operations.ClassifierDimensions] - ), - classifier_filters=utils.get_pydantic_model( - classifier_filters, Optional[operations.ClassifierFilters] - ), - dimensions=utils.unmarshal(dimensions, Optional[List[str]]), - filters=utils.get_pydantic_model( - filters, Optional[List[operations.Filter]] - ), - granularity=granularity, - group_limit=group_limit, - limit=limit, - metrics=utils.unmarshal(metrics, List[str]), - order_by=utils.get_pydantic_model( - order_by, Optional[operations.OrderBy] - ), - time_range=utils.get_pydantic_model( - time_range, Optional[operations.TimeRange] - ), - ), - ) - - req = self._build_request( - method="POST", - path="/analytics/query", - base_url=base_url, - url_variables=url_variables, - request=request, - request_body_required=True, - request_has_path_params=False, - request_has_query_params=True, - user_agent_header="user-agent", - accept_header_value="application/json", - http_headers=http_headers, - _globals=operations.QueryAnalyticsGlobals( - http_referer=self.sdk_configuration.globals.http_referer, - x_open_router_title=self.sdk_configuration.globals.x_open_router_title, - x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, - ), - security=self.sdk_configuration.security, - get_serialized_body=lambda: utils.serialize_request_body( - request.request_body, - False, - False, - "json", - operations.QueryAnalyticsRequestBody, - ), - allow_empty_value=None, - timeout_ms=timeout_ms, - ) - - if retries == UNSET: - if self.sdk_configuration.retry_config is not UNSET: - retries = self.sdk_configuration.retry_config - else: - retries = utils.RetryConfig( - "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True - ) - - retry_config = None - if isinstance(retries, utils.RetryConfig): - retry_config = (retries, ["5XX"]) - - http_res = self.do_request( - hook_ctx=HookContext( - config=self.sdk_configuration, - base_url=base_url or "", - operation_id="queryAnalytics", - oauth2_scopes=None, - security_source=get_security_from_env( - self.sdk_configuration.security, components.Security - ), - tags=["beta.Analytics"], - extensions=None, - ), - request=req, - is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c), - retry_config=retry_config, - ) - - response_data: Any = None - if utils.match_response(http_res, "200", "application/json"): - return unmarshal_json_response(operations.QueryAnalyticsResponse, http_res) - if utils.match_response(http_res, "400", "application/json"): - response_data = unmarshal_json_response( - errors.BadRequestResponseErrorData, http_res - ) - raise errors.BadRequestResponseError(response_data, http_res) - if utils.match_response(http_res, "401", "application/json"): - response_data = unmarshal_json_response( - errors.UnauthorizedResponseErrorData, http_res - ) - raise errors.UnauthorizedResponseError(response_data, http_res) - if utils.match_response(http_res, "403", "application/json"): - response_data = unmarshal_json_response( - errors.ForbiddenResponseErrorData, http_res - ) - raise errors.ForbiddenResponseError(response_data, http_res) - if utils.match_response(http_res, "408", "application/json"): - response_data = unmarshal_json_response( - errors.RequestTimeoutResponseErrorData, http_res - ) - raise errors.RequestTimeoutResponseError(response_data, http_res) - if utils.match_response(http_res, "500", "application/json"): - response_data = unmarshal_json_response( - errors.InternalServerResponseErrorData, http_res - ) - raise errors.InternalServerResponseError(response_data, http_res) - if utils.match_response(http_res, "4XX", "*"): - http_res_text = utils.stream_to_text(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - if utils.match_response(http_res, "5XX", "*"): - http_res_text = utils.stream_to_text(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - - raise errors.OpenRouterDefaultError("Unexpected response received", http_res) - - async def query_analytics_async( - self, - *, - metrics: Iterable[str], - http_referer: Optional[str] = None, - x_open_router_title: Optional[str] = None, - x_open_router_categories: Optional[str] = None, - classifier_dimensions: Optional[ - Union[ - operations.ClassifierDimensions, - operations.ClassifierDimensionsTypedDict, - ] - ] = None, - classifier_filters: Optional[ - Union[operations.ClassifierFilters, operations.ClassifierFiltersTypedDict] - ] = None, - dimensions: Optional[Iterable[str]] = None, - filters: Optional[ - Union[Iterable[operations.Filter], Iterable[operations.FilterTypedDict]] - ] = None, - granularity: Optional[str] = None, - group_limit: Optional[int] = None, - limit: Optional[int] = None, - order_by: Optional[ - Union[operations.OrderBy, operations.OrderByTypedDict] - ] = None, - time_range: Optional[ - Union[operations.TimeRange, operations.TimeRangeTypedDict] - ] = None, - retries: OptionalNullable[utils.RetryConfig] = UNSET, - server_url: Optional[str] = None, - timeout_ms: Optional[int] = None, - http_headers: Optional[Mapping[str, str]] = None, - ) -> operations.QueryAnalyticsResponse: - r"""Query analytics data - - Execute an analytics query with specified metrics, dimensions, filters, and time range. [Management key](/docs/guides/overview/auth/management-api-keys) required. - - :param metrics: - :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. - This is used to track API usage per application. - - :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. - - :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. - - :param classifier_dimensions: Group results by custom classifier tags, breaking down metrics by the specified dimension values. Requires an active classifier on the workspace. - :param classifier_filters: Filter results to generations with specific classifier tag values. Can be combined with classifier_dimensions (must use the same classifier_id) or used independently with standard dimensions. - :param dimensions: - :param filters: - :param granularity: Time granularity - :param group_limit: Maximum rows per distinct combination of dimensions. When omitted on time-series queries (granularity + dimensions), auto-computed to avoid truncating time windows. Explicit values override the default and may truncate time buckets if set lower than the number of buckets in the range. Ignored when no dimensions are specified. - :param limit: Maximum total rows returned. Defaults to 1000. On time-series queries with dimensions and no explicit group_limit, the server may raise this to accommodate the expected number of unique time-bucket/dimension combinations. - :param order_by: - :param time_range: - :param retries: Override the default retry configuration for this method - :param server_url: Override the default server URL for this method - :param timeout_ms: Override the default request timeout configuration for this method in milliseconds - :param http_headers: Additional headers to set or replace on requests. - """ - base_url = None - url_variables = None - if timeout_ms is None: - timeout_ms = self.sdk_configuration.timeout_ms - - if server_url is not None: - base_url = server_url - else: - base_url = self._get_url(base_url, url_variables) - - request = operations.QueryAnalyticsRequest( - http_referer=http_referer, - x_open_router_title=x_open_router_title, - x_open_router_categories=x_open_router_categories, - request_body=operations.QueryAnalyticsRequestBody( - classifier_dimensions=utils.get_pydantic_model( - classifier_dimensions, Optional[operations.ClassifierDimensions] - ), - classifier_filters=utils.get_pydantic_model( - classifier_filters, Optional[operations.ClassifierFilters] - ), - dimensions=utils.unmarshal(dimensions, Optional[List[str]]), - filters=utils.get_pydantic_model( - filters, Optional[List[operations.Filter]] - ), - granularity=granularity, - group_limit=group_limit, - limit=limit, - metrics=utils.unmarshal(metrics, List[str]), - order_by=utils.get_pydantic_model( - order_by, Optional[operations.OrderBy] - ), - time_range=utils.get_pydantic_model( - time_range, Optional[operations.TimeRange] - ), - ), - ) - - req = self._build_request_async( - method="POST", - path="/analytics/query", - base_url=base_url, - url_variables=url_variables, - request=request, - request_body_required=True, - request_has_path_params=False, - request_has_query_params=True, - user_agent_header="user-agent", - accept_header_value="application/json", - http_headers=http_headers, - _globals=operations.QueryAnalyticsGlobals( - http_referer=self.sdk_configuration.globals.http_referer, - x_open_router_title=self.sdk_configuration.globals.x_open_router_title, - x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, - ), - security=self.sdk_configuration.security, - get_serialized_body=lambda: utils.serialize_request_body( - request.request_body, - False, - False, - "json", - operations.QueryAnalyticsRequestBody, - ), - allow_empty_value=None, - timeout_ms=timeout_ms, - ) - - if retries == UNSET: - if self.sdk_configuration.retry_config is not UNSET: - retries = self.sdk_configuration.retry_config - else: - retries = utils.RetryConfig( - "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True - ) - - retry_config = None - if isinstance(retries, utils.RetryConfig): - retry_config = (retries, ["5XX"]) - - http_res = await self.do_request_async( - hook_ctx=HookContext( - config=self.sdk_configuration, - base_url=base_url or "", - operation_id="queryAnalytics", - oauth2_scopes=None, - security_source=get_security_from_env( - self.sdk_configuration.security, components.Security - ), - tags=["beta.Analytics"], - extensions=None, - ), - request=req, - is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c), - retry_config=retry_config, - ) - - response_data: Any = None - if utils.match_response(http_res, "200", "application/json"): - return unmarshal_json_response(operations.QueryAnalyticsResponse, http_res) - if utils.match_response(http_res, "400", "application/json"): - response_data = unmarshal_json_response( - errors.BadRequestResponseErrorData, http_res - ) - raise errors.BadRequestResponseError(response_data, http_res) - if utils.match_response(http_res, "401", "application/json"): - response_data = unmarshal_json_response( - errors.UnauthorizedResponseErrorData, http_res - ) - raise errors.UnauthorizedResponseError(response_data, http_res) - if utils.match_response(http_res, "403", "application/json"): - response_data = unmarshal_json_response( - errors.ForbiddenResponseErrorData, http_res - ) - raise errors.ForbiddenResponseError(response_data, http_res) - if utils.match_response(http_res, "408", "application/json"): - response_data = unmarshal_json_response( - errors.RequestTimeoutResponseErrorData, http_res - ) - raise errors.RequestTimeoutResponseError(response_data, http_res) - if utils.match_response(http_res, "500", "application/json"): - response_data = unmarshal_json_response( - errors.InternalServerResponseErrorData, http_res - ) - raise errors.InternalServerResponseError(response_data, http_res) - if utils.match_response(http_res, "4XX", "*"): - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - if utils.match_response(http_res, "5XX", "*"): - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - - raise errors.OpenRouterDefaultError("Unexpected response received", http_res) diff --git a/src/openrouter/sdk.py b/src/openrouter/sdk.py index b00e07cd..4dca8972 100644 --- a/src/openrouter/sdk.py +++ b/src/openrouter/sdk.py @@ -53,7 +53,6 @@ class OpenRouter(BaseSDK): analytics: "Analytics" r"""Analytics and usage endpoints""" - beta: "Beta" tts: "TTS" r"""Text-to-speech endpoints""" stt: "STT" @@ -99,6 +98,7 @@ class OpenRouter(BaseSDK): r"""Rerank endpoints""" responses: "Responses" r"""OpenAI-compatible Responses API endpoints""" + beta: "Beta" scim: "Scim" r"""SCIM endpoints""" video_generation: "VideoGeneration" @@ -107,7 +107,6 @@ class OpenRouter(BaseSDK): r"""Workspaces endpoints""" _sub_sdk_map = { "analytics": ("openrouter.analytics", "Analytics"), - "beta": ("openrouter.beta", "Beta"), "tts": ("openrouter.tts", "TTS"), "stt": ("openrouter.stt", "STT"), "o_auth": ("openrouter.oauth", "OAuth"), @@ -131,6 +130,7 @@ class OpenRouter(BaseSDK): "providers": ("openrouter.providers", "Providers"), "rerank": ("openrouter.rerank", "Rerank"), "responses": ("openrouter.responses", "Responses"), + "beta": ("openrouter.beta", "Beta"), "scim": ("openrouter.scim", "Scim"), "video_generation": ("openrouter.video_generation", "VideoGeneration"), "workspaces": ("openrouter.workspaces", "Workspaces"), diff --git a/uv.lock b/uv.lock index 34faeb76..0b12d18c 100644 --- a/uv.lock +++ b/uv.lock @@ -213,7 +213,7 @@ wheels = [ [[package]] name = "openrouter" -version = "1.1.68" +version = "1.1.69" source = { editable = "." } dependencies = [ { name = "httpcore" },