|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Optional |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
| 10 | +from ..._utils import maybe_transform, async_maybe_transform |
| 11 | +from ..._compat import cached_property |
| 12 | +from ..._resource import SyncAPIResource, AsyncAPIResource |
| 13 | +from ..._response import ( |
| 14 | + to_raw_response_wrapper, |
| 15 | + to_streamed_response_wrapper, |
| 16 | + async_to_raw_response_wrapper, |
| 17 | + async_to_streamed_response_wrapper, |
| 18 | +) |
| 19 | +from ..._base_client import make_request_options |
| 20 | +from ...types.workspaces import api_key_create_params |
| 21 | +from ...types.workspaces.api_key_create_response import APIKeyCreateResponse |
| 22 | + |
| 23 | +__all__ = ["APIKeysResource", "AsyncAPIKeysResource"] |
| 24 | + |
| 25 | + |
| 26 | +class APIKeysResource(SyncAPIResource): |
| 27 | + @cached_property |
| 28 | + def with_raw_response(self) -> APIKeysResourceWithRawResponse: |
| 29 | + """ |
| 30 | + This property can be used as a prefix for any HTTP method call to return |
| 31 | + the raw response object instead of the parsed content. |
| 32 | +
|
| 33 | + For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers |
| 34 | + """ |
| 35 | + return APIKeysResourceWithRawResponse(self) |
| 36 | + |
| 37 | + @cached_property |
| 38 | + def with_streaming_response(self) -> APIKeysResourceWithStreamingResponse: |
| 39 | + """ |
| 40 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 41 | +
|
| 42 | + For more information, see https://www.github.com/openlayer-ai/openlayer-python#with_streaming_response |
| 43 | + """ |
| 44 | + return APIKeysResourceWithStreamingResponse(self) |
| 45 | + |
| 46 | + def create( |
| 47 | + self, |
| 48 | + workspace_id: str, |
| 49 | + *, |
| 50 | + name: Optional[str] | Omit = omit, |
| 51 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 52 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 53 | + extra_headers: Headers | None = None, |
| 54 | + extra_query: Query | None = None, |
| 55 | + extra_body: Body | None = None, |
| 56 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 57 | + ) -> APIKeyCreateResponse: |
| 58 | + """ |
| 59 | + Create a new API key in a workspace. |
| 60 | +
|
| 61 | + Args: |
| 62 | + name: The API key name. |
| 63 | +
|
| 64 | + extra_headers: Send extra headers |
| 65 | +
|
| 66 | + extra_query: Add additional query parameters to the request |
| 67 | +
|
| 68 | + extra_body: Add additional JSON properties to the request |
| 69 | +
|
| 70 | + timeout: Override the client-level default timeout for this request, in seconds |
| 71 | + """ |
| 72 | + if not workspace_id: |
| 73 | + raise ValueError(f"Expected a non-empty value for `workspace_id` but received {workspace_id!r}") |
| 74 | + return self._post( |
| 75 | + f"/workspaces/{workspace_id}/api-keys", |
| 76 | + body=maybe_transform({"name": name}, api_key_create_params.APIKeyCreateParams), |
| 77 | + options=make_request_options( |
| 78 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 79 | + ), |
| 80 | + cast_to=APIKeyCreateResponse, |
| 81 | + ) |
| 82 | + |
| 83 | + |
| 84 | +class AsyncAPIKeysResource(AsyncAPIResource): |
| 85 | + @cached_property |
| 86 | + def with_raw_response(self) -> AsyncAPIKeysResourceWithRawResponse: |
| 87 | + """ |
| 88 | + This property can be used as a prefix for any HTTP method call to return |
| 89 | + the raw response object instead of the parsed content. |
| 90 | +
|
| 91 | + For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers |
| 92 | + """ |
| 93 | + return AsyncAPIKeysResourceWithRawResponse(self) |
| 94 | + |
| 95 | + @cached_property |
| 96 | + def with_streaming_response(self) -> AsyncAPIKeysResourceWithStreamingResponse: |
| 97 | + """ |
| 98 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 99 | +
|
| 100 | + For more information, see https://www.github.com/openlayer-ai/openlayer-python#with_streaming_response |
| 101 | + """ |
| 102 | + return AsyncAPIKeysResourceWithStreamingResponse(self) |
| 103 | + |
| 104 | + async def create( |
| 105 | + self, |
| 106 | + workspace_id: str, |
| 107 | + *, |
| 108 | + name: Optional[str] | Omit = omit, |
| 109 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 110 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 111 | + extra_headers: Headers | None = None, |
| 112 | + extra_query: Query | None = None, |
| 113 | + extra_body: Body | None = None, |
| 114 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 115 | + ) -> APIKeyCreateResponse: |
| 116 | + """ |
| 117 | + Create a new API key in a workspace. |
| 118 | +
|
| 119 | + Args: |
| 120 | + name: The API key name. |
| 121 | +
|
| 122 | + extra_headers: Send extra headers |
| 123 | +
|
| 124 | + extra_query: Add additional query parameters to the request |
| 125 | +
|
| 126 | + extra_body: Add additional JSON properties to the request |
| 127 | +
|
| 128 | + timeout: Override the client-level default timeout for this request, in seconds |
| 129 | + """ |
| 130 | + if not workspace_id: |
| 131 | + raise ValueError(f"Expected a non-empty value for `workspace_id` but received {workspace_id!r}") |
| 132 | + return await self._post( |
| 133 | + f"/workspaces/{workspace_id}/api-keys", |
| 134 | + body=await async_maybe_transform({"name": name}, api_key_create_params.APIKeyCreateParams), |
| 135 | + options=make_request_options( |
| 136 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 137 | + ), |
| 138 | + cast_to=APIKeyCreateResponse, |
| 139 | + ) |
| 140 | + |
| 141 | + |
| 142 | +class APIKeysResourceWithRawResponse: |
| 143 | + def __init__(self, api_keys: APIKeysResource) -> None: |
| 144 | + self._api_keys = api_keys |
| 145 | + |
| 146 | + self.create = to_raw_response_wrapper( |
| 147 | + api_keys.create, |
| 148 | + ) |
| 149 | + |
| 150 | + |
| 151 | +class AsyncAPIKeysResourceWithRawResponse: |
| 152 | + def __init__(self, api_keys: AsyncAPIKeysResource) -> None: |
| 153 | + self._api_keys = api_keys |
| 154 | + |
| 155 | + self.create = async_to_raw_response_wrapper( |
| 156 | + api_keys.create, |
| 157 | + ) |
| 158 | + |
| 159 | + |
| 160 | +class APIKeysResourceWithStreamingResponse: |
| 161 | + def __init__(self, api_keys: APIKeysResource) -> None: |
| 162 | + self._api_keys = api_keys |
| 163 | + |
| 164 | + self.create = to_streamed_response_wrapper( |
| 165 | + api_keys.create, |
| 166 | + ) |
| 167 | + |
| 168 | + |
| 169 | +class AsyncAPIKeysResourceWithStreamingResponse: |
| 170 | + def __init__(self, api_keys: AsyncAPIKeysResource) -> None: |
| 171 | + self._api_keys = api_keys |
| 172 | + |
| 173 | + self.create = async_to_streamed_response_wrapper( |
| 174 | + api_keys.create, |
| 175 | + ) |
0 commit comments