update bots

This commit is contained in:
2026-05-18 14:15:59 +07:00
parent b0ce866a2f
commit b9054d178e
5775 changed files with 832577 additions and 38 deletions

View File

@@ -0,0 +1,257 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .beta import (
Beta,
AsyncBeta,
BetaWithRawResponse,
AsyncBetaWithRawResponse,
BetaWithStreamingResponse,
AsyncBetaWithStreamingResponse,
)
from .chat import (
Chat,
AsyncChat,
ChatWithRawResponse,
AsyncChatWithRawResponse,
ChatWithStreamingResponse,
AsyncChatWithStreamingResponse,
)
from .admin import (
Admin,
AsyncAdmin,
AdminWithRawResponse,
AsyncAdminWithRawResponse,
AdminWithStreamingResponse,
AsyncAdminWithStreamingResponse,
)
from .audio import (
Audio,
AsyncAudio,
AudioWithRawResponse,
AsyncAudioWithRawResponse,
AudioWithStreamingResponse,
AsyncAudioWithStreamingResponse,
)
from .evals import (
Evals,
AsyncEvals,
EvalsWithRawResponse,
AsyncEvalsWithRawResponse,
EvalsWithStreamingResponse,
AsyncEvalsWithStreamingResponse,
)
from .files import (
Files,
AsyncFiles,
FilesWithRawResponse,
AsyncFilesWithRawResponse,
FilesWithStreamingResponse,
AsyncFilesWithStreamingResponse,
)
from .images import (
Images,
AsyncImages,
ImagesWithRawResponse,
AsyncImagesWithRawResponse,
ImagesWithStreamingResponse,
AsyncImagesWithStreamingResponse,
)
from .models import (
Models,
AsyncModels,
ModelsWithRawResponse,
AsyncModelsWithRawResponse,
ModelsWithStreamingResponse,
AsyncModelsWithStreamingResponse,
)
from .skills import (
Skills,
AsyncSkills,
SkillsWithRawResponse,
AsyncSkillsWithRawResponse,
SkillsWithStreamingResponse,
AsyncSkillsWithStreamingResponse,
)
from .videos import (
Videos,
AsyncVideos,
VideosWithRawResponse,
AsyncVideosWithRawResponse,
VideosWithStreamingResponse,
AsyncVideosWithStreamingResponse,
)
from .batches import (
Batches,
AsyncBatches,
BatchesWithRawResponse,
AsyncBatchesWithRawResponse,
BatchesWithStreamingResponse,
AsyncBatchesWithStreamingResponse,
)
from .uploads import (
Uploads,
AsyncUploads,
UploadsWithRawResponse,
AsyncUploadsWithRawResponse,
UploadsWithStreamingResponse,
AsyncUploadsWithStreamingResponse,
)
from .containers import (
Containers,
AsyncContainers,
ContainersWithRawResponse,
AsyncContainersWithRawResponse,
ContainersWithStreamingResponse,
AsyncContainersWithStreamingResponse,
)
from .embeddings import (
Embeddings,
AsyncEmbeddings,
EmbeddingsWithRawResponse,
AsyncEmbeddingsWithRawResponse,
EmbeddingsWithStreamingResponse,
AsyncEmbeddingsWithStreamingResponse,
)
from .completions import (
Completions,
AsyncCompletions,
CompletionsWithRawResponse,
AsyncCompletionsWithRawResponse,
CompletionsWithStreamingResponse,
AsyncCompletionsWithStreamingResponse,
)
from .fine_tuning import (
FineTuning,
AsyncFineTuning,
FineTuningWithRawResponse,
AsyncFineTuningWithRawResponse,
FineTuningWithStreamingResponse,
AsyncFineTuningWithStreamingResponse,
)
from .moderations import (
Moderations,
AsyncModerations,
ModerationsWithRawResponse,
AsyncModerationsWithRawResponse,
ModerationsWithStreamingResponse,
AsyncModerationsWithStreamingResponse,
)
from .vector_stores import (
VectorStores,
AsyncVectorStores,
VectorStoresWithRawResponse,
AsyncVectorStoresWithRawResponse,
VectorStoresWithStreamingResponse,
AsyncVectorStoresWithStreamingResponse,
)
__all__ = [
"Completions",
"AsyncCompletions",
"CompletionsWithRawResponse",
"AsyncCompletionsWithRawResponse",
"CompletionsWithStreamingResponse",
"AsyncCompletionsWithStreamingResponse",
"Chat",
"AsyncChat",
"ChatWithRawResponse",
"AsyncChatWithRawResponse",
"ChatWithStreamingResponse",
"AsyncChatWithStreamingResponse",
"Embeddings",
"AsyncEmbeddings",
"EmbeddingsWithRawResponse",
"AsyncEmbeddingsWithRawResponse",
"EmbeddingsWithStreamingResponse",
"AsyncEmbeddingsWithStreamingResponse",
"Files",
"AsyncFiles",
"FilesWithRawResponse",
"AsyncFilesWithRawResponse",
"FilesWithStreamingResponse",
"AsyncFilesWithStreamingResponse",
"Images",
"AsyncImages",
"ImagesWithRawResponse",
"AsyncImagesWithRawResponse",
"ImagesWithStreamingResponse",
"AsyncImagesWithStreamingResponse",
"Audio",
"AsyncAudio",
"AudioWithRawResponse",
"AsyncAudioWithRawResponse",
"AudioWithStreamingResponse",
"AsyncAudioWithStreamingResponse",
"Moderations",
"AsyncModerations",
"ModerationsWithRawResponse",
"AsyncModerationsWithRawResponse",
"ModerationsWithStreamingResponse",
"AsyncModerationsWithStreamingResponse",
"Models",
"AsyncModels",
"ModelsWithRawResponse",
"AsyncModelsWithRawResponse",
"ModelsWithStreamingResponse",
"AsyncModelsWithStreamingResponse",
"FineTuning",
"AsyncFineTuning",
"FineTuningWithRawResponse",
"AsyncFineTuningWithRawResponse",
"FineTuningWithStreamingResponse",
"AsyncFineTuningWithStreamingResponse",
"VectorStores",
"AsyncVectorStores",
"VectorStoresWithRawResponse",
"AsyncVectorStoresWithRawResponse",
"VectorStoresWithStreamingResponse",
"AsyncVectorStoresWithStreamingResponse",
"Beta",
"AsyncBeta",
"BetaWithRawResponse",
"AsyncBetaWithRawResponse",
"BetaWithStreamingResponse",
"AsyncBetaWithStreamingResponse",
"Batches",
"AsyncBatches",
"BatchesWithRawResponse",
"AsyncBatchesWithRawResponse",
"BatchesWithStreamingResponse",
"AsyncBatchesWithStreamingResponse",
"Uploads",
"AsyncUploads",
"UploadsWithRawResponse",
"AsyncUploadsWithRawResponse",
"UploadsWithStreamingResponse",
"AsyncUploadsWithStreamingResponse",
"Admin",
"AsyncAdmin",
"AdminWithRawResponse",
"AsyncAdminWithRawResponse",
"AdminWithStreamingResponse",
"AsyncAdminWithStreamingResponse",
"Evals",
"AsyncEvals",
"EvalsWithRawResponse",
"AsyncEvalsWithRawResponse",
"EvalsWithStreamingResponse",
"AsyncEvalsWithStreamingResponse",
"Containers",
"AsyncContainers",
"ContainersWithRawResponse",
"AsyncContainersWithRawResponse",
"ContainersWithStreamingResponse",
"AsyncContainersWithStreamingResponse",
"Skills",
"AsyncSkills",
"SkillsWithRawResponse",
"AsyncSkillsWithRawResponse",
"SkillsWithStreamingResponse",
"AsyncSkillsWithStreamingResponse",
"Videos",
"AsyncVideos",
"VideosWithRawResponse",
"AsyncVideosWithRawResponse",
"VideosWithStreamingResponse",
"AsyncVideosWithStreamingResponse",
]

View File

@@ -0,0 +1,33 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .admin import (
Admin,
AsyncAdmin,
AdminWithRawResponse,
AsyncAdminWithRawResponse,
AdminWithStreamingResponse,
AsyncAdminWithStreamingResponse,
)
from .organization import (
Organization,
AsyncOrganization,
OrganizationWithRawResponse,
AsyncOrganizationWithRawResponse,
OrganizationWithStreamingResponse,
AsyncOrganizationWithStreamingResponse,
)
__all__ = [
"Organization",
"AsyncOrganization",
"OrganizationWithRawResponse",
"AsyncOrganizationWithRawResponse",
"OrganizationWithStreamingResponse",
"AsyncOrganizationWithStreamingResponse",
"Admin",
"AsyncAdmin",
"AdminWithRawResponse",
"AsyncAdminWithRawResponse",
"AdminWithStreamingResponse",
"AsyncAdminWithStreamingResponse",
]

View File

@@ -0,0 +1,102 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from .organization.organization import (
Organization,
AsyncOrganization,
OrganizationWithRawResponse,
AsyncOrganizationWithRawResponse,
OrganizationWithStreamingResponse,
AsyncOrganizationWithStreamingResponse,
)
__all__ = ["Admin", "AsyncAdmin"]
class Admin(SyncAPIResource):
@cached_property
def organization(self) -> Organization:
return Organization(self._client)
@cached_property
def with_raw_response(self) -> AdminWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AdminWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AdminWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AdminWithStreamingResponse(self)
class AsyncAdmin(AsyncAPIResource):
@cached_property
def organization(self) -> AsyncOrganization:
return AsyncOrganization(self._client)
@cached_property
def with_raw_response(self) -> AsyncAdminWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncAdminWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncAdminWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncAdminWithStreamingResponse(self)
class AdminWithRawResponse:
def __init__(self, admin: Admin) -> None:
self._admin = admin
@cached_property
def organization(self) -> OrganizationWithRawResponse:
return OrganizationWithRawResponse(self._admin.organization)
class AsyncAdminWithRawResponse:
def __init__(self, admin: AsyncAdmin) -> None:
self._admin = admin
@cached_property
def organization(self) -> AsyncOrganizationWithRawResponse:
return AsyncOrganizationWithRawResponse(self._admin.organization)
class AdminWithStreamingResponse:
def __init__(self, admin: Admin) -> None:
self._admin = admin
@cached_property
def organization(self) -> OrganizationWithStreamingResponse:
return OrganizationWithStreamingResponse(self._admin.organization)
class AsyncAdminWithStreamingResponse:
def __init__(self, admin: AsyncAdmin) -> None:
self._admin = admin
@cached_property
def organization(self) -> AsyncOrganizationWithStreamingResponse:
return AsyncOrganizationWithStreamingResponse(self._admin.organization)

View File

@@ -0,0 +1,145 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .usage import (
Usage,
AsyncUsage,
UsageWithRawResponse,
AsyncUsageWithRawResponse,
UsageWithStreamingResponse,
AsyncUsageWithStreamingResponse,
)
from .users import (
Users,
AsyncUsers,
UsersWithRawResponse,
AsyncUsersWithRawResponse,
UsersWithStreamingResponse,
AsyncUsersWithStreamingResponse,
)
from .groups import (
Groups,
AsyncGroups,
GroupsWithRawResponse,
AsyncGroupsWithRawResponse,
GroupsWithStreamingResponse,
AsyncGroupsWithStreamingResponse,
)
from .invites import (
Invites,
AsyncInvites,
InvitesWithRawResponse,
AsyncInvitesWithRawResponse,
InvitesWithStreamingResponse,
AsyncInvitesWithStreamingResponse,
)
from .projects import (
Projects,
AsyncProjects,
ProjectsWithRawResponse,
AsyncProjectsWithRawResponse,
ProjectsWithStreamingResponse,
AsyncProjectsWithStreamingResponse,
)
from .audit_logs import (
AuditLogs,
AsyncAuditLogs,
AuditLogsWithRawResponse,
AsyncAuditLogsWithRawResponse,
AuditLogsWithStreamingResponse,
AsyncAuditLogsWithStreamingResponse,
)
from .certificates import (
Certificates,
AsyncCertificates,
CertificatesWithRawResponse,
AsyncCertificatesWithRawResponse,
CertificatesWithStreamingResponse,
AsyncCertificatesWithStreamingResponse,
)
from .organization import (
Organization,
AsyncOrganization,
OrganizationWithRawResponse,
AsyncOrganizationWithRawResponse,
OrganizationWithStreamingResponse,
AsyncOrganizationWithStreamingResponse,
)
from .admin_api_keys import (
AdminAPIKeys,
AsyncAdminAPIKeys,
AdminAPIKeysWithRawResponse,
AsyncAdminAPIKeysWithRawResponse,
AdminAPIKeysWithStreamingResponse,
AsyncAdminAPIKeysWithStreamingResponse,
)
__all__ = [
"AuditLogs",
"AsyncAuditLogs",
"AuditLogsWithRawResponse",
"AsyncAuditLogsWithRawResponse",
"AuditLogsWithStreamingResponse",
"AsyncAuditLogsWithStreamingResponse",
"AdminAPIKeys",
"AsyncAdminAPIKeys",
"AdminAPIKeysWithRawResponse",
"AsyncAdminAPIKeysWithRawResponse",
"AdminAPIKeysWithStreamingResponse",
"AsyncAdminAPIKeysWithStreamingResponse",
"Usage",
"AsyncUsage",
"UsageWithRawResponse",
"AsyncUsageWithRawResponse",
"UsageWithStreamingResponse",
"AsyncUsageWithStreamingResponse",
"Invites",
"AsyncInvites",
"InvitesWithRawResponse",
"AsyncInvitesWithRawResponse",
"InvitesWithStreamingResponse",
"AsyncInvitesWithStreamingResponse",
"Users",
"AsyncUsers",
"UsersWithRawResponse",
"AsyncUsersWithRawResponse",
"UsersWithStreamingResponse",
"AsyncUsersWithStreamingResponse",
"Groups",
"AsyncGroups",
"GroupsWithRawResponse",
"AsyncGroupsWithRawResponse",
"GroupsWithStreamingResponse",
"AsyncGroupsWithStreamingResponse",
"Roles",
"AsyncRoles",
"RolesWithRawResponse",
"AsyncRolesWithRawResponse",
"RolesWithStreamingResponse",
"AsyncRolesWithStreamingResponse",
"Certificates",
"AsyncCertificates",
"CertificatesWithRawResponse",
"AsyncCertificatesWithRawResponse",
"CertificatesWithStreamingResponse",
"AsyncCertificatesWithStreamingResponse",
"Projects",
"AsyncProjects",
"ProjectsWithRawResponse",
"AsyncProjectsWithRawResponse",
"ProjectsWithStreamingResponse",
"AsyncProjectsWithStreamingResponse",
"Organization",
"AsyncOrganization",
"OrganizationWithRawResponse",
"AsyncOrganizationWithRawResponse",
"OrganizationWithStreamingResponse",
"AsyncOrganizationWithStreamingResponse",
]

View File

@@ -0,0 +1,469 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Optional
from typing_extensions import Literal
import httpx
from .... import _legacy_response
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ...._utils import path_template, maybe_transform, async_maybe_transform
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ....pagination import SyncCursorPage, AsyncCursorPage
from ...._base_client import AsyncPaginator, make_request_options
from ....types.admin.organization import admin_api_key_list_params, admin_api_key_create_params
from ....types.admin.organization.admin_api_key import AdminAPIKey
from ....types.admin.organization.admin_api_key_create_response import AdminAPIKeyCreateResponse
from ....types.admin.organization.admin_api_key_delete_response import AdminAPIKeyDeleteResponse
__all__ = ["AdminAPIKeys", "AsyncAdminAPIKeys"]
class AdminAPIKeys(SyncAPIResource):
@cached_property
def with_raw_response(self) -> AdminAPIKeysWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AdminAPIKeysWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AdminAPIKeysWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AdminAPIKeysWithStreamingResponse(self)
def create(
self,
*,
name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AdminAPIKeyCreateResponse:
"""
Create an organization admin API key
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/organization/admin_api_keys",
body=maybe_transform({"name": name}, admin_api_key_create_params.AdminAPIKeyCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=AdminAPIKeyCreateResponse,
)
def retrieve(
self,
key_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AdminAPIKey:
"""
Retrieve a single organization API key
Args:
key_id: The ID of the API key.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not key_id:
raise ValueError(f"Expected a non-empty value for `key_id` but received {key_id!r}")
return self._get(
path_template("/organization/admin_api_keys/{key_id}", key_id=key_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=AdminAPIKey,
)
def list(
self,
*,
after: Optional[str] | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncCursorPage[AdminAPIKey]:
"""
List organization API keys
Args:
after: Return keys with IDs that come after this ID in the pagination order.
limit: Maximum number of keys to return.
order: Order results by creation time, ascending or descending.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/admin_api_keys",
page=SyncCursorPage[AdminAPIKey],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
admin_api_key_list_params.AdminAPIKeyListParams,
),
security={"admin_api_key_auth": True},
),
model=AdminAPIKey,
)
def delete(
self,
key_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AdminAPIKeyDeleteResponse:
"""
Delete an organization admin API key
Args:
key_id: The ID of the API key to be deleted.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not key_id:
raise ValueError(f"Expected a non-empty value for `key_id` but received {key_id!r}")
return self._delete(
path_template("/organization/admin_api_keys/{key_id}", key_id=key_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=AdminAPIKeyDeleteResponse,
)
class AsyncAdminAPIKeys(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncAdminAPIKeysWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncAdminAPIKeysWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncAdminAPIKeysWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncAdminAPIKeysWithStreamingResponse(self)
async def create(
self,
*,
name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AdminAPIKeyCreateResponse:
"""
Create an organization admin API key
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/organization/admin_api_keys",
body=await async_maybe_transform({"name": name}, admin_api_key_create_params.AdminAPIKeyCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=AdminAPIKeyCreateResponse,
)
async def retrieve(
self,
key_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AdminAPIKey:
"""
Retrieve a single organization API key
Args:
key_id: The ID of the API key.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not key_id:
raise ValueError(f"Expected a non-empty value for `key_id` but received {key_id!r}")
return await self._get(
path_template("/organization/admin_api_keys/{key_id}", key_id=key_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=AdminAPIKey,
)
def list(
self,
*,
after: Optional[str] | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[AdminAPIKey, AsyncCursorPage[AdminAPIKey]]:
"""
List organization API keys
Args:
after: Return keys with IDs that come after this ID in the pagination order.
limit: Maximum number of keys to return.
order: Order results by creation time, ascending or descending.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/admin_api_keys",
page=AsyncCursorPage[AdminAPIKey],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
admin_api_key_list_params.AdminAPIKeyListParams,
),
security={"admin_api_key_auth": True},
),
model=AdminAPIKey,
)
async def delete(
self,
key_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AdminAPIKeyDeleteResponse:
"""
Delete an organization admin API key
Args:
key_id: The ID of the API key to be deleted.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not key_id:
raise ValueError(f"Expected a non-empty value for `key_id` but received {key_id!r}")
return await self._delete(
path_template("/organization/admin_api_keys/{key_id}", key_id=key_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=AdminAPIKeyDeleteResponse,
)
class AdminAPIKeysWithRawResponse:
def __init__(self, admin_api_keys: AdminAPIKeys) -> None:
self._admin_api_keys = admin_api_keys
self.create = _legacy_response.to_raw_response_wrapper(
admin_api_keys.create,
)
self.retrieve = _legacy_response.to_raw_response_wrapper(
admin_api_keys.retrieve,
)
self.list = _legacy_response.to_raw_response_wrapper(
admin_api_keys.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
admin_api_keys.delete,
)
class AsyncAdminAPIKeysWithRawResponse:
def __init__(self, admin_api_keys: AsyncAdminAPIKeys) -> None:
self._admin_api_keys = admin_api_keys
self.create = _legacy_response.async_to_raw_response_wrapper(
admin_api_keys.create,
)
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
admin_api_keys.retrieve,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
admin_api_keys.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
admin_api_keys.delete,
)
class AdminAPIKeysWithStreamingResponse:
def __init__(self, admin_api_keys: AdminAPIKeys) -> None:
self._admin_api_keys = admin_api_keys
self.create = to_streamed_response_wrapper(
admin_api_keys.create,
)
self.retrieve = to_streamed_response_wrapper(
admin_api_keys.retrieve,
)
self.list = to_streamed_response_wrapper(
admin_api_keys.list,
)
self.delete = to_streamed_response_wrapper(
admin_api_keys.delete,
)
class AsyncAdminAPIKeysWithStreamingResponse:
def __init__(self, admin_api_keys: AsyncAdminAPIKeys) -> None:
self._admin_api_keys = admin_api_keys
self.create = async_to_streamed_response_wrapper(
admin_api_keys.create,
)
self.retrieve = async_to_streamed_response_wrapper(
admin_api_keys.retrieve,
)
self.list = async_to_streamed_response_wrapper(
admin_api_keys.list,
)
self.delete = async_to_streamed_response_wrapper(
admin_api_keys.delete,
)

View File

@@ -0,0 +1,387 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import List
from typing_extensions import Literal
import httpx
from .... import _legacy_response
from ...._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
from ...._utils import maybe_transform
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ....pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ...._base_client import AsyncPaginator, make_request_options
from ....types.admin.organization import audit_log_list_params
from ....types.admin.organization.audit_log_list_response import AuditLogListResponse
__all__ = ["AuditLogs", "AsyncAuditLogs"]
class AuditLogs(SyncAPIResource):
"""List user actions and configuration changes within this organization."""
@cached_property
def with_raw_response(self) -> AuditLogsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AuditLogsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AuditLogsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AuditLogsWithStreamingResponse(self)
def list(
self,
*,
actor_emails: SequenceNotStr[str] | Omit = omit,
actor_ids: SequenceNotStr[str] | Omit = omit,
after: str | Omit = omit,
before: str | Omit = omit,
effective_at: audit_log_list_params.EffectiveAt | Omit = omit,
event_types: List[
Literal[
"api_key.created",
"api_key.updated",
"api_key.deleted",
"certificate.created",
"certificate.updated",
"certificate.deleted",
"certificates.activated",
"certificates.deactivated",
"checkpoint.permission.created",
"checkpoint.permission.deleted",
"external_key.registered",
"external_key.removed",
"group.created",
"group.updated",
"group.deleted",
"invite.sent",
"invite.accepted",
"invite.deleted",
"ip_allowlist.created",
"ip_allowlist.updated",
"ip_allowlist.deleted",
"ip_allowlist.config.activated",
"ip_allowlist.config.deactivated",
"login.succeeded",
"login.failed",
"logout.succeeded",
"logout.failed",
"organization.updated",
"project.created",
"project.updated",
"project.archived",
"project.deleted",
"rate_limit.updated",
"rate_limit.deleted",
"resource.deleted",
"tunnel.created",
"tunnel.updated",
"tunnel.deleted",
"role.created",
"role.updated",
"role.deleted",
"role.assignment.created",
"role.assignment.deleted",
"scim.enabled",
"scim.disabled",
"service_account.created",
"service_account.updated",
"service_account.deleted",
"user.added",
"user.updated",
"user.deleted",
]
]
| Omit = omit,
limit: int | Omit = omit,
project_ids: SequenceNotStr[str] | Omit = omit,
resource_ids: SequenceNotStr[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[AuditLogListResponse]:
"""
List user actions and configuration changes within this organization.
Args:
actor_emails: Return only events performed by users with these emails.
actor_ids: Return only events performed by these actors. Can be a user ID, a service
account ID, or an api key tracking ID.
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
before: A cursor for use in pagination. `before` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
starting with obj_foo, your subsequent call can include before=obj_foo in order
to fetch the previous page of the list.
effective_at: Return only events whose `effective_at` (Unix seconds) is in this range.
event_types: Return only events with a `type` in one of these values. For example,
`project.created`. For all options, see the documentation for the
[audit log object](https://platform.openai.com/docs/api-reference/audit-logs/object).
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
project_ids: Return only events for these projects.
resource_ids: Return only events performed on these targets. For example, a project ID
updated.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/audit_logs",
page=SyncConversationCursorPage[AuditLogListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"actor_emails": actor_emails,
"actor_ids": actor_ids,
"after": after,
"before": before,
"effective_at": effective_at,
"event_types": event_types,
"limit": limit,
"project_ids": project_ids,
"resource_ids": resource_ids,
},
audit_log_list_params.AuditLogListParams,
),
security={"admin_api_key_auth": True},
),
model=AuditLogListResponse,
)
class AsyncAuditLogs(AsyncAPIResource):
"""List user actions and configuration changes within this organization."""
@cached_property
def with_raw_response(self) -> AsyncAuditLogsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncAuditLogsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncAuditLogsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncAuditLogsWithStreamingResponse(self)
def list(
self,
*,
actor_emails: SequenceNotStr[str] | Omit = omit,
actor_ids: SequenceNotStr[str] | Omit = omit,
after: str | Omit = omit,
before: str | Omit = omit,
effective_at: audit_log_list_params.EffectiveAt | Omit = omit,
event_types: List[
Literal[
"api_key.created",
"api_key.updated",
"api_key.deleted",
"certificate.created",
"certificate.updated",
"certificate.deleted",
"certificates.activated",
"certificates.deactivated",
"checkpoint.permission.created",
"checkpoint.permission.deleted",
"external_key.registered",
"external_key.removed",
"group.created",
"group.updated",
"group.deleted",
"invite.sent",
"invite.accepted",
"invite.deleted",
"ip_allowlist.created",
"ip_allowlist.updated",
"ip_allowlist.deleted",
"ip_allowlist.config.activated",
"ip_allowlist.config.deactivated",
"login.succeeded",
"login.failed",
"logout.succeeded",
"logout.failed",
"organization.updated",
"project.created",
"project.updated",
"project.archived",
"project.deleted",
"rate_limit.updated",
"rate_limit.deleted",
"resource.deleted",
"tunnel.created",
"tunnel.updated",
"tunnel.deleted",
"role.created",
"role.updated",
"role.deleted",
"role.assignment.created",
"role.assignment.deleted",
"scim.enabled",
"scim.disabled",
"service_account.created",
"service_account.updated",
"service_account.deleted",
"user.added",
"user.updated",
"user.deleted",
]
]
| Omit = omit,
limit: int | Omit = omit,
project_ids: SequenceNotStr[str] | Omit = omit,
resource_ids: SequenceNotStr[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[AuditLogListResponse, AsyncConversationCursorPage[AuditLogListResponse]]:
"""
List user actions and configuration changes within this organization.
Args:
actor_emails: Return only events performed by users with these emails.
actor_ids: Return only events performed by these actors. Can be a user ID, a service
account ID, or an api key tracking ID.
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
before: A cursor for use in pagination. `before` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
starting with obj_foo, your subsequent call can include before=obj_foo in order
to fetch the previous page of the list.
effective_at: Return only events whose `effective_at` (Unix seconds) is in this range.
event_types: Return only events with a `type` in one of these values. For example,
`project.created`. For all options, see the documentation for the
[audit log object](https://platform.openai.com/docs/api-reference/audit-logs/object).
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
project_ids: Return only events for these projects.
resource_ids: Return only events performed on these targets. For example, a project ID
updated.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/audit_logs",
page=AsyncConversationCursorPage[AuditLogListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"actor_emails": actor_emails,
"actor_ids": actor_ids,
"after": after,
"before": before,
"effective_at": effective_at,
"event_types": event_types,
"limit": limit,
"project_ids": project_ids,
"resource_ids": resource_ids,
},
audit_log_list_params.AuditLogListParams,
),
security={"admin_api_key_auth": True},
),
model=AuditLogListResponse,
)
class AuditLogsWithRawResponse:
def __init__(self, audit_logs: AuditLogs) -> None:
self._audit_logs = audit_logs
self.list = _legacy_response.to_raw_response_wrapper(
audit_logs.list,
)
class AsyncAuditLogsWithRawResponse:
def __init__(self, audit_logs: AsyncAuditLogs) -> None:
self._audit_logs = audit_logs
self.list = _legacy_response.async_to_raw_response_wrapper(
audit_logs.list,
)
class AuditLogsWithStreamingResponse:
def __init__(self, audit_logs: AuditLogs) -> None:
self._audit_logs = audit_logs
self.list = to_streamed_response_wrapper(
audit_logs.list,
)
class AsyncAuditLogsWithStreamingResponse:
def __init__(self, audit_logs: AsyncAuditLogs) -> None:
self._audit_logs = audit_logs
self.list = async_to_streamed_response_wrapper(
audit_logs.list,
)

View File

@@ -0,0 +1,818 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import List
from typing_extensions import Literal
import httpx
from .... import _legacy_response
from ...._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
from ...._utils import path_template, maybe_transform, async_maybe_transform
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ....pagination import SyncPage, AsyncPage, SyncConversationCursorPage, AsyncConversationCursorPage
from ...._base_client import AsyncPaginator, make_request_options
from ....types.admin.organization import (
certificate_list_params,
certificate_create_params,
certificate_update_params,
certificate_activate_params,
certificate_retrieve_params,
certificate_deactivate_params,
)
from ....types.admin.organization.certificate import Certificate
from ....types.admin.organization.certificate_list_response import CertificateListResponse
from ....types.admin.organization.certificate_delete_response import CertificateDeleteResponse
from ....types.admin.organization.certificate_activate_response import CertificateActivateResponse
from ....types.admin.organization.certificate_deactivate_response import CertificateDeactivateResponse
__all__ = ["Certificates", "AsyncCertificates"]
class Certificates(SyncAPIResource):
@cached_property
def with_raw_response(self) -> CertificatesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return CertificatesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> CertificatesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return CertificatesWithStreamingResponse(self)
def create(
self,
*,
certificate: str,
name: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Certificate:
"""Upload a certificate to the organization.
This does **not** automatically
activate the certificate.
Organizations can upload up to 50 certificates.
Args:
certificate: The certificate content in PEM format
name: An optional name for the certificate
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/organization/certificates",
body=maybe_transform(
{
"certificate": certificate,
"name": name,
},
certificate_create_params.CertificateCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Certificate,
)
def retrieve(
self,
certificate_id: str,
*,
include: List[Literal["content"]] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Certificate:
"""
Get a certificate that has been uploaded to the organization.
You can get a certificate regardless of whether it is active or not.
Args:
include: A list of additional fields to include in the response. Currently the only
supported value is `content` to fetch the PEM content of the certificate.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not certificate_id:
raise ValueError(f"Expected a non-empty value for `certificate_id` but received {certificate_id!r}")
return self._get(
path_template("/organization/certificates/{certificate_id}", certificate_id=certificate_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform({"include": include}, certificate_retrieve_params.CertificateRetrieveParams),
security={"admin_api_key_auth": True},
),
cast_to=Certificate,
)
def update(
self,
certificate_id: str,
*,
name: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Certificate:
"""Modify a certificate.
Note that only the name can be modified.
Args:
name: The updated name for the certificate
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not certificate_id:
raise ValueError(f"Expected a non-empty value for `certificate_id` but received {certificate_id!r}")
return self._post(
path_template("/organization/certificates/{certificate_id}", certificate_id=certificate_id),
body=maybe_transform({"name": name}, certificate_update_params.CertificateUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Certificate,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[CertificateListResponse]:
"""
List uploaded certificates for this organization.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
order and `desc` for descending order.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/certificates",
page=SyncConversationCursorPage[CertificateListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
certificate_list_params.CertificateListParams,
),
security={"admin_api_key_auth": True},
),
model=CertificateListResponse,
)
def delete(
self,
certificate_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> CertificateDeleteResponse:
"""
Delete a certificate from the organization.
The certificate must be inactive for the organization and all projects.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not certificate_id:
raise ValueError(f"Expected a non-empty value for `certificate_id` but received {certificate_id!r}")
return self._delete(
path_template("/organization/certificates/{certificate_id}", certificate_id=certificate_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=CertificateDeleteResponse,
)
def activate(
self,
*,
certificate_ids: SequenceNotStr[str],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncPage[CertificateActivateResponse]:
"""
Activate certificates at the organization level.
You can atomically and idempotently activate up to 10 certificates at a time.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/certificates/activate",
page=SyncPage[CertificateActivateResponse],
body=maybe_transform(
{"certificate_ids": certificate_ids}, certificate_activate_params.CertificateActivateParams
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
model=CertificateActivateResponse,
method="post",
)
def deactivate(
self,
*,
certificate_ids: SequenceNotStr[str],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncPage[CertificateDeactivateResponse]:
"""
Deactivate certificates at the organization level.
You can atomically and idempotently deactivate up to 10 certificates at a time.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/certificates/deactivate",
page=SyncPage[CertificateDeactivateResponse],
body=maybe_transform(
{"certificate_ids": certificate_ids}, certificate_deactivate_params.CertificateDeactivateParams
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
model=CertificateDeactivateResponse,
method="post",
)
class AsyncCertificates(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncCertificatesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncCertificatesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncCertificatesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncCertificatesWithStreamingResponse(self)
async def create(
self,
*,
certificate: str,
name: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Certificate:
"""Upload a certificate to the organization.
This does **not** automatically
activate the certificate.
Organizations can upload up to 50 certificates.
Args:
certificate: The certificate content in PEM format
name: An optional name for the certificate
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/organization/certificates",
body=await async_maybe_transform(
{
"certificate": certificate,
"name": name,
},
certificate_create_params.CertificateCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Certificate,
)
async def retrieve(
self,
certificate_id: str,
*,
include: List[Literal["content"]] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Certificate:
"""
Get a certificate that has been uploaded to the organization.
You can get a certificate regardless of whether it is active or not.
Args:
include: A list of additional fields to include in the response. Currently the only
supported value is `content` to fetch the PEM content of the certificate.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not certificate_id:
raise ValueError(f"Expected a non-empty value for `certificate_id` but received {certificate_id!r}")
return await self._get(
path_template("/organization/certificates/{certificate_id}", certificate_id=certificate_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=await async_maybe_transform(
{"include": include}, certificate_retrieve_params.CertificateRetrieveParams
),
security={"admin_api_key_auth": True},
),
cast_to=Certificate,
)
async def update(
self,
certificate_id: str,
*,
name: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Certificate:
"""Modify a certificate.
Note that only the name can be modified.
Args:
name: The updated name for the certificate
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not certificate_id:
raise ValueError(f"Expected a non-empty value for `certificate_id` but received {certificate_id!r}")
return await self._post(
path_template("/organization/certificates/{certificate_id}", certificate_id=certificate_id),
body=await async_maybe_transform({"name": name}, certificate_update_params.CertificateUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Certificate,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[CertificateListResponse, AsyncConversationCursorPage[CertificateListResponse]]:
"""
List uploaded certificates for this organization.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
order and `desc` for descending order.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/certificates",
page=AsyncConversationCursorPage[CertificateListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
certificate_list_params.CertificateListParams,
),
security={"admin_api_key_auth": True},
),
model=CertificateListResponse,
)
async def delete(
self,
certificate_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> CertificateDeleteResponse:
"""
Delete a certificate from the organization.
The certificate must be inactive for the organization and all projects.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not certificate_id:
raise ValueError(f"Expected a non-empty value for `certificate_id` but received {certificate_id!r}")
return await self._delete(
path_template("/organization/certificates/{certificate_id}", certificate_id=certificate_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=CertificateDeleteResponse,
)
def activate(
self,
*,
certificate_ids: SequenceNotStr[str],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[CertificateActivateResponse, AsyncPage[CertificateActivateResponse]]:
"""
Activate certificates at the organization level.
You can atomically and idempotently activate up to 10 certificates at a time.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/certificates/activate",
page=AsyncPage[CertificateActivateResponse],
body=maybe_transform(
{"certificate_ids": certificate_ids}, certificate_activate_params.CertificateActivateParams
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
model=CertificateActivateResponse,
method="post",
)
def deactivate(
self,
*,
certificate_ids: SequenceNotStr[str],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[CertificateDeactivateResponse, AsyncPage[CertificateDeactivateResponse]]:
"""
Deactivate certificates at the organization level.
You can atomically and idempotently deactivate up to 10 certificates at a time.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/certificates/deactivate",
page=AsyncPage[CertificateDeactivateResponse],
body=maybe_transform(
{"certificate_ids": certificate_ids}, certificate_deactivate_params.CertificateDeactivateParams
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
model=CertificateDeactivateResponse,
method="post",
)
class CertificatesWithRawResponse:
def __init__(self, certificates: Certificates) -> None:
self._certificates = certificates
self.create = _legacy_response.to_raw_response_wrapper(
certificates.create,
)
self.retrieve = _legacy_response.to_raw_response_wrapper(
certificates.retrieve,
)
self.update = _legacy_response.to_raw_response_wrapper(
certificates.update,
)
self.list = _legacy_response.to_raw_response_wrapper(
certificates.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
certificates.delete,
)
self.activate = _legacy_response.to_raw_response_wrapper(
certificates.activate,
)
self.deactivate = _legacy_response.to_raw_response_wrapper(
certificates.deactivate,
)
class AsyncCertificatesWithRawResponse:
def __init__(self, certificates: AsyncCertificates) -> None:
self._certificates = certificates
self.create = _legacy_response.async_to_raw_response_wrapper(
certificates.create,
)
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
certificates.retrieve,
)
self.update = _legacy_response.async_to_raw_response_wrapper(
certificates.update,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
certificates.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
certificates.delete,
)
self.activate = _legacy_response.async_to_raw_response_wrapper(
certificates.activate,
)
self.deactivate = _legacy_response.async_to_raw_response_wrapper(
certificates.deactivate,
)
class CertificatesWithStreamingResponse:
def __init__(self, certificates: Certificates) -> None:
self._certificates = certificates
self.create = to_streamed_response_wrapper(
certificates.create,
)
self.retrieve = to_streamed_response_wrapper(
certificates.retrieve,
)
self.update = to_streamed_response_wrapper(
certificates.update,
)
self.list = to_streamed_response_wrapper(
certificates.list,
)
self.delete = to_streamed_response_wrapper(
certificates.delete,
)
self.activate = to_streamed_response_wrapper(
certificates.activate,
)
self.deactivate = to_streamed_response_wrapper(
certificates.deactivate,
)
class AsyncCertificatesWithStreamingResponse:
def __init__(self, certificates: AsyncCertificates) -> None:
self._certificates = certificates
self.create = async_to_streamed_response_wrapper(
certificates.create,
)
self.retrieve = async_to_streamed_response_wrapper(
certificates.retrieve,
)
self.update = async_to_streamed_response_wrapper(
certificates.update,
)
self.list = async_to_streamed_response_wrapper(
certificates.list,
)
self.delete = async_to_streamed_response_wrapper(
certificates.delete,
)
self.activate = async_to_streamed_response_wrapper(
certificates.activate,
)
self.deactivate = async_to_streamed_response_wrapper(
certificates.deactivate,
)

View File

@@ -0,0 +1,47 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .users import (
Users,
AsyncUsers,
UsersWithRawResponse,
AsyncUsersWithRawResponse,
UsersWithStreamingResponse,
AsyncUsersWithStreamingResponse,
)
from .groups import (
Groups,
AsyncGroups,
GroupsWithRawResponse,
AsyncGroupsWithRawResponse,
GroupsWithStreamingResponse,
AsyncGroupsWithStreamingResponse,
)
__all__ = [
"Users",
"AsyncUsers",
"UsersWithRawResponse",
"AsyncUsersWithRawResponse",
"UsersWithStreamingResponse",
"AsyncUsersWithStreamingResponse",
"Roles",
"AsyncRoles",
"RolesWithRawResponse",
"AsyncRolesWithRawResponse",
"RolesWithStreamingResponse",
"AsyncRolesWithStreamingResponse",
"Groups",
"AsyncGroups",
"GroupsWithRawResponse",
"AsyncGroupsWithRawResponse",
"GroupsWithStreamingResponse",
"AsyncGroupsWithStreamingResponse",
]

View File

@@ -0,0 +1,544 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ..... import _legacy_response
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .users import (
Users,
AsyncUsers,
UsersWithRawResponse,
AsyncUsersWithRawResponse,
UsersWithStreamingResponse,
AsyncUsersWithStreamingResponse,
)
from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncNextCursorPage, AsyncNextCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization import group_list_params, group_create_params, group_update_params
from .....types.admin.organization.group import Group
from .....types.admin.organization.group_delete_response import GroupDeleteResponse
from .....types.admin.organization.group_update_response import GroupUpdateResponse
__all__ = ["Groups", "AsyncGroups"]
class Groups(SyncAPIResource):
@cached_property
def users(self) -> Users:
return Users(self._client)
@cached_property
def roles(self) -> Roles:
return Roles(self._client)
@cached_property
def with_raw_response(self) -> GroupsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return GroupsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> GroupsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return GroupsWithStreamingResponse(self)
def create(
self,
*,
name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Group:
"""
Creates a new group in the organization.
Args:
name: Human readable name for the group.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/organization/groups",
body=maybe_transform({"name": name}, group_create_params.GroupCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Group,
)
def update(
self,
group_id: str,
*,
name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> GroupUpdateResponse:
"""
Updates a group's information.
Args:
name: New display name for the group.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._post(
path_template("/organization/groups/{group_id}", group_id=group_id),
body=maybe_transform({"name": name}, group_update_params.GroupUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=GroupUpdateResponse,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[Group]:
"""
Lists all groups in the organization.
Args:
after: A cursor for use in pagination. `after` is a group ID that defines your place in
the list. For instance, if you make a list request and receive 100 objects,
ending with group_abc, your subsequent call can include `after=group_abc` in
order to fetch the next page of the list.
limit: A limit on the number of groups to be returned. Limit can range between 0 and
1000, and the default is 100.
order: Specifies the sort order of the returned groups.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/groups",
page=SyncNextCursorPage[Group],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
group_list_params.GroupListParams,
),
security={"admin_api_key_auth": True},
),
model=Group,
)
def delete(
self,
group_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> GroupDeleteResponse:
"""
Deletes a group from the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._delete(
path_template("/organization/groups/{group_id}", group_id=group_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=GroupDeleteResponse,
)
class AsyncGroups(AsyncAPIResource):
@cached_property
def users(self) -> AsyncUsers:
return AsyncUsers(self._client)
@cached_property
def roles(self) -> AsyncRoles:
return AsyncRoles(self._client)
@cached_property
def with_raw_response(self) -> AsyncGroupsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncGroupsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncGroupsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncGroupsWithStreamingResponse(self)
async def create(
self,
*,
name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Group:
"""
Creates a new group in the organization.
Args:
name: Human readable name for the group.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/organization/groups",
body=await async_maybe_transform({"name": name}, group_create_params.GroupCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Group,
)
async def update(
self,
group_id: str,
*,
name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> GroupUpdateResponse:
"""
Updates a group's information.
Args:
name: New display name for the group.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return await self._post(
path_template("/organization/groups/{group_id}", group_id=group_id),
body=await async_maybe_transform({"name": name}, group_update_params.GroupUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=GroupUpdateResponse,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[Group, AsyncNextCursorPage[Group]]:
"""
Lists all groups in the organization.
Args:
after: A cursor for use in pagination. `after` is a group ID that defines your place in
the list. For instance, if you make a list request and receive 100 objects,
ending with group_abc, your subsequent call can include `after=group_abc` in
order to fetch the next page of the list.
limit: A limit on the number of groups to be returned. Limit can range between 0 and
1000, and the default is 100.
order: Specifies the sort order of the returned groups.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/groups",
page=AsyncNextCursorPage[Group],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
group_list_params.GroupListParams,
),
security={"admin_api_key_auth": True},
),
model=Group,
)
async def delete(
self,
group_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> GroupDeleteResponse:
"""
Deletes a group from the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return await self._delete(
path_template("/organization/groups/{group_id}", group_id=group_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=GroupDeleteResponse,
)
class GroupsWithRawResponse:
def __init__(self, groups: Groups) -> None:
self._groups = groups
self.create = _legacy_response.to_raw_response_wrapper(
groups.create,
)
self.update = _legacy_response.to_raw_response_wrapper(
groups.update,
)
self.list = _legacy_response.to_raw_response_wrapper(
groups.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
groups.delete,
)
@cached_property
def users(self) -> UsersWithRawResponse:
return UsersWithRawResponse(self._groups.users)
@cached_property
def roles(self) -> RolesWithRawResponse:
return RolesWithRawResponse(self._groups.roles)
class AsyncGroupsWithRawResponse:
def __init__(self, groups: AsyncGroups) -> None:
self._groups = groups
self.create = _legacy_response.async_to_raw_response_wrapper(
groups.create,
)
self.update = _legacy_response.async_to_raw_response_wrapper(
groups.update,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
groups.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
groups.delete,
)
@cached_property
def users(self) -> AsyncUsersWithRawResponse:
return AsyncUsersWithRawResponse(self._groups.users)
@cached_property
def roles(self) -> AsyncRolesWithRawResponse:
return AsyncRolesWithRawResponse(self._groups.roles)
class GroupsWithStreamingResponse:
def __init__(self, groups: Groups) -> None:
self._groups = groups
self.create = to_streamed_response_wrapper(
groups.create,
)
self.update = to_streamed_response_wrapper(
groups.update,
)
self.list = to_streamed_response_wrapper(
groups.list,
)
self.delete = to_streamed_response_wrapper(
groups.delete,
)
@cached_property
def users(self) -> UsersWithStreamingResponse:
return UsersWithStreamingResponse(self._groups.users)
@cached_property
def roles(self) -> RolesWithStreamingResponse:
return RolesWithStreamingResponse(self._groups.roles)
class AsyncGroupsWithStreamingResponse:
def __init__(self, groups: AsyncGroups) -> None:
self._groups = groups
self.create = async_to_streamed_response_wrapper(
groups.create,
)
self.update = async_to_streamed_response_wrapper(
groups.update,
)
self.list = async_to_streamed_response_wrapper(
groups.list,
)
self.delete = async_to_streamed_response_wrapper(
groups.delete,
)
@cached_property
def users(self) -> AsyncUsersWithStreamingResponse:
return AsyncUsersWithStreamingResponse(self._groups.users)
@cached_property
def roles(self) -> AsyncRolesWithStreamingResponse:
return AsyncRolesWithStreamingResponse(self._groups.roles)

View File

@@ -0,0 +1,398 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ..... import _legacy_response
from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncNextCursorPage, AsyncNextCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization.groups import role_list_params, role_create_params
from .....types.admin.organization.groups.role_list_response import RoleListResponse
from .....types.admin.organization.groups.role_create_response import RoleCreateResponse
from .....types.admin.organization.groups.role_delete_response import RoleDeleteResponse
__all__ = ["Roles", "AsyncRoles"]
class Roles(SyncAPIResource):
@cached_property
def with_raw_response(self) -> RolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return RolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> RolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return RolesWithStreamingResponse(self)
def create(
self,
group_id: str,
*,
role_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns an organization role to a group within the organization.
Args:
role_id: Identifier of the role to assign.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._post(
path_template("/organization/groups/{group_id}/roles", group_id=group_id),
body=maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleCreateResponse,
)
def list(
self,
group_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[RoleListResponse]:
"""
Lists the organization roles assigned to a group within the organization.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing organization roles.
limit: A limit on the number of organization role assignments to return.
order: Sort order for the returned organization roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._get_api_list(
path_template("/organization/groups/{group_id}/roles", group_id=group_id),
page=SyncNextCursorPage[RoleListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=RoleListResponse,
)
def delete(
self,
role_id: str,
*,
group_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Unassigns an organization role from a group within the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return self._delete(
path_template("/organization/groups/{group_id}/roles/{role_id}", group_id=group_id, role_id=role_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class AsyncRoles(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncRolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncRolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncRolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncRolesWithStreamingResponse(self)
async def create(
self,
group_id: str,
*,
role_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns an organization role to a group within the organization.
Args:
role_id: Identifier of the role to assign.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return await self._post(
path_template("/organization/groups/{group_id}/roles", group_id=group_id),
body=await async_maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleCreateResponse,
)
def list(
self,
group_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[RoleListResponse, AsyncNextCursorPage[RoleListResponse]]:
"""
Lists the organization roles assigned to a group within the organization.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing organization roles.
limit: A limit on the number of organization role assignments to return.
order: Sort order for the returned organization roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._get_api_list(
path_template("/organization/groups/{group_id}/roles", group_id=group_id),
page=AsyncNextCursorPage[RoleListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=RoleListResponse,
)
async def delete(
self,
role_id: str,
*,
group_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Unassigns an organization role from a group within the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return await self._delete(
path_template("/organization/groups/{group_id}/roles/{role_id}", group_id=group_id, role_id=role_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class RolesWithRawResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = _legacy_response.to_raw_response_wrapper(
roles.create,
)
self.list = _legacy_response.to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
roles.delete,
)
class AsyncRolesWithRawResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = _legacy_response.async_to_raw_response_wrapper(
roles.create,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
roles.delete,
)
class RolesWithStreamingResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = to_streamed_response_wrapper(
roles.create,
)
self.list = to_streamed_response_wrapper(
roles.list,
)
self.delete = to_streamed_response_wrapper(
roles.delete,
)
class AsyncRolesWithStreamingResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = async_to_streamed_response_wrapper(
roles.create,
)
self.list = async_to_streamed_response_wrapper(
roles.list,
)
self.delete = async_to_streamed_response_wrapper(
roles.delete,
)

View File

@@ -0,0 +1,400 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ..... import _legacy_response
from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncNextCursorPage, AsyncNextCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization.groups import user_list_params, user_create_params
from .....types.admin.organization.groups.user_create_response import UserCreateResponse
from .....types.admin.organization.groups.user_delete_response import UserDeleteResponse
from .....types.admin.organization.groups.organization_group_user import OrganizationGroupUser
__all__ = ["Users", "AsyncUsers"]
class Users(SyncAPIResource):
@cached_property
def with_raw_response(self) -> UsersWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return UsersWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> UsersWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return UsersWithStreamingResponse(self)
def create(
self,
group_id: str,
*,
user_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> UserCreateResponse:
"""
Adds a user to a group.
Args:
user_id: Identifier of the user to add to the group.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._post(
path_template("/organization/groups/{group_id}/users", group_id=group_id),
body=maybe_transform({"user_id": user_id}, user_create_params.UserCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=UserCreateResponse,
)
def list(
self,
group_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[OrganizationGroupUser]:
"""
Lists the users assigned to a group.
Args:
after: A cursor for use in pagination. Provide the ID of the last user from the
previous list response to retrieve the next page.
limit: A limit on the number of users to be returned. Limit can range between 0 and
1000, and the default is 100.
order: Specifies the sort order of users in the list.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._get_api_list(
path_template("/organization/groups/{group_id}/users", group_id=group_id),
page=SyncNextCursorPage[OrganizationGroupUser],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
user_list_params.UserListParams,
),
security={"admin_api_key_auth": True},
),
model=OrganizationGroupUser,
)
def delete(
self,
user_id: str,
*,
group_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> UserDeleteResponse:
"""
Removes a user from a group.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._delete(
path_template("/organization/groups/{group_id}/users/{user_id}", group_id=group_id, user_id=user_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=UserDeleteResponse,
)
class AsyncUsers(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncUsersWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncUsersWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncUsersWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncUsersWithStreamingResponse(self)
async def create(
self,
group_id: str,
*,
user_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> UserCreateResponse:
"""
Adds a user to a group.
Args:
user_id: Identifier of the user to add to the group.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return await self._post(
path_template("/organization/groups/{group_id}/users", group_id=group_id),
body=await async_maybe_transform({"user_id": user_id}, user_create_params.UserCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=UserCreateResponse,
)
def list(
self,
group_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[OrganizationGroupUser, AsyncNextCursorPage[OrganizationGroupUser]]:
"""
Lists the users assigned to a group.
Args:
after: A cursor for use in pagination. Provide the ID of the last user from the
previous list response to retrieve the next page.
limit: A limit on the number of users to be returned. Limit can range between 0 and
1000, and the default is 100.
order: Specifies the sort order of users in the list.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._get_api_list(
path_template("/organization/groups/{group_id}/users", group_id=group_id),
page=AsyncNextCursorPage[OrganizationGroupUser],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
user_list_params.UserListParams,
),
security={"admin_api_key_auth": True},
),
model=OrganizationGroupUser,
)
async def delete(
self,
user_id: str,
*,
group_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> UserDeleteResponse:
"""
Removes a user from a group.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._delete(
path_template("/organization/groups/{group_id}/users/{user_id}", group_id=group_id, user_id=user_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=UserDeleteResponse,
)
class UsersWithRawResponse:
def __init__(self, users: Users) -> None:
self._users = users
self.create = _legacy_response.to_raw_response_wrapper(
users.create,
)
self.list = _legacy_response.to_raw_response_wrapper(
users.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
users.delete,
)
class AsyncUsersWithRawResponse:
def __init__(self, users: AsyncUsers) -> None:
self._users = users
self.create = _legacy_response.async_to_raw_response_wrapper(
users.create,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
users.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
users.delete,
)
class UsersWithStreamingResponse:
def __init__(self, users: Users) -> None:
self._users = users
self.create = to_streamed_response_wrapper(
users.create,
)
self.list = to_streamed_response_wrapper(
users.list,
)
self.delete = to_streamed_response_wrapper(
users.delete,
)
class AsyncUsersWithStreamingResponse:
def __init__(self, users: AsyncUsers) -> None:
self._users = users
self.create = async_to_streamed_response_wrapper(
users.create,
)
self.list = async_to_streamed_response_wrapper(
users.list,
)
self.delete = async_to_streamed_response_wrapper(
users.delete,
)

View File

@@ -0,0 +1,500 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Iterable
from typing_extensions import Literal
import httpx
from .... import _legacy_response
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ...._utils import path_template, maybe_transform, async_maybe_transform
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ....pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ...._base_client import AsyncPaginator, make_request_options
from ....types.admin.organization import invite_list_params, invite_create_params
from ....types.admin.organization.invite import Invite
from ....types.admin.organization.invite_delete_response import InviteDeleteResponse
__all__ = ["Invites", "AsyncInvites"]
class Invites(SyncAPIResource):
@cached_property
def with_raw_response(self) -> InvitesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return InvitesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> InvitesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return InvitesWithStreamingResponse(self)
def create(
self,
*,
email: str,
role: Literal["reader", "owner"],
projects: Iterable[invite_create_params.Project] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Invite:
"""Create an invite for a user to the organization.
The invite must be accepted by
the user before they have access to the organization.
Args:
email: Send an email to this address
role: `owner` or `reader`
projects: An array of projects to which membership is granted at the same time the org
invite is accepted. If omitted, the user will be invited to the default project
for compatibility with legacy behavior.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/organization/invites",
body=maybe_transform(
{
"email": email,
"role": role,
"projects": projects,
},
invite_create_params.InviteCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Invite,
)
def retrieve(
self,
invite_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Invite:
"""
Retrieves an invite.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not invite_id:
raise ValueError(f"Expected a non-empty value for `invite_id` but received {invite_id!r}")
return self._get(
path_template("/organization/invites/{invite_id}", invite_id=invite_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Invite,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[Invite]:
"""
Returns a list of invites in the organization.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/invites",
page=SyncConversationCursorPage[Invite],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
invite_list_params.InviteListParams,
),
security={"admin_api_key_auth": True},
),
model=Invite,
)
def delete(
self,
invite_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> InviteDeleteResponse:
"""Delete an invite.
If the invite has already been accepted, it cannot be deleted.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not invite_id:
raise ValueError(f"Expected a non-empty value for `invite_id` but received {invite_id!r}")
return self._delete(
path_template("/organization/invites/{invite_id}", invite_id=invite_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=InviteDeleteResponse,
)
class AsyncInvites(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncInvitesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncInvitesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncInvitesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncInvitesWithStreamingResponse(self)
async def create(
self,
*,
email: str,
role: Literal["reader", "owner"],
projects: Iterable[invite_create_params.Project] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Invite:
"""Create an invite for a user to the organization.
The invite must be accepted by
the user before they have access to the organization.
Args:
email: Send an email to this address
role: `owner` or `reader`
projects: An array of projects to which membership is granted at the same time the org
invite is accepted. If omitted, the user will be invited to the default project
for compatibility with legacy behavior.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/organization/invites",
body=await async_maybe_transform(
{
"email": email,
"role": role,
"projects": projects,
},
invite_create_params.InviteCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Invite,
)
async def retrieve(
self,
invite_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Invite:
"""
Retrieves an invite.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not invite_id:
raise ValueError(f"Expected a non-empty value for `invite_id` but received {invite_id!r}")
return await self._get(
path_template("/organization/invites/{invite_id}", invite_id=invite_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Invite,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[Invite, AsyncConversationCursorPage[Invite]]:
"""
Returns a list of invites in the organization.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/invites",
page=AsyncConversationCursorPage[Invite],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
invite_list_params.InviteListParams,
),
security={"admin_api_key_auth": True},
),
model=Invite,
)
async def delete(
self,
invite_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> InviteDeleteResponse:
"""Delete an invite.
If the invite has already been accepted, it cannot be deleted.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not invite_id:
raise ValueError(f"Expected a non-empty value for `invite_id` but received {invite_id!r}")
return await self._delete(
path_template("/organization/invites/{invite_id}", invite_id=invite_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=InviteDeleteResponse,
)
class InvitesWithRawResponse:
def __init__(self, invites: Invites) -> None:
self._invites = invites
self.create = _legacy_response.to_raw_response_wrapper(
invites.create,
)
self.retrieve = _legacy_response.to_raw_response_wrapper(
invites.retrieve,
)
self.list = _legacy_response.to_raw_response_wrapper(
invites.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
invites.delete,
)
class AsyncInvitesWithRawResponse:
def __init__(self, invites: AsyncInvites) -> None:
self._invites = invites
self.create = _legacy_response.async_to_raw_response_wrapper(
invites.create,
)
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
invites.retrieve,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
invites.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
invites.delete,
)
class InvitesWithStreamingResponse:
def __init__(self, invites: Invites) -> None:
self._invites = invites
self.create = to_streamed_response_wrapper(
invites.create,
)
self.retrieve = to_streamed_response_wrapper(
invites.retrieve,
)
self.list = to_streamed_response_wrapper(
invites.list,
)
self.delete = to_streamed_response_wrapper(
invites.delete,
)
class AsyncInvitesWithStreamingResponse:
def __init__(self, invites: AsyncInvites) -> None:
self._invites = invites
self.create = async_to_streamed_response_wrapper(
invites.create,
)
self.retrieve = async_to_streamed_response_wrapper(
invites.retrieve,
)
self.list = async_to_streamed_response_wrapper(
invites.list,
)
self.delete = async_to_streamed_response_wrapper(
invites.delete,
)

View File

@@ -0,0 +1,364 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .usage import (
Usage,
AsyncUsage,
UsageWithRawResponse,
AsyncUsageWithRawResponse,
UsageWithStreamingResponse,
AsyncUsageWithStreamingResponse,
)
from .invites import (
Invites,
AsyncInvites,
InvitesWithRawResponse,
AsyncInvitesWithRawResponse,
InvitesWithStreamingResponse,
AsyncInvitesWithStreamingResponse,
)
from ...._compat import cached_property
from .audit_logs import (
AuditLogs,
AsyncAuditLogs,
AuditLogsWithRawResponse,
AsyncAuditLogsWithRawResponse,
AuditLogsWithStreamingResponse,
AsyncAuditLogsWithStreamingResponse,
)
from .users.users import (
Users,
AsyncUsers,
UsersWithRawResponse,
AsyncUsersWithRawResponse,
UsersWithStreamingResponse,
AsyncUsersWithStreamingResponse,
)
from ...._resource import SyncAPIResource, AsyncAPIResource
from .certificates import (
Certificates,
AsyncCertificates,
CertificatesWithRawResponse,
AsyncCertificatesWithRawResponse,
CertificatesWithStreamingResponse,
AsyncCertificatesWithStreamingResponse,
)
from .groups.groups import (
Groups,
AsyncGroups,
GroupsWithRawResponse,
AsyncGroupsWithRawResponse,
GroupsWithStreamingResponse,
AsyncGroupsWithStreamingResponse,
)
from .admin_api_keys import (
AdminAPIKeys,
AsyncAdminAPIKeys,
AdminAPIKeysWithRawResponse,
AsyncAdminAPIKeysWithRawResponse,
AdminAPIKeysWithStreamingResponse,
AsyncAdminAPIKeysWithStreamingResponse,
)
from .projects.projects import (
Projects,
AsyncProjects,
ProjectsWithRawResponse,
AsyncProjectsWithRawResponse,
ProjectsWithStreamingResponse,
AsyncProjectsWithStreamingResponse,
)
__all__ = ["Organization", "AsyncOrganization"]
class Organization(SyncAPIResource):
@cached_property
def audit_logs(self) -> AuditLogs:
"""List user actions and configuration changes within this organization."""
return AuditLogs(self._client)
@cached_property
def admin_api_keys(self) -> AdminAPIKeys:
return AdminAPIKeys(self._client)
@cached_property
def usage(self) -> Usage:
return Usage(self._client)
@cached_property
def invites(self) -> Invites:
return Invites(self._client)
@cached_property
def users(self) -> Users:
return Users(self._client)
@cached_property
def groups(self) -> Groups:
return Groups(self._client)
@cached_property
def roles(self) -> Roles:
return Roles(self._client)
@cached_property
def certificates(self) -> Certificates:
return Certificates(self._client)
@cached_property
def projects(self) -> Projects:
return Projects(self._client)
@cached_property
def with_raw_response(self) -> OrganizationWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return OrganizationWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> OrganizationWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return OrganizationWithStreamingResponse(self)
class AsyncOrganization(AsyncAPIResource):
@cached_property
def audit_logs(self) -> AsyncAuditLogs:
"""List user actions and configuration changes within this organization."""
return AsyncAuditLogs(self._client)
@cached_property
def admin_api_keys(self) -> AsyncAdminAPIKeys:
return AsyncAdminAPIKeys(self._client)
@cached_property
def usage(self) -> AsyncUsage:
return AsyncUsage(self._client)
@cached_property
def invites(self) -> AsyncInvites:
return AsyncInvites(self._client)
@cached_property
def users(self) -> AsyncUsers:
return AsyncUsers(self._client)
@cached_property
def groups(self) -> AsyncGroups:
return AsyncGroups(self._client)
@cached_property
def roles(self) -> AsyncRoles:
return AsyncRoles(self._client)
@cached_property
def certificates(self) -> AsyncCertificates:
return AsyncCertificates(self._client)
@cached_property
def projects(self) -> AsyncProjects:
return AsyncProjects(self._client)
@cached_property
def with_raw_response(self) -> AsyncOrganizationWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncOrganizationWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncOrganizationWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncOrganizationWithStreamingResponse(self)
class OrganizationWithRawResponse:
def __init__(self, organization: Organization) -> None:
self._organization = organization
@cached_property
def audit_logs(self) -> AuditLogsWithRawResponse:
"""List user actions and configuration changes within this organization."""
return AuditLogsWithRawResponse(self._organization.audit_logs)
@cached_property
def admin_api_keys(self) -> AdminAPIKeysWithRawResponse:
return AdminAPIKeysWithRawResponse(self._organization.admin_api_keys)
@cached_property
def usage(self) -> UsageWithRawResponse:
return UsageWithRawResponse(self._organization.usage)
@cached_property
def invites(self) -> InvitesWithRawResponse:
return InvitesWithRawResponse(self._organization.invites)
@cached_property
def users(self) -> UsersWithRawResponse:
return UsersWithRawResponse(self._organization.users)
@cached_property
def groups(self) -> GroupsWithRawResponse:
return GroupsWithRawResponse(self._organization.groups)
@cached_property
def roles(self) -> RolesWithRawResponse:
return RolesWithRawResponse(self._organization.roles)
@cached_property
def certificates(self) -> CertificatesWithRawResponse:
return CertificatesWithRawResponse(self._organization.certificates)
@cached_property
def projects(self) -> ProjectsWithRawResponse:
return ProjectsWithRawResponse(self._organization.projects)
class AsyncOrganizationWithRawResponse:
def __init__(self, organization: AsyncOrganization) -> None:
self._organization = organization
@cached_property
def audit_logs(self) -> AsyncAuditLogsWithRawResponse:
"""List user actions and configuration changes within this organization."""
return AsyncAuditLogsWithRawResponse(self._organization.audit_logs)
@cached_property
def admin_api_keys(self) -> AsyncAdminAPIKeysWithRawResponse:
return AsyncAdminAPIKeysWithRawResponse(self._organization.admin_api_keys)
@cached_property
def usage(self) -> AsyncUsageWithRawResponse:
return AsyncUsageWithRawResponse(self._organization.usage)
@cached_property
def invites(self) -> AsyncInvitesWithRawResponse:
return AsyncInvitesWithRawResponse(self._organization.invites)
@cached_property
def users(self) -> AsyncUsersWithRawResponse:
return AsyncUsersWithRawResponse(self._organization.users)
@cached_property
def groups(self) -> AsyncGroupsWithRawResponse:
return AsyncGroupsWithRawResponse(self._organization.groups)
@cached_property
def roles(self) -> AsyncRolesWithRawResponse:
return AsyncRolesWithRawResponse(self._organization.roles)
@cached_property
def certificates(self) -> AsyncCertificatesWithRawResponse:
return AsyncCertificatesWithRawResponse(self._organization.certificates)
@cached_property
def projects(self) -> AsyncProjectsWithRawResponse:
return AsyncProjectsWithRawResponse(self._organization.projects)
class OrganizationWithStreamingResponse:
def __init__(self, organization: Organization) -> None:
self._organization = organization
@cached_property
def audit_logs(self) -> AuditLogsWithStreamingResponse:
"""List user actions and configuration changes within this organization."""
return AuditLogsWithStreamingResponse(self._organization.audit_logs)
@cached_property
def admin_api_keys(self) -> AdminAPIKeysWithStreamingResponse:
return AdminAPIKeysWithStreamingResponse(self._organization.admin_api_keys)
@cached_property
def usage(self) -> UsageWithStreamingResponse:
return UsageWithStreamingResponse(self._organization.usage)
@cached_property
def invites(self) -> InvitesWithStreamingResponse:
return InvitesWithStreamingResponse(self._organization.invites)
@cached_property
def users(self) -> UsersWithStreamingResponse:
return UsersWithStreamingResponse(self._organization.users)
@cached_property
def groups(self) -> GroupsWithStreamingResponse:
return GroupsWithStreamingResponse(self._organization.groups)
@cached_property
def roles(self) -> RolesWithStreamingResponse:
return RolesWithStreamingResponse(self._organization.roles)
@cached_property
def certificates(self) -> CertificatesWithStreamingResponse:
return CertificatesWithStreamingResponse(self._organization.certificates)
@cached_property
def projects(self) -> ProjectsWithStreamingResponse:
return ProjectsWithStreamingResponse(self._organization.projects)
class AsyncOrganizationWithStreamingResponse:
def __init__(self, organization: AsyncOrganization) -> None:
self._organization = organization
@cached_property
def audit_logs(self) -> AsyncAuditLogsWithStreamingResponse:
"""List user actions and configuration changes within this organization."""
return AsyncAuditLogsWithStreamingResponse(self._organization.audit_logs)
@cached_property
def admin_api_keys(self) -> AsyncAdminAPIKeysWithStreamingResponse:
return AsyncAdminAPIKeysWithStreamingResponse(self._organization.admin_api_keys)
@cached_property
def usage(self) -> AsyncUsageWithStreamingResponse:
return AsyncUsageWithStreamingResponse(self._organization.usage)
@cached_property
def invites(self) -> AsyncInvitesWithStreamingResponse:
return AsyncInvitesWithStreamingResponse(self._organization.invites)
@cached_property
def users(self) -> AsyncUsersWithStreamingResponse:
return AsyncUsersWithStreamingResponse(self._organization.users)
@cached_property
def groups(self) -> AsyncGroupsWithStreamingResponse:
return AsyncGroupsWithStreamingResponse(self._organization.groups)
@cached_property
def roles(self) -> AsyncRolesWithStreamingResponse:
return AsyncRolesWithStreamingResponse(self._organization.roles)
@cached_property
def certificates(self) -> AsyncCertificatesWithStreamingResponse:
return AsyncCertificatesWithStreamingResponse(self._organization.certificates)
@cached_property
def projects(self) -> AsyncProjectsWithStreamingResponse:
return AsyncProjectsWithStreamingResponse(self._organization.projects)

View File

@@ -0,0 +1,117 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .users import (
Users,
AsyncUsers,
UsersWithRawResponse,
AsyncUsersWithRawResponse,
UsersWithStreamingResponse,
AsyncUsersWithStreamingResponse,
)
from .groups import (
Groups,
AsyncGroups,
GroupsWithRawResponse,
AsyncGroupsWithRawResponse,
GroupsWithStreamingResponse,
AsyncGroupsWithStreamingResponse,
)
from .api_keys import (
APIKeys,
AsyncAPIKeys,
APIKeysWithRawResponse,
AsyncAPIKeysWithRawResponse,
APIKeysWithStreamingResponse,
AsyncAPIKeysWithStreamingResponse,
)
from .projects import (
Projects,
AsyncProjects,
ProjectsWithRawResponse,
AsyncProjectsWithRawResponse,
ProjectsWithStreamingResponse,
AsyncProjectsWithStreamingResponse,
)
from .rate_limits import (
RateLimits,
AsyncRateLimits,
RateLimitsWithRawResponse,
AsyncRateLimitsWithRawResponse,
RateLimitsWithStreamingResponse,
AsyncRateLimitsWithStreamingResponse,
)
from .certificates import (
Certificates,
AsyncCertificates,
CertificatesWithRawResponse,
AsyncCertificatesWithRawResponse,
CertificatesWithStreamingResponse,
AsyncCertificatesWithStreamingResponse,
)
from .service_accounts import (
ServiceAccounts,
AsyncServiceAccounts,
ServiceAccountsWithRawResponse,
AsyncServiceAccountsWithRawResponse,
ServiceAccountsWithStreamingResponse,
AsyncServiceAccountsWithStreamingResponse,
)
__all__ = [
"Users",
"AsyncUsers",
"UsersWithRawResponse",
"AsyncUsersWithRawResponse",
"UsersWithStreamingResponse",
"AsyncUsersWithStreamingResponse",
"ServiceAccounts",
"AsyncServiceAccounts",
"ServiceAccountsWithRawResponse",
"AsyncServiceAccountsWithRawResponse",
"ServiceAccountsWithStreamingResponse",
"AsyncServiceAccountsWithStreamingResponse",
"APIKeys",
"AsyncAPIKeys",
"APIKeysWithRawResponse",
"AsyncAPIKeysWithRawResponse",
"APIKeysWithStreamingResponse",
"AsyncAPIKeysWithStreamingResponse",
"RateLimits",
"AsyncRateLimits",
"RateLimitsWithRawResponse",
"AsyncRateLimitsWithRawResponse",
"RateLimitsWithStreamingResponse",
"AsyncRateLimitsWithStreamingResponse",
"Groups",
"AsyncGroups",
"GroupsWithRawResponse",
"AsyncGroupsWithRawResponse",
"GroupsWithStreamingResponse",
"AsyncGroupsWithStreamingResponse",
"Roles",
"AsyncRoles",
"RolesWithRawResponse",
"AsyncRolesWithRawResponse",
"RolesWithStreamingResponse",
"AsyncRolesWithStreamingResponse",
"Certificates",
"AsyncCertificates",
"CertificatesWithRawResponse",
"AsyncCertificatesWithRawResponse",
"CertificatesWithStreamingResponse",
"AsyncCertificatesWithStreamingResponse",
"Projects",
"AsyncProjects",
"ProjectsWithRawResponse",
"AsyncProjectsWithRawResponse",
"ProjectsWithStreamingResponse",
"AsyncProjectsWithStreamingResponse",
]

View File

@@ -0,0 +1,413 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
import httpx
from ..... import _legacy_response
from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ....._utils import path_template, maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization.projects import api_key_list_params
from .....types.admin.organization.projects.project_api_key import ProjectAPIKey
from .....types.admin.organization.projects.api_key_delete_response import APIKeyDeleteResponse
__all__ = ["APIKeys", "AsyncAPIKeys"]
class APIKeys(SyncAPIResource):
@cached_property
def with_raw_response(self) -> APIKeysWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return APIKeysWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> APIKeysWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return APIKeysWithStreamingResponse(self)
def retrieve(
self,
api_key_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectAPIKey:
"""
Retrieves an API key in the project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return self._get(
path_template(
"/organization/projects/{project_id}/api_keys/{api_key_id}",
project_id=project_id,
api_key_id=api_key_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectAPIKey,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[ProjectAPIKey]:
"""
Returns a list of API keys in the project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/api_keys", project_id=project_id),
page=SyncConversationCursorPage[ProjectAPIKey],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
api_key_list_params.APIKeyListParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectAPIKey,
)
def delete(
self,
api_key_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> APIKeyDeleteResponse:
"""
Deletes an API key from the project.
Returns confirmation of the key deletion, or an error if the key belonged to a
service account.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return self._delete(
path_template(
"/organization/projects/{project_id}/api_keys/{api_key_id}",
project_id=project_id,
api_key_id=api_key_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=APIKeyDeleteResponse,
)
class AsyncAPIKeys(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncAPIKeysWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncAPIKeysWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncAPIKeysWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncAPIKeysWithStreamingResponse(self)
async def retrieve(
self,
api_key_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectAPIKey:
"""
Retrieves an API key in the project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return await self._get(
path_template(
"/organization/projects/{project_id}/api_keys/{api_key_id}",
project_id=project_id,
api_key_id=api_key_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectAPIKey,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[ProjectAPIKey, AsyncConversationCursorPage[ProjectAPIKey]]:
"""
Returns a list of API keys in the project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/api_keys", project_id=project_id),
page=AsyncConversationCursorPage[ProjectAPIKey],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
api_key_list_params.APIKeyListParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectAPIKey,
)
async def delete(
self,
api_key_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> APIKeyDeleteResponse:
"""
Deletes an API key from the project.
Returns confirmation of the key deletion, or an error if the key belonged to a
service account.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return await self._delete(
path_template(
"/organization/projects/{project_id}/api_keys/{api_key_id}",
project_id=project_id,
api_key_id=api_key_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=APIKeyDeleteResponse,
)
class APIKeysWithRawResponse:
def __init__(self, api_keys: APIKeys) -> None:
self._api_keys = api_keys
self.retrieve = _legacy_response.to_raw_response_wrapper(
api_keys.retrieve,
)
self.list = _legacy_response.to_raw_response_wrapper(
api_keys.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
api_keys.delete,
)
class AsyncAPIKeysWithRawResponse:
def __init__(self, api_keys: AsyncAPIKeys) -> None:
self._api_keys = api_keys
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
api_keys.retrieve,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
api_keys.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
api_keys.delete,
)
class APIKeysWithStreamingResponse:
def __init__(self, api_keys: APIKeys) -> None:
self._api_keys = api_keys
self.retrieve = to_streamed_response_wrapper(
api_keys.retrieve,
)
self.list = to_streamed_response_wrapper(
api_keys.list,
)
self.delete = to_streamed_response_wrapper(
api_keys.delete,
)
class AsyncAPIKeysWithStreamingResponse:
def __init__(self, api_keys: AsyncAPIKeys) -> None:
self._api_keys = api_keys
self.retrieve = async_to_streamed_response_wrapper(
api_keys.retrieve,
)
self.list = async_to_streamed_response_wrapper(
api_keys.list,
)
self.delete = async_to_streamed_response_wrapper(
api_keys.delete,
)

View File

@@ -0,0 +1,428 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ..... import _legacy_response
from ....._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
from ....._utils import path_template, maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncPage, AsyncPage, SyncConversationCursorPage, AsyncConversationCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization.projects import (
certificate_list_params,
certificate_activate_params,
certificate_deactivate_params,
)
from .....types.admin.organization.projects.certificate_list_response import CertificateListResponse
from .....types.admin.organization.projects.certificate_activate_response import CertificateActivateResponse
from .....types.admin.organization.projects.certificate_deactivate_response import CertificateDeactivateResponse
__all__ = ["Certificates", "AsyncCertificates"]
class Certificates(SyncAPIResource):
@cached_property
def with_raw_response(self) -> CertificatesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return CertificatesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> CertificatesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return CertificatesWithStreamingResponse(self)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[CertificateListResponse]:
"""
List certificates for this project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
order and `desc` for descending order.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/certificates", project_id=project_id),
page=SyncConversationCursorPage[CertificateListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
certificate_list_params.CertificateListParams,
),
security={"admin_api_key_auth": True},
),
model=CertificateListResponse,
)
def activate(
self,
project_id: str,
*,
certificate_ids: SequenceNotStr[str],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncPage[CertificateActivateResponse]:
"""
Activate certificates at the project level.
You can atomically and idempotently activate up to 10 certificates at a time.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/certificates/activate", project_id=project_id),
page=SyncPage[CertificateActivateResponse],
body=maybe_transform(
{"certificate_ids": certificate_ids}, certificate_activate_params.CertificateActivateParams
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
model=CertificateActivateResponse,
method="post",
)
def deactivate(
self,
project_id: str,
*,
certificate_ids: SequenceNotStr[str],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncPage[CertificateDeactivateResponse]:
"""Deactivate certificates at the project level.
You can atomically and
idempotently deactivate up to 10 certificates at a time.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/certificates/deactivate", project_id=project_id),
page=SyncPage[CertificateDeactivateResponse],
body=maybe_transform(
{"certificate_ids": certificate_ids}, certificate_deactivate_params.CertificateDeactivateParams
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
model=CertificateDeactivateResponse,
method="post",
)
class AsyncCertificates(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncCertificatesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncCertificatesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncCertificatesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncCertificatesWithStreamingResponse(self)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[CertificateListResponse, AsyncConversationCursorPage[CertificateListResponse]]:
"""
List certificates for this project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
order and `desc` for descending order.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/certificates", project_id=project_id),
page=AsyncConversationCursorPage[CertificateListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
certificate_list_params.CertificateListParams,
),
security={"admin_api_key_auth": True},
),
model=CertificateListResponse,
)
def activate(
self,
project_id: str,
*,
certificate_ids: SequenceNotStr[str],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[CertificateActivateResponse, AsyncPage[CertificateActivateResponse]]:
"""
Activate certificates at the project level.
You can atomically and idempotently activate up to 10 certificates at a time.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/certificates/activate", project_id=project_id),
page=AsyncPage[CertificateActivateResponse],
body=maybe_transform(
{"certificate_ids": certificate_ids}, certificate_activate_params.CertificateActivateParams
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
model=CertificateActivateResponse,
method="post",
)
def deactivate(
self,
project_id: str,
*,
certificate_ids: SequenceNotStr[str],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[CertificateDeactivateResponse, AsyncPage[CertificateDeactivateResponse]]:
"""Deactivate certificates at the project level.
You can atomically and
idempotently deactivate up to 10 certificates at a time.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/certificates/deactivate", project_id=project_id),
page=AsyncPage[CertificateDeactivateResponse],
body=maybe_transform(
{"certificate_ids": certificate_ids}, certificate_deactivate_params.CertificateDeactivateParams
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
model=CertificateDeactivateResponse,
method="post",
)
class CertificatesWithRawResponse:
def __init__(self, certificates: Certificates) -> None:
self._certificates = certificates
self.list = _legacy_response.to_raw_response_wrapper(
certificates.list,
)
self.activate = _legacy_response.to_raw_response_wrapper(
certificates.activate,
)
self.deactivate = _legacy_response.to_raw_response_wrapper(
certificates.deactivate,
)
class AsyncCertificatesWithRawResponse:
def __init__(self, certificates: AsyncCertificates) -> None:
self._certificates = certificates
self.list = _legacy_response.async_to_raw_response_wrapper(
certificates.list,
)
self.activate = _legacy_response.async_to_raw_response_wrapper(
certificates.activate,
)
self.deactivate = _legacy_response.async_to_raw_response_wrapper(
certificates.deactivate,
)
class CertificatesWithStreamingResponse:
def __init__(self, certificates: Certificates) -> None:
self._certificates = certificates
self.list = to_streamed_response_wrapper(
certificates.list,
)
self.activate = to_streamed_response_wrapper(
certificates.activate,
)
self.deactivate = to_streamed_response_wrapper(
certificates.deactivate,
)
class AsyncCertificatesWithStreamingResponse:
def __init__(self, certificates: AsyncCertificates) -> None:
self._certificates = certificates
self.list = async_to_streamed_response_wrapper(
certificates.list,
)
self.activate = async_to_streamed_response_wrapper(
certificates.activate,
)
self.deactivate = async_to_streamed_response_wrapper(
certificates.deactivate,
)

View File

@@ -0,0 +1,33 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .groups import (
Groups,
AsyncGroups,
GroupsWithRawResponse,
AsyncGroupsWithRawResponse,
GroupsWithStreamingResponse,
AsyncGroupsWithStreamingResponse,
)
__all__ = [
"Roles",
"AsyncRoles",
"RolesWithRawResponse",
"AsyncRolesWithRawResponse",
"RolesWithStreamingResponse",
"AsyncRolesWithStreamingResponse",
"Groups",
"AsyncGroups",
"GroupsWithRawResponse",
"AsyncGroupsWithRawResponse",
"GroupsWithStreamingResponse",
"AsyncGroupsWithStreamingResponse",
]

View File

@@ -0,0 +1,451 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ...... import _legacy_response
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from ......_types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ......_utils import path_template, maybe_transform, async_maybe_transform
from ......_compat import cached_property
from ......_resource import SyncAPIResource, AsyncAPIResource
from ......_response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ......pagination import SyncNextCursorPage, AsyncNextCursorPage
from ......_base_client import AsyncPaginator, make_request_options
from ......types.admin.organization.projects import group_list_params, group_create_params
from ......types.admin.organization.projects.project_group import ProjectGroup
from ......types.admin.organization.projects.group_delete_response import GroupDeleteResponse
__all__ = ["Groups", "AsyncGroups"]
class Groups(SyncAPIResource):
@cached_property
def roles(self) -> Roles:
return Roles(self._client)
@cached_property
def with_raw_response(self) -> GroupsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return GroupsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> GroupsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return GroupsWithStreamingResponse(self)
def create(
self,
project_id: str,
*,
group_id: str,
role: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectGroup:
"""
Grants a group access to a project.
Args:
group_id: Identifier of the group to add to the project.
role: Identifier of the project role to grant to the group.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._post(
path_template("/organization/projects/{project_id}/groups", project_id=project_id),
body=maybe_transform(
{
"group_id": group_id,
"role": role,
},
group_create_params.GroupCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectGroup,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[ProjectGroup]:
"""
Lists the groups that have access to a project.
Args:
after: Cursor for pagination. Provide the ID of the last group from the previous
response to fetch the next page.
limit: A limit on the number of project groups to return. Defaults to 20.
order: Sort order for the returned groups.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/groups", project_id=project_id),
page=SyncNextCursorPage[ProjectGroup],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
group_list_params.GroupListParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectGroup,
)
def delete(
self,
group_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> GroupDeleteResponse:
"""
Revokes a group's access to a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._delete(
path_template(
"/organization/projects/{project_id}/groups/{group_id}", project_id=project_id, group_id=group_id
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=GroupDeleteResponse,
)
class AsyncGroups(AsyncAPIResource):
@cached_property
def roles(self) -> AsyncRoles:
return AsyncRoles(self._client)
@cached_property
def with_raw_response(self) -> AsyncGroupsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncGroupsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncGroupsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncGroupsWithStreamingResponse(self)
async def create(
self,
project_id: str,
*,
group_id: str,
role: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectGroup:
"""
Grants a group access to a project.
Args:
group_id: Identifier of the group to add to the project.
role: Identifier of the project role to grant to the group.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return await self._post(
path_template("/organization/projects/{project_id}/groups", project_id=project_id),
body=await async_maybe_transform(
{
"group_id": group_id,
"role": role,
},
group_create_params.GroupCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectGroup,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[ProjectGroup, AsyncNextCursorPage[ProjectGroup]]:
"""
Lists the groups that have access to a project.
Args:
after: Cursor for pagination. Provide the ID of the last group from the previous
response to fetch the next page.
limit: A limit on the number of project groups to return. Defaults to 20.
order: Sort order for the returned groups.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/groups", project_id=project_id),
page=AsyncNextCursorPage[ProjectGroup],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
group_list_params.GroupListParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectGroup,
)
async def delete(
self,
group_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> GroupDeleteResponse:
"""
Revokes a group's access to a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return await self._delete(
path_template(
"/organization/projects/{project_id}/groups/{group_id}", project_id=project_id, group_id=group_id
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=GroupDeleteResponse,
)
class GroupsWithRawResponse:
def __init__(self, groups: Groups) -> None:
self._groups = groups
self.create = _legacy_response.to_raw_response_wrapper(
groups.create,
)
self.list = _legacy_response.to_raw_response_wrapper(
groups.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
groups.delete,
)
@cached_property
def roles(self) -> RolesWithRawResponse:
return RolesWithRawResponse(self._groups.roles)
class AsyncGroupsWithRawResponse:
def __init__(self, groups: AsyncGroups) -> None:
self._groups = groups
self.create = _legacy_response.async_to_raw_response_wrapper(
groups.create,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
groups.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
groups.delete,
)
@cached_property
def roles(self) -> AsyncRolesWithRawResponse:
return AsyncRolesWithRawResponse(self._groups.roles)
class GroupsWithStreamingResponse:
def __init__(self, groups: Groups) -> None:
self._groups = groups
self.create = to_streamed_response_wrapper(
groups.create,
)
self.list = to_streamed_response_wrapper(
groups.list,
)
self.delete = to_streamed_response_wrapper(
groups.delete,
)
@cached_property
def roles(self) -> RolesWithStreamingResponse:
return RolesWithStreamingResponse(self._groups.roles)
class AsyncGroupsWithStreamingResponse:
def __init__(self, groups: AsyncGroups) -> None:
self._groups = groups
self.create = async_to_streamed_response_wrapper(
groups.create,
)
self.list = async_to_streamed_response_wrapper(
groups.list,
)
self.delete = async_to_streamed_response_wrapper(
groups.delete,
)
@cached_property
def roles(self) -> AsyncRolesWithStreamingResponse:
return AsyncRolesWithStreamingResponse(self._groups.roles)

View File

@@ -0,0 +1,426 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ...... import _legacy_response
from ......_types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ......_utils import path_template, maybe_transform, async_maybe_transform
from ......_compat import cached_property
from ......_resource import SyncAPIResource, AsyncAPIResource
from ......_response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ......pagination import SyncNextCursorPage, AsyncNextCursorPage
from ......_base_client import AsyncPaginator, make_request_options
from ......types.admin.organization.projects.groups import role_list_params, role_create_params
from ......types.admin.organization.projects.groups.role_list_response import RoleListResponse
from ......types.admin.organization.projects.groups.role_create_response import RoleCreateResponse
from ......types.admin.organization.projects.groups.role_delete_response import RoleDeleteResponse
__all__ = ["Roles", "AsyncRoles"]
class Roles(SyncAPIResource):
@cached_property
def with_raw_response(self) -> RolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return RolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> RolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return RolesWithStreamingResponse(self)
def create(
self,
group_id: str,
*,
project_id: str,
role_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns a project role to a group within a project.
Args:
role_id: Identifier of the role to assign.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._post(
path_template("/projects/{project_id}/groups/{group_id}/roles", project_id=project_id, group_id=group_id),
body=maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleCreateResponse,
)
def list(
self,
group_id: str,
*,
project_id: str,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[RoleListResponse]:
"""
Lists the project roles assigned to a group within a project.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing project roles.
limit: A limit on the number of project role assignments to return.
order: Sort order for the returned project roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._get_api_list(
path_template("/projects/{project_id}/groups/{group_id}/roles", project_id=project_id, group_id=group_id),
page=SyncNextCursorPage[RoleListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=RoleListResponse,
)
def delete(
self,
role_id: str,
*,
project_id: str,
group_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Unassigns a project role from a group within a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return self._delete(
path_template(
"/projects/{project_id}/groups/{group_id}/roles/{role_id}",
project_id=project_id,
group_id=group_id,
role_id=role_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class AsyncRoles(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncRolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncRolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncRolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncRolesWithStreamingResponse(self)
async def create(
self,
group_id: str,
*,
project_id: str,
role_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns a project role to a group within a project.
Args:
role_id: Identifier of the role to assign.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return await self._post(
path_template("/projects/{project_id}/groups/{group_id}/roles", project_id=project_id, group_id=group_id),
body=await async_maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleCreateResponse,
)
def list(
self,
group_id: str,
*,
project_id: str,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[RoleListResponse, AsyncNextCursorPage[RoleListResponse]]:
"""
Lists the project roles assigned to a group within a project.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing project roles.
limit: A limit on the number of project role assignments to return.
order: Sort order for the returned project roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._get_api_list(
path_template("/projects/{project_id}/groups/{group_id}/roles", project_id=project_id, group_id=group_id),
page=AsyncNextCursorPage[RoleListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=RoleListResponse,
)
async def delete(
self,
role_id: str,
*,
project_id: str,
group_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Unassigns a project role from a group within a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return await self._delete(
path_template(
"/projects/{project_id}/groups/{group_id}/roles/{role_id}",
project_id=project_id,
group_id=group_id,
role_id=role_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class RolesWithRawResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = _legacy_response.to_raw_response_wrapper(
roles.create,
)
self.list = _legacy_response.to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
roles.delete,
)
class AsyncRolesWithRawResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = _legacy_response.async_to_raw_response_wrapper(
roles.create,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
roles.delete,
)
class RolesWithStreamingResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = to_streamed_response_wrapper(
roles.create,
)
self.list = to_streamed_response_wrapper(
roles.list,
)
self.delete = to_streamed_response_wrapper(
roles.delete,
)
class AsyncRolesWithStreamingResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = async_to_streamed_response_wrapper(
roles.create,
)
self.list = async_to_streamed_response_wrapper(
roles.list,
)
self.delete = async_to_streamed_response_wrapper(
roles.delete,
)

View File

@@ -0,0 +1,858 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Optional
import httpx
from ..... import _legacy_response
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .api_keys import (
APIKeys,
AsyncAPIKeys,
APIKeysWithRawResponse,
AsyncAPIKeysWithRawResponse,
APIKeysWithStreamingResponse,
AsyncAPIKeysWithStreamingResponse,
)
from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from .rate_limits import (
RateLimits,
AsyncRateLimits,
RateLimitsWithRawResponse,
AsyncRateLimitsWithRawResponse,
RateLimitsWithStreamingResponse,
AsyncRateLimitsWithStreamingResponse,
)
from .users.users import (
Users,
AsyncUsers,
UsersWithRawResponse,
AsyncUsersWithRawResponse,
UsersWithStreamingResponse,
AsyncUsersWithStreamingResponse,
)
from .certificates import (
Certificates,
AsyncCertificates,
CertificatesWithRawResponse,
AsyncCertificatesWithRawResponse,
CertificatesWithStreamingResponse,
AsyncCertificatesWithStreamingResponse,
)
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .groups.groups import (
Groups,
AsyncGroups,
GroupsWithRawResponse,
AsyncGroupsWithRawResponse,
GroupsWithStreamingResponse,
AsyncGroupsWithStreamingResponse,
)
from .....pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .service_accounts import (
ServiceAccounts,
AsyncServiceAccounts,
ServiceAccountsWithRawResponse,
AsyncServiceAccountsWithRawResponse,
ServiceAccountsWithStreamingResponse,
AsyncServiceAccountsWithStreamingResponse,
)
from .....types.admin.organization import project_list_params, project_create_params, project_update_params
from .....types.admin.organization.project import Project
__all__ = ["Projects", "AsyncProjects"]
class Projects(SyncAPIResource):
@cached_property
def users(self) -> Users:
return Users(self._client)
@cached_property
def service_accounts(self) -> ServiceAccounts:
return ServiceAccounts(self._client)
@cached_property
def api_keys(self) -> APIKeys:
return APIKeys(self._client)
@cached_property
def rate_limits(self) -> RateLimits:
return RateLimits(self._client)
@cached_property
def groups(self) -> Groups:
return Groups(self._client)
@cached_property
def roles(self) -> Roles:
return Roles(self._client)
@cached_property
def certificates(self) -> Certificates:
return Certificates(self._client)
@cached_property
def with_raw_response(self) -> ProjectsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return ProjectsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> ProjectsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return ProjectsWithStreamingResponse(self)
def create(
self,
*,
name: str,
external_key_id: Optional[str] | Omit = omit,
geography: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Project:
"""Create a new project in the organization.
Projects can be created and archived,
but cannot be deleted.
Args:
name: The friendly name of the project, this name appears in reports.
external_key_id: External key ID to associate with the project.
geography: Create the project with the specified data residency region. Your organization
must have access to Data residency functionality in order to use. See
[data residency controls](https://platform.openai.com/docs/guides/your-data#data-residency-controls)
to review the functionality and limitations of setting this field.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/organization/projects",
body=maybe_transform(
{
"name": name,
"external_key_id": external_key_id,
"geography": geography,
},
project_create_params.ProjectCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Project,
)
def retrieve(
self,
project_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Project:
"""
Retrieves a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get(
path_template("/organization/projects/{project_id}", project_id=project_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Project,
)
def update(
self,
project_id: str,
*,
external_key_id: Optional[str] | Omit = omit,
geography: Optional[str] | Omit = omit,
name: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Project:
"""
Modifies a project in the organization.
Args:
external_key_id: External key ID to associate with the project.
geography: Geography for the project.
name: The updated name of the project, this name appears in reports.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._post(
path_template("/organization/projects/{project_id}", project_id=project_id),
body=maybe_transform(
{
"external_key_id": external_key_id,
"geography": geography,
"name": name,
},
project_update_params.ProjectUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Project,
)
def list(
self,
*,
after: str | Omit = omit,
include_archived: bool | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[Project]:
"""Returns a list of projects.
Args:
after: A cursor for use in pagination.
`after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
include_archived: If `true` returns all projects including those that have been `archived`.
Archived projects are not included by default.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/projects",
page=SyncConversationCursorPage[Project],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"include_archived": include_archived,
"limit": limit,
},
project_list_params.ProjectListParams,
),
security={"admin_api_key_auth": True},
),
model=Project,
)
def archive(
self,
project_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Project:
"""Archives a project in the organization.
Archived projects cannot be used or
updated.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._post(
path_template("/organization/projects/{project_id}/archive", project_id=project_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Project,
)
class AsyncProjects(AsyncAPIResource):
@cached_property
def users(self) -> AsyncUsers:
return AsyncUsers(self._client)
@cached_property
def service_accounts(self) -> AsyncServiceAccounts:
return AsyncServiceAccounts(self._client)
@cached_property
def api_keys(self) -> AsyncAPIKeys:
return AsyncAPIKeys(self._client)
@cached_property
def rate_limits(self) -> AsyncRateLimits:
return AsyncRateLimits(self._client)
@cached_property
def groups(self) -> AsyncGroups:
return AsyncGroups(self._client)
@cached_property
def roles(self) -> AsyncRoles:
return AsyncRoles(self._client)
@cached_property
def certificates(self) -> AsyncCertificates:
return AsyncCertificates(self._client)
@cached_property
def with_raw_response(self) -> AsyncProjectsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncProjectsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncProjectsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncProjectsWithStreamingResponse(self)
async def create(
self,
*,
name: str,
external_key_id: Optional[str] | Omit = omit,
geography: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Project:
"""Create a new project in the organization.
Projects can be created and archived,
but cannot be deleted.
Args:
name: The friendly name of the project, this name appears in reports.
external_key_id: External key ID to associate with the project.
geography: Create the project with the specified data residency region. Your organization
must have access to Data residency functionality in order to use. See
[data residency controls](https://platform.openai.com/docs/guides/your-data#data-residency-controls)
to review the functionality and limitations of setting this field.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/organization/projects",
body=await async_maybe_transform(
{
"name": name,
"external_key_id": external_key_id,
"geography": geography,
},
project_create_params.ProjectCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Project,
)
async def retrieve(
self,
project_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Project:
"""
Retrieves a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return await self._get(
path_template("/organization/projects/{project_id}", project_id=project_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Project,
)
async def update(
self,
project_id: str,
*,
external_key_id: Optional[str] | Omit = omit,
geography: Optional[str] | Omit = omit,
name: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Project:
"""
Modifies a project in the organization.
Args:
external_key_id: External key ID to associate with the project.
geography: Geography for the project.
name: The updated name of the project, this name appears in reports.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return await self._post(
path_template("/organization/projects/{project_id}", project_id=project_id),
body=await async_maybe_transform(
{
"external_key_id": external_key_id,
"geography": geography,
"name": name,
},
project_update_params.ProjectUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Project,
)
def list(
self,
*,
after: str | Omit = omit,
include_archived: bool | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[Project, AsyncConversationCursorPage[Project]]:
"""Returns a list of projects.
Args:
after: A cursor for use in pagination.
`after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
include_archived: If `true` returns all projects including those that have been `archived`.
Archived projects are not included by default.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/projects",
page=AsyncConversationCursorPage[Project],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"include_archived": include_archived,
"limit": limit,
},
project_list_params.ProjectListParams,
),
security={"admin_api_key_auth": True},
),
model=Project,
)
async def archive(
self,
project_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Project:
"""Archives a project in the organization.
Archived projects cannot be used or
updated.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return await self._post(
path_template("/organization/projects/{project_id}/archive", project_id=project_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Project,
)
class ProjectsWithRawResponse:
def __init__(self, projects: Projects) -> None:
self._projects = projects
self.create = _legacy_response.to_raw_response_wrapper(
projects.create,
)
self.retrieve = _legacy_response.to_raw_response_wrapper(
projects.retrieve,
)
self.update = _legacy_response.to_raw_response_wrapper(
projects.update,
)
self.list = _legacy_response.to_raw_response_wrapper(
projects.list,
)
self.archive = _legacy_response.to_raw_response_wrapper(
projects.archive,
)
@cached_property
def users(self) -> UsersWithRawResponse:
return UsersWithRawResponse(self._projects.users)
@cached_property
def service_accounts(self) -> ServiceAccountsWithRawResponse:
return ServiceAccountsWithRawResponse(self._projects.service_accounts)
@cached_property
def api_keys(self) -> APIKeysWithRawResponse:
return APIKeysWithRawResponse(self._projects.api_keys)
@cached_property
def rate_limits(self) -> RateLimitsWithRawResponse:
return RateLimitsWithRawResponse(self._projects.rate_limits)
@cached_property
def groups(self) -> GroupsWithRawResponse:
return GroupsWithRawResponse(self._projects.groups)
@cached_property
def roles(self) -> RolesWithRawResponse:
return RolesWithRawResponse(self._projects.roles)
@cached_property
def certificates(self) -> CertificatesWithRawResponse:
return CertificatesWithRawResponse(self._projects.certificates)
class AsyncProjectsWithRawResponse:
def __init__(self, projects: AsyncProjects) -> None:
self._projects = projects
self.create = _legacy_response.async_to_raw_response_wrapper(
projects.create,
)
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
projects.retrieve,
)
self.update = _legacy_response.async_to_raw_response_wrapper(
projects.update,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
projects.list,
)
self.archive = _legacy_response.async_to_raw_response_wrapper(
projects.archive,
)
@cached_property
def users(self) -> AsyncUsersWithRawResponse:
return AsyncUsersWithRawResponse(self._projects.users)
@cached_property
def service_accounts(self) -> AsyncServiceAccountsWithRawResponse:
return AsyncServiceAccountsWithRawResponse(self._projects.service_accounts)
@cached_property
def api_keys(self) -> AsyncAPIKeysWithRawResponse:
return AsyncAPIKeysWithRawResponse(self._projects.api_keys)
@cached_property
def rate_limits(self) -> AsyncRateLimitsWithRawResponse:
return AsyncRateLimitsWithRawResponse(self._projects.rate_limits)
@cached_property
def groups(self) -> AsyncGroupsWithRawResponse:
return AsyncGroupsWithRawResponse(self._projects.groups)
@cached_property
def roles(self) -> AsyncRolesWithRawResponse:
return AsyncRolesWithRawResponse(self._projects.roles)
@cached_property
def certificates(self) -> AsyncCertificatesWithRawResponse:
return AsyncCertificatesWithRawResponse(self._projects.certificates)
class ProjectsWithStreamingResponse:
def __init__(self, projects: Projects) -> None:
self._projects = projects
self.create = to_streamed_response_wrapper(
projects.create,
)
self.retrieve = to_streamed_response_wrapper(
projects.retrieve,
)
self.update = to_streamed_response_wrapper(
projects.update,
)
self.list = to_streamed_response_wrapper(
projects.list,
)
self.archive = to_streamed_response_wrapper(
projects.archive,
)
@cached_property
def users(self) -> UsersWithStreamingResponse:
return UsersWithStreamingResponse(self._projects.users)
@cached_property
def service_accounts(self) -> ServiceAccountsWithStreamingResponse:
return ServiceAccountsWithStreamingResponse(self._projects.service_accounts)
@cached_property
def api_keys(self) -> APIKeysWithStreamingResponse:
return APIKeysWithStreamingResponse(self._projects.api_keys)
@cached_property
def rate_limits(self) -> RateLimitsWithStreamingResponse:
return RateLimitsWithStreamingResponse(self._projects.rate_limits)
@cached_property
def groups(self) -> GroupsWithStreamingResponse:
return GroupsWithStreamingResponse(self._projects.groups)
@cached_property
def roles(self) -> RolesWithStreamingResponse:
return RolesWithStreamingResponse(self._projects.roles)
@cached_property
def certificates(self) -> CertificatesWithStreamingResponse:
return CertificatesWithStreamingResponse(self._projects.certificates)
class AsyncProjectsWithStreamingResponse:
def __init__(self, projects: AsyncProjects) -> None:
self._projects = projects
self.create = async_to_streamed_response_wrapper(
projects.create,
)
self.retrieve = async_to_streamed_response_wrapper(
projects.retrieve,
)
self.update = async_to_streamed_response_wrapper(
projects.update,
)
self.list = async_to_streamed_response_wrapper(
projects.list,
)
self.archive = async_to_streamed_response_wrapper(
projects.archive,
)
@cached_property
def users(self) -> AsyncUsersWithStreamingResponse:
return AsyncUsersWithStreamingResponse(self._projects.users)
@cached_property
def service_accounts(self) -> AsyncServiceAccountsWithStreamingResponse:
return AsyncServiceAccountsWithStreamingResponse(self._projects.service_accounts)
@cached_property
def api_keys(self) -> AsyncAPIKeysWithStreamingResponse:
return AsyncAPIKeysWithStreamingResponse(self._projects.api_keys)
@cached_property
def rate_limits(self) -> AsyncRateLimitsWithStreamingResponse:
return AsyncRateLimitsWithStreamingResponse(self._projects.rate_limits)
@cached_property
def groups(self) -> AsyncGroupsWithStreamingResponse:
return AsyncGroupsWithStreamingResponse(self._projects.groups)
@cached_property
def roles(self) -> AsyncRolesWithStreamingResponse:
return AsyncRolesWithStreamingResponse(self._projects.roles)
@cached_property
def certificates(self) -> AsyncCertificatesWithStreamingResponse:
return AsyncCertificatesWithStreamingResponse(self._projects.certificates)

View File

@@ -0,0 +1,379 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
import httpx
from ..... import _legacy_response
from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization.projects import (
rate_limit_list_rate_limits_params,
rate_limit_update_rate_limit_params,
)
from .....types.admin.organization.projects.project_rate_limit import ProjectRateLimit
__all__ = ["RateLimits", "AsyncRateLimits"]
class RateLimits(SyncAPIResource):
@cached_property
def with_raw_response(self) -> RateLimitsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return RateLimitsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> RateLimitsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return RateLimitsWithStreamingResponse(self)
def list_rate_limits(
self,
project_id: str,
*,
after: str | Omit = omit,
before: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[ProjectRateLimit]:
"""
Returns the rate limits per model for a project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
before: A cursor for use in pagination. `before` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
beginning with obj_foo, your subsequent call can include before=obj_foo in order
to fetch the previous page of the list.
limit: A limit on the number of objects to be returned. The default is 100.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/rate_limits", project_id=project_id),
page=SyncConversationCursorPage[ProjectRateLimit],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"before": before,
"limit": limit,
},
rate_limit_list_rate_limits_params.RateLimitListRateLimitsParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectRateLimit,
)
def update_rate_limit(
self,
rate_limit_id: str,
*,
project_id: str,
batch_1_day_max_input_tokens: int | Omit = omit,
max_audio_megabytes_per_1_minute: int | Omit = omit,
max_images_per_1_minute: int | Omit = omit,
max_requests_per_1_day: int | Omit = omit,
max_requests_per_1_minute: int | Omit = omit,
max_tokens_per_1_minute: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectRateLimit:
"""
Updates a project rate limit.
Args:
batch_1_day_max_input_tokens: The maximum batch input tokens per day. Only relevant for certain models.
max_audio_megabytes_per_1_minute: The maximum audio megabytes per minute. Only relevant for certain models.
max_images_per_1_minute: The maximum images per minute. Only relevant for certain models.
max_requests_per_1_day: The maximum requests per day. Only relevant for certain models.
max_requests_per_1_minute: The maximum requests per minute.
max_tokens_per_1_minute: The maximum tokens per minute.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not rate_limit_id:
raise ValueError(f"Expected a non-empty value for `rate_limit_id` but received {rate_limit_id!r}")
return self._post(
path_template(
"/organization/projects/{project_id}/rate_limits/{rate_limit_id}",
project_id=project_id,
rate_limit_id=rate_limit_id,
),
body=maybe_transform(
{
"batch_1_day_max_input_tokens": batch_1_day_max_input_tokens,
"max_audio_megabytes_per_1_minute": max_audio_megabytes_per_1_minute,
"max_images_per_1_minute": max_images_per_1_minute,
"max_requests_per_1_day": max_requests_per_1_day,
"max_requests_per_1_minute": max_requests_per_1_minute,
"max_tokens_per_1_minute": max_tokens_per_1_minute,
},
rate_limit_update_rate_limit_params.RateLimitUpdateRateLimitParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectRateLimit,
)
class AsyncRateLimits(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncRateLimitsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncRateLimitsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncRateLimitsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncRateLimitsWithStreamingResponse(self)
def list_rate_limits(
self,
project_id: str,
*,
after: str | Omit = omit,
before: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[ProjectRateLimit, AsyncConversationCursorPage[ProjectRateLimit]]:
"""
Returns the rate limits per model for a project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
before: A cursor for use in pagination. `before` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
beginning with obj_foo, your subsequent call can include before=obj_foo in order
to fetch the previous page of the list.
limit: A limit on the number of objects to be returned. The default is 100.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/rate_limits", project_id=project_id),
page=AsyncConversationCursorPage[ProjectRateLimit],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"before": before,
"limit": limit,
},
rate_limit_list_rate_limits_params.RateLimitListRateLimitsParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectRateLimit,
)
async def update_rate_limit(
self,
rate_limit_id: str,
*,
project_id: str,
batch_1_day_max_input_tokens: int | Omit = omit,
max_audio_megabytes_per_1_minute: int | Omit = omit,
max_images_per_1_minute: int | Omit = omit,
max_requests_per_1_day: int | Omit = omit,
max_requests_per_1_minute: int | Omit = omit,
max_tokens_per_1_minute: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectRateLimit:
"""
Updates a project rate limit.
Args:
batch_1_day_max_input_tokens: The maximum batch input tokens per day. Only relevant for certain models.
max_audio_megabytes_per_1_minute: The maximum audio megabytes per minute. Only relevant for certain models.
max_images_per_1_minute: The maximum images per minute. Only relevant for certain models.
max_requests_per_1_day: The maximum requests per day. Only relevant for certain models.
max_requests_per_1_minute: The maximum requests per minute.
max_tokens_per_1_minute: The maximum tokens per minute.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not rate_limit_id:
raise ValueError(f"Expected a non-empty value for `rate_limit_id` but received {rate_limit_id!r}")
return await self._post(
path_template(
"/organization/projects/{project_id}/rate_limits/{rate_limit_id}",
project_id=project_id,
rate_limit_id=rate_limit_id,
),
body=await async_maybe_transform(
{
"batch_1_day_max_input_tokens": batch_1_day_max_input_tokens,
"max_audio_megabytes_per_1_minute": max_audio_megabytes_per_1_minute,
"max_images_per_1_minute": max_images_per_1_minute,
"max_requests_per_1_day": max_requests_per_1_day,
"max_requests_per_1_minute": max_requests_per_1_minute,
"max_tokens_per_1_minute": max_tokens_per_1_minute,
},
rate_limit_update_rate_limit_params.RateLimitUpdateRateLimitParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectRateLimit,
)
class RateLimitsWithRawResponse:
def __init__(self, rate_limits: RateLimits) -> None:
self._rate_limits = rate_limits
self.list_rate_limits = _legacy_response.to_raw_response_wrapper(
rate_limits.list_rate_limits,
)
self.update_rate_limit = _legacy_response.to_raw_response_wrapper(
rate_limits.update_rate_limit,
)
class AsyncRateLimitsWithRawResponse:
def __init__(self, rate_limits: AsyncRateLimits) -> None:
self._rate_limits = rate_limits
self.list_rate_limits = _legacy_response.async_to_raw_response_wrapper(
rate_limits.list_rate_limits,
)
self.update_rate_limit = _legacy_response.async_to_raw_response_wrapper(
rate_limits.update_rate_limit,
)
class RateLimitsWithStreamingResponse:
def __init__(self, rate_limits: RateLimits) -> None:
self._rate_limits = rate_limits
self.list_rate_limits = to_streamed_response_wrapper(
rate_limits.list_rate_limits,
)
self.update_rate_limit = to_streamed_response_wrapper(
rate_limits.update_rate_limit,
)
class AsyncRateLimitsWithStreamingResponse:
def __init__(self, rate_limits: AsyncRateLimits) -> None:
self._rate_limits = rate_limits
self.list_rate_limits = async_to_streamed_response_wrapper(
rate_limits.list_rate_limits,
)
self.update_rate_limit = async_to_streamed_response_wrapper(
rate_limits.update_rate_limit,
)

View File

@@ -0,0 +1,552 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Optional
from typing_extensions import Literal
import httpx
from ..... import _legacy_response
from ....._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncNextCursorPage, AsyncNextCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization.role import Role
from .....types.admin.organization.projects import role_list_params, role_create_params, role_update_params
from .....types.admin.organization.projects.role_delete_response import RoleDeleteResponse
__all__ = ["Roles", "AsyncRoles"]
class Roles(SyncAPIResource):
@cached_property
def with_raw_response(self) -> RolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return RolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> RolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return RolesWithStreamingResponse(self)
def create(
self,
project_id: str,
*,
permissions: SequenceNotStr[str],
role_name: str,
description: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Role:
"""
Creates a custom role for a project.
Args:
permissions: Permissions to grant to the role.
role_name: Unique name for the role.
description: Optional description of the role.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._post(
path_template("/projects/{project_id}/roles", project_id=project_id),
body=maybe_transform(
{
"permissions": permissions,
"role_name": role_name,
"description": description,
},
role_create_params.RoleCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Role,
)
def update(
self,
role_id: str,
*,
project_id: str,
description: Optional[str] | Omit = omit,
permissions: Optional[SequenceNotStr[str]] | Omit = omit,
role_name: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Role:
"""
Updates an existing project role.
Args:
description: New description for the role.
permissions: Updated set of permissions for the role.
role_name: New name for the role.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return self._post(
path_template("/projects/{project_id}/roles/{role_id}", project_id=project_id, role_id=role_id),
body=maybe_transform(
{
"description": description,
"permissions": permissions,
"role_name": role_name,
},
role_update_params.RoleUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Role,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[Role]:
"""Lists the roles configured for a project.
Args:
after: Cursor for pagination.
Provide the value from the previous response's `next`
field to continue listing roles.
limit: A limit on the number of roles to return. Defaults to 1000.
order: Sort order for the returned roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/projects/{project_id}/roles", project_id=project_id),
page=SyncNextCursorPage[Role],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=Role,
)
def delete(
self,
role_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Deletes a custom role from a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return self._delete(
path_template("/projects/{project_id}/roles/{role_id}", project_id=project_id, role_id=role_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class AsyncRoles(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncRolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncRolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncRolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncRolesWithStreamingResponse(self)
async def create(
self,
project_id: str,
*,
permissions: SequenceNotStr[str],
role_name: str,
description: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Role:
"""
Creates a custom role for a project.
Args:
permissions: Permissions to grant to the role.
role_name: Unique name for the role.
description: Optional description of the role.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return await self._post(
path_template("/projects/{project_id}/roles", project_id=project_id),
body=await async_maybe_transform(
{
"permissions": permissions,
"role_name": role_name,
"description": description,
},
role_create_params.RoleCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Role,
)
async def update(
self,
role_id: str,
*,
project_id: str,
description: Optional[str] | Omit = omit,
permissions: Optional[SequenceNotStr[str]] | Omit = omit,
role_name: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Role:
"""
Updates an existing project role.
Args:
description: New description for the role.
permissions: Updated set of permissions for the role.
role_name: New name for the role.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return await self._post(
path_template("/projects/{project_id}/roles/{role_id}", project_id=project_id, role_id=role_id),
body=await async_maybe_transform(
{
"description": description,
"permissions": permissions,
"role_name": role_name,
},
role_update_params.RoleUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Role,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[Role, AsyncNextCursorPage[Role]]:
"""Lists the roles configured for a project.
Args:
after: Cursor for pagination.
Provide the value from the previous response's `next`
field to continue listing roles.
limit: A limit on the number of roles to return. Defaults to 1000.
order: Sort order for the returned roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/projects/{project_id}/roles", project_id=project_id),
page=AsyncNextCursorPage[Role],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=Role,
)
async def delete(
self,
role_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Deletes a custom role from a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return await self._delete(
path_template("/projects/{project_id}/roles/{role_id}", project_id=project_id, role_id=role_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class RolesWithRawResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = _legacy_response.to_raw_response_wrapper(
roles.create,
)
self.update = _legacy_response.to_raw_response_wrapper(
roles.update,
)
self.list = _legacy_response.to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
roles.delete,
)
class AsyncRolesWithRawResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = _legacy_response.async_to_raw_response_wrapper(
roles.create,
)
self.update = _legacy_response.async_to_raw_response_wrapper(
roles.update,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
roles.delete,
)
class RolesWithStreamingResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = to_streamed_response_wrapper(
roles.create,
)
self.update = to_streamed_response_wrapper(
roles.update,
)
self.list = to_streamed_response_wrapper(
roles.list,
)
self.delete = to_streamed_response_wrapper(
roles.delete,
)
class AsyncRolesWithStreamingResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = async_to_streamed_response_wrapper(
roles.create,
)
self.update = async_to_streamed_response_wrapper(
roles.update,
)
self.list = async_to_streamed_response_wrapper(
roles.list,
)
self.delete = async_to_streamed_response_wrapper(
roles.delete,
)

View File

@@ -0,0 +1,512 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
import httpx
from ..... import _legacy_response
from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization.projects import service_account_list_params, service_account_create_params
from .....types.admin.organization.projects.project_service_account import ProjectServiceAccount
from .....types.admin.organization.projects.service_account_create_response import ServiceAccountCreateResponse
from .....types.admin.organization.projects.service_account_delete_response import ServiceAccountDeleteResponse
__all__ = ["ServiceAccounts", "AsyncServiceAccounts"]
class ServiceAccounts(SyncAPIResource):
@cached_property
def with_raw_response(self) -> ServiceAccountsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return ServiceAccountsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> ServiceAccountsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return ServiceAccountsWithStreamingResponse(self)
def create(
self,
project_id: str,
*,
name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ServiceAccountCreateResponse:
"""Creates a new service account in the project.
This also returns an unredacted
API key for the service account.
Args:
name: The name of the service account being created.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._post(
path_template("/organization/projects/{project_id}/service_accounts", project_id=project_id),
body=maybe_transform({"name": name}, service_account_create_params.ServiceAccountCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ServiceAccountCreateResponse,
)
def retrieve(
self,
service_account_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectServiceAccount:
"""
Retrieves a service account in the project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not service_account_id:
raise ValueError(f"Expected a non-empty value for `service_account_id` but received {service_account_id!r}")
return self._get(
path_template(
"/organization/projects/{project_id}/service_accounts/{service_account_id}",
project_id=project_id,
service_account_id=service_account_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectServiceAccount,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[ProjectServiceAccount]:
"""
Returns a list of service accounts in the project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/service_accounts", project_id=project_id),
page=SyncConversationCursorPage[ProjectServiceAccount],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
service_account_list_params.ServiceAccountListParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectServiceAccount,
)
def delete(
self,
service_account_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ServiceAccountDeleteResponse:
"""
Deletes a service account from the project.
Returns confirmation of service account deletion, or an error if the project is
archived (archived projects have no service accounts).
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not service_account_id:
raise ValueError(f"Expected a non-empty value for `service_account_id` but received {service_account_id!r}")
return self._delete(
path_template(
"/organization/projects/{project_id}/service_accounts/{service_account_id}",
project_id=project_id,
service_account_id=service_account_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ServiceAccountDeleteResponse,
)
class AsyncServiceAccounts(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncServiceAccountsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncServiceAccountsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncServiceAccountsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncServiceAccountsWithStreamingResponse(self)
async def create(
self,
project_id: str,
*,
name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ServiceAccountCreateResponse:
"""Creates a new service account in the project.
This also returns an unredacted
API key for the service account.
Args:
name: The name of the service account being created.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return await self._post(
path_template("/organization/projects/{project_id}/service_accounts", project_id=project_id),
body=await async_maybe_transform({"name": name}, service_account_create_params.ServiceAccountCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ServiceAccountCreateResponse,
)
async def retrieve(
self,
service_account_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectServiceAccount:
"""
Retrieves a service account in the project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not service_account_id:
raise ValueError(f"Expected a non-empty value for `service_account_id` but received {service_account_id!r}")
return await self._get(
path_template(
"/organization/projects/{project_id}/service_accounts/{service_account_id}",
project_id=project_id,
service_account_id=service_account_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectServiceAccount,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[ProjectServiceAccount, AsyncConversationCursorPage[ProjectServiceAccount]]:
"""
Returns a list of service accounts in the project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/service_accounts", project_id=project_id),
page=AsyncConversationCursorPage[ProjectServiceAccount],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
service_account_list_params.ServiceAccountListParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectServiceAccount,
)
async def delete(
self,
service_account_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ServiceAccountDeleteResponse:
"""
Deletes a service account from the project.
Returns confirmation of service account deletion, or an error if the project is
archived (archived projects have no service accounts).
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not service_account_id:
raise ValueError(f"Expected a non-empty value for `service_account_id` but received {service_account_id!r}")
return await self._delete(
path_template(
"/organization/projects/{project_id}/service_accounts/{service_account_id}",
project_id=project_id,
service_account_id=service_account_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ServiceAccountDeleteResponse,
)
class ServiceAccountsWithRawResponse:
def __init__(self, service_accounts: ServiceAccounts) -> None:
self._service_accounts = service_accounts
self.create = _legacy_response.to_raw_response_wrapper(
service_accounts.create,
)
self.retrieve = _legacy_response.to_raw_response_wrapper(
service_accounts.retrieve,
)
self.list = _legacy_response.to_raw_response_wrapper(
service_accounts.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
service_accounts.delete,
)
class AsyncServiceAccountsWithRawResponse:
def __init__(self, service_accounts: AsyncServiceAccounts) -> None:
self._service_accounts = service_accounts
self.create = _legacy_response.async_to_raw_response_wrapper(
service_accounts.create,
)
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
service_accounts.retrieve,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
service_accounts.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
service_accounts.delete,
)
class ServiceAccountsWithStreamingResponse:
def __init__(self, service_accounts: ServiceAccounts) -> None:
self._service_accounts = service_accounts
self.create = to_streamed_response_wrapper(
service_accounts.create,
)
self.retrieve = to_streamed_response_wrapper(
service_accounts.retrieve,
)
self.list = to_streamed_response_wrapper(
service_accounts.list,
)
self.delete = to_streamed_response_wrapper(
service_accounts.delete,
)
class AsyncServiceAccountsWithStreamingResponse:
def __init__(self, service_accounts: AsyncServiceAccounts) -> None:
self._service_accounts = service_accounts
self.create = async_to_streamed_response_wrapper(
service_accounts.create,
)
self.retrieve = async_to_streamed_response_wrapper(
service_accounts.retrieve,
)
self.list = async_to_streamed_response_wrapper(
service_accounts.list,
)
self.delete = async_to_streamed_response_wrapper(
service_accounts.delete,
)

View File

@@ -0,0 +1,33 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .users import (
Users,
AsyncUsers,
UsersWithRawResponse,
AsyncUsersWithRawResponse,
UsersWithStreamingResponse,
AsyncUsersWithStreamingResponse,
)
__all__ = [
"Roles",
"AsyncRoles",
"RolesWithRawResponse",
"AsyncRolesWithRawResponse",
"RolesWithStreamingResponse",
"AsyncRolesWithStreamingResponse",
"Users",
"AsyncUsers",
"UsersWithRawResponse",
"AsyncUsersWithRawResponse",
"UsersWithStreamingResponse",
"AsyncUsersWithStreamingResponse",
]

View File

@@ -0,0 +1,426 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ...... import _legacy_response
from ......_types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ......_utils import path_template, maybe_transform, async_maybe_transform
from ......_compat import cached_property
from ......_resource import SyncAPIResource, AsyncAPIResource
from ......_response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ......pagination import SyncNextCursorPage, AsyncNextCursorPage
from ......_base_client import AsyncPaginator, make_request_options
from ......types.admin.organization.projects.users import role_list_params, role_create_params
from ......types.admin.organization.projects.users.role_list_response import RoleListResponse
from ......types.admin.organization.projects.users.role_create_response import RoleCreateResponse
from ......types.admin.organization.projects.users.role_delete_response import RoleDeleteResponse
__all__ = ["Roles", "AsyncRoles"]
class Roles(SyncAPIResource):
@cached_property
def with_raw_response(self) -> RolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return RolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> RolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return RolesWithStreamingResponse(self)
def create(
self,
user_id: str,
*,
project_id: str,
role_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns a project role to a user within a project.
Args:
role_id: Identifier of the role to assign.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._post(
path_template("/projects/{project_id}/users/{user_id}/roles", project_id=project_id, user_id=user_id),
body=maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleCreateResponse,
)
def list(
self,
user_id: str,
*,
project_id: str,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[RoleListResponse]:
"""
Lists the project roles assigned to a user within a project.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing project roles.
limit: A limit on the number of project role assignments to return.
order: Sort order for the returned project roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._get_api_list(
path_template("/projects/{project_id}/users/{user_id}/roles", project_id=project_id, user_id=user_id),
page=SyncNextCursorPage[RoleListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=RoleListResponse,
)
def delete(
self,
role_id: str,
*,
project_id: str,
user_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Unassigns a project role from a user within a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return self._delete(
path_template(
"/projects/{project_id}/users/{user_id}/roles/{role_id}",
project_id=project_id,
user_id=user_id,
role_id=role_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class AsyncRoles(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncRolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncRolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncRolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncRolesWithStreamingResponse(self)
async def create(
self,
user_id: str,
*,
project_id: str,
role_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns a project role to a user within a project.
Args:
role_id: Identifier of the role to assign.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._post(
path_template("/projects/{project_id}/users/{user_id}/roles", project_id=project_id, user_id=user_id),
body=await async_maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleCreateResponse,
)
def list(
self,
user_id: str,
*,
project_id: str,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[RoleListResponse, AsyncNextCursorPage[RoleListResponse]]:
"""
Lists the project roles assigned to a user within a project.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing project roles.
limit: A limit on the number of project role assignments to return.
order: Sort order for the returned project roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._get_api_list(
path_template("/projects/{project_id}/users/{user_id}/roles", project_id=project_id, user_id=user_id),
page=AsyncNextCursorPage[RoleListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=RoleListResponse,
)
async def delete(
self,
role_id: str,
*,
project_id: str,
user_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Unassigns a project role from a user within a project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return await self._delete(
path_template(
"/projects/{project_id}/users/{user_id}/roles/{role_id}",
project_id=project_id,
user_id=user_id,
role_id=role_id,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class RolesWithRawResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = _legacy_response.to_raw_response_wrapper(
roles.create,
)
self.list = _legacy_response.to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
roles.delete,
)
class AsyncRolesWithRawResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = _legacy_response.async_to_raw_response_wrapper(
roles.create,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
roles.delete,
)
class RolesWithStreamingResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = to_streamed_response_wrapper(
roles.create,
)
self.list = to_streamed_response_wrapper(
roles.list,
)
self.delete = to_streamed_response_wrapper(
roles.delete,
)
class AsyncRolesWithStreamingResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = async_to_streamed_response_wrapper(
roles.create,
)
self.list = async_to_streamed_response_wrapper(
roles.list,
)
self.delete = async_to_streamed_response_wrapper(
roles.delete,
)

View File

@@ -0,0 +1,667 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Optional
import httpx
from ...... import _legacy_response
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from ......_types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ......_utils import path_template, maybe_transform, async_maybe_transform
from ......_compat import cached_property
from ......_resource import SyncAPIResource, AsyncAPIResource
from ......_response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ......pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ......_base_client import AsyncPaginator, make_request_options
from ......types.admin.organization.projects import user_list_params, user_create_params, user_update_params
from ......types.admin.organization.projects.project_user import ProjectUser
from ......types.admin.organization.projects.user_delete_response import UserDeleteResponse
__all__ = ["Users", "AsyncUsers"]
class Users(SyncAPIResource):
@cached_property
def roles(self) -> Roles:
return Roles(self._client)
@cached_property
def with_raw_response(self) -> UsersWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return UsersWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> UsersWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return UsersWithStreamingResponse(self)
def create(
self,
project_id: str,
*,
role: str,
email: Optional[str] | Omit = omit,
user_id: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectUser:
"""Adds a user to the project.
Users must already be members of the organization to
be added to a project.
Args:
role: `owner` or `member`
email: Email of the user to add.
user_id: The ID of the user.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._post(
path_template("/organization/projects/{project_id}/users", project_id=project_id),
body=maybe_transform(
{
"role": role,
"email": email,
"user_id": user_id,
},
user_create_params.UserCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectUser,
)
def retrieve(
self,
user_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectUser:
"""
Retrieves a user in the project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._get(
path_template(
"/organization/projects/{project_id}/users/{user_id}", project_id=project_id, user_id=user_id
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectUser,
)
def update(
self,
user_id: str,
*,
project_id: str,
role: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectUser:
"""
Modifies a user's role in the project.
Args:
role: `owner` or `member`
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._post(
path_template(
"/organization/projects/{project_id}/users/{user_id}", project_id=project_id, user_id=user_id
),
body=maybe_transform({"role": role}, user_update_params.UserUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectUser,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[ProjectUser]:
"""
Returns a list of users in the project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/users", project_id=project_id),
page=SyncConversationCursorPage[ProjectUser],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
user_list_params.UserListParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectUser,
)
def delete(
self,
user_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> UserDeleteResponse:
"""
Deletes a user from the project.
Returns confirmation of project user deletion, or an error if the project is
archived (archived projects have no users).
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._delete(
path_template(
"/organization/projects/{project_id}/users/{user_id}", project_id=project_id, user_id=user_id
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=UserDeleteResponse,
)
class AsyncUsers(AsyncAPIResource):
@cached_property
def roles(self) -> AsyncRoles:
return AsyncRoles(self._client)
@cached_property
def with_raw_response(self) -> AsyncUsersWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncUsersWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncUsersWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncUsersWithStreamingResponse(self)
async def create(
self,
project_id: str,
*,
role: str,
email: Optional[str] | Omit = omit,
user_id: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectUser:
"""Adds a user to the project.
Users must already be members of the organization to
be added to a project.
Args:
role: `owner` or `member`
email: Email of the user to add.
user_id: The ID of the user.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return await self._post(
path_template("/organization/projects/{project_id}/users", project_id=project_id),
body=await async_maybe_transform(
{
"role": role,
"email": email,
"user_id": user_id,
},
user_create_params.UserCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectUser,
)
async def retrieve(
self,
user_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectUser:
"""
Retrieves a user in the project.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._get(
path_template(
"/organization/projects/{project_id}/users/{user_id}", project_id=project_id, user_id=user_id
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectUser,
)
async def update(
self,
user_id: str,
*,
project_id: str,
role: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ProjectUser:
"""
Modifies a user's role in the project.
Args:
role: `owner` or `member`
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._post(
path_template(
"/organization/projects/{project_id}/users/{user_id}", project_id=project_id, user_id=user_id
),
body=await async_maybe_transform({"role": role}, user_update_params.UserUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=ProjectUser,
)
def list(
self,
project_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[ProjectUser, AsyncConversationCursorPage[ProjectUser]]:
"""
Returns a list of users in the project.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
return self._get_api_list(
path_template("/organization/projects/{project_id}/users", project_id=project_id),
page=AsyncConversationCursorPage[ProjectUser],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
user_list_params.UserListParams,
),
security={"admin_api_key_auth": True},
),
model=ProjectUser,
)
async def delete(
self,
user_id: str,
*,
project_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> UserDeleteResponse:
"""
Deletes a user from the project.
Returns confirmation of project user deletion, or an error if the project is
archived (archived projects have no users).
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not project_id:
raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._delete(
path_template(
"/organization/projects/{project_id}/users/{user_id}", project_id=project_id, user_id=user_id
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=UserDeleteResponse,
)
class UsersWithRawResponse:
def __init__(self, users: Users) -> None:
self._users = users
self.create = _legacy_response.to_raw_response_wrapper(
users.create,
)
self.retrieve = _legacy_response.to_raw_response_wrapper(
users.retrieve,
)
self.update = _legacy_response.to_raw_response_wrapper(
users.update,
)
self.list = _legacy_response.to_raw_response_wrapper(
users.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
users.delete,
)
@cached_property
def roles(self) -> RolesWithRawResponse:
return RolesWithRawResponse(self._users.roles)
class AsyncUsersWithRawResponse:
def __init__(self, users: AsyncUsers) -> None:
self._users = users
self.create = _legacy_response.async_to_raw_response_wrapper(
users.create,
)
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
users.retrieve,
)
self.update = _legacy_response.async_to_raw_response_wrapper(
users.update,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
users.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
users.delete,
)
@cached_property
def roles(self) -> AsyncRolesWithRawResponse:
return AsyncRolesWithRawResponse(self._users.roles)
class UsersWithStreamingResponse:
def __init__(self, users: Users) -> None:
self._users = users
self.create = to_streamed_response_wrapper(
users.create,
)
self.retrieve = to_streamed_response_wrapper(
users.retrieve,
)
self.update = to_streamed_response_wrapper(
users.update,
)
self.list = to_streamed_response_wrapper(
users.list,
)
self.delete = to_streamed_response_wrapper(
users.delete,
)
@cached_property
def roles(self) -> RolesWithStreamingResponse:
return RolesWithStreamingResponse(self._users.roles)
class AsyncUsersWithStreamingResponse:
def __init__(self, users: AsyncUsers) -> None:
self._users = users
self.create = async_to_streamed_response_wrapper(
users.create,
)
self.retrieve = async_to_streamed_response_wrapper(
users.retrieve,
)
self.update = async_to_streamed_response_wrapper(
users.update,
)
self.list = async_to_streamed_response_wrapper(
users.list,
)
self.delete = async_to_streamed_response_wrapper(
users.delete,
)
@cached_property
def roles(self) -> AsyncRolesWithStreamingResponse:
return AsyncRolesWithStreamingResponse(self._users.roles)

View File

@@ -0,0 +1,526 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Optional
from typing_extensions import Literal
import httpx
from .... import _legacy_response
from ...._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
from ...._utils import path_template, maybe_transform, async_maybe_transform
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ....pagination import SyncNextCursorPage, AsyncNextCursorPage
from ...._base_client import AsyncPaginator, make_request_options
from ....types.admin.organization import role_list_params, role_create_params, role_update_params
from ....types.admin.organization.role import Role
from ....types.admin.organization.role_delete_response import RoleDeleteResponse
__all__ = ["Roles", "AsyncRoles"]
class Roles(SyncAPIResource):
@cached_property
def with_raw_response(self) -> RolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return RolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> RolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return RolesWithStreamingResponse(self)
def create(
self,
*,
permissions: SequenceNotStr[str],
role_name: str,
description: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Role:
"""
Creates a custom role for the organization.
Args:
permissions: Permissions to grant to the role.
role_name: Unique name for the role.
description: Optional description of the role.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/organization/roles",
body=maybe_transform(
{
"permissions": permissions,
"role_name": role_name,
"description": description,
},
role_create_params.RoleCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Role,
)
def update(
self,
role_id: str,
*,
description: Optional[str] | Omit = omit,
permissions: Optional[SequenceNotStr[str]] | Omit = omit,
role_name: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Role:
"""
Updates an existing organization role.
Args:
description: New description for the role.
permissions: Updated set of permissions for the role.
role_name: New name for the role.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return self._post(
path_template("/organization/roles/{role_id}", role_id=role_id),
body=maybe_transform(
{
"description": description,
"permissions": permissions,
"role_name": role_name,
},
role_update_params.RoleUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Role,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[Role]:
"""
Lists the roles configured for the organization.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing roles.
limit: A limit on the number of roles to return. Defaults to 1000.
order: Sort order for the returned roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/roles",
page=SyncNextCursorPage[Role],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=Role,
)
def delete(
self,
role_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Deletes a custom role from the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return self._delete(
path_template("/organization/roles/{role_id}", role_id=role_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class AsyncRoles(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncRolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncRolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncRolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncRolesWithStreamingResponse(self)
async def create(
self,
*,
permissions: SequenceNotStr[str],
role_name: str,
description: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Role:
"""
Creates a custom role for the organization.
Args:
permissions: Permissions to grant to the role.
role_name: Unique name for the role.
description: Optional description of the role.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/organization/roles",
body=await async_maybe_transform(
{
"permissions": permissions,
"role_name": role_name,
"description": description,
},
role_create_params.RoleCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Role,
)
async def update(
self,
role_id: str,
*,
description: Optional[str] | Omit = omit,
permissions: Optional[SequenceNotStr[str]] | Omit = omit,
role_name: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Role:
"""
Updates an existing organization role.
Args:
description: New description for the role.
permissions: Updated set of permissions for the role.
role_name: New name for the role.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return await self._post(
path_template("/organization/roles/{role_id}", role_id=role_id),
body=await async_maybe_transform(
{
"description": description,
"permissions": permissions,
"role_name": role_name,
},
role_update_params.RoleUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=Role,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[Role, AsyncNextCursorPage[Role]]:
"""
Lists the roles configured for the organization.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing roles.
limit: A limit on the number of roles to return. Defaults to 1000.
order: Sort order for the returned roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/roles",
page=AsyncNextCursorPage[Role],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=Role,
)
async def delete(
self,
role_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Deletes a custom role from the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return await self._delete(
path_template("/organization/roles/{role_id}", role_id=role_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class RolesWithRawResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = _legacy_response.to_raw_response_wrapper(
roles.create,
)
self.update = _legacy_response.to_raw_response_wrapper(
roles.update,
)
self.list = _legacy_response.to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
roles.delete,
)
class AsyncRolesWithRawResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = _legacy_response.async_to_raw_response_wrapper(
roles.create,
)
self.update = _legacy_response.async_to_raw_response_wrapper(
roles.update,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
roles.delete,
)
class RolesWithStreamingResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = to_streamed_response_wrapper(
roles.create,
)
self.update = to_streamed_response_wrapper(
roles.update,
)
self.list = to_streamed_response_wrapper(
roles.list,
)
self.delete = to_streamed_response_wrapper(
roles.delete,
)
class AsyncRolesWithStreamingResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = async_to_streamed_response_wrapper(
roles.create,
)
self.update = async_to_streamed_response_wrapper(
roles.update,
)
self.list = async_to_streamed_response_wrapper(
roles.list,
)
self.delete = async_to_streamed_response_wrapper(
roles.delete,
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,33 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from .users import (
Users,
AsyncUsers,
UsersWithRawResponse,
AsyncUsersWithRawResponse,
UsersWithStreamingResponse,
AsyncUsersWithStreamingResponse,
)
__all__ = [
"Roles",
"AsyncRoles",
"RolesWithRawResponse",
"AsyncRolesWithRawResponse",
"RolesWithStreamingResponse",
"AsyncRolesWithStreamingResponse",
"Users",
"AsyncUsers",
"UsersWithRawResponse",
"AsyncUsersWithRawResponse",
"UsersWithStreamingResponse",
"AsyncUsersWithStreamingResponse",
]

View File

@@ -0,0 +1,398 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from ..... import _legacy_response
from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncNextCursorPage, AsyncNextCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization.users import role_list_params, role_create_params
from .....types.admin.organization.users.role_list_response import RoleListResponse
from .....types.admin.organization.users.role_create_response import RoleCreateResponse
from .....types.admin.organization.users.role_delete_response import RoleDeleteResponse
__all__ = ["Roles", "AsyncRoles"]
class Roles(SyncAPIResource):
@cached_property
def with_raw_response(self) -> RolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return RolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> RolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return RolesWithStreamingResponse(self)
def create(
self,
user_id: str,
*,
role_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns an organization role to a user within the organization.
Args:
role_id: Identifier of the role to assign.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._post(
path_template("/organization/users/{user_id}/roles", user_id=user_id),
body=maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleCreateResponse,
)
def list(
self,
user_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncNextCursorPage[RoleListResponse]:
"""
Lists the organization roles assigned to a user within the organization.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing organization roles.
limit: A limit on the number of organization role assignments to return.
order: Sort order for the returned organization roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._get_api_list(
path_template("/organization/users/{user_id}/roles", user_id=user_id),
page=SyncNextCursorPage[RoleListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=RoleListResponse,
)
def delete(
self,
role_id: str,
*,
user_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Unassigns an organization role from a user within the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return self._delete(
path_template("/organization/users/{user_id}/roles/{role_id}", user_id=user_id, role_id=role_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class AsyncRoles(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncRolesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncRolesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncRolesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncRolesWithStreamingResponse(self)
async def create(
self,
user_id: str,
*,
role_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns an organization role to a user within the organization.
Args:
role_id: Identifier of the role to assign.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._post(
path_template("/organization/users/{user_id}/roles", user_id=user_id),
body=await async_maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleCreateResponse,
)
def list(
self,
user_id: str,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[RoleListResponse, AsyncNextCursorPage[RoleListResponse]]:
"""
Lists the organization roles assigned to a user within the organization.
Args:
after: Cursor for pagination. Provide the value from the previous response's `next`
field to continue listing organization roles.
limit: A limit on the number of organization role assignments to return.
order: Sort order for the returned organization roles.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._get_api_list(
path_template("/organization/users/{user_id}/roles", user_id=user_id),
page=AsyncNextCursorPage[RoleListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
"order": order,
},
role_list_params.RoleListParams,
),
security={"admin_api_key_auth": True},
),
model=RoleListResponse,
)
async def delete(
self,
role_id: str,
*,
user_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> RoleDeleteResponse:
"""
Unassigns an organization role from a user within the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
if not role_id:
raise ValueError(f"Expected a non-empty value for `role_id` but received {role_id!r}")
return await self._delete(
path_template("/organization/users/{user_id}/roles/{role_id}", user_id=user_id, role_id=role_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=RoleDeleteResponse,
)
class RolesWithRawResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = _legacy_response.to_raw_response_wrapper(
roles.create,
)
self.list = _legacy_response.to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
roles.delete,
)
class AsyncRolesWithRawResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = _legacy_response.async_to_raw_response_wrapper(
roles.create,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
roles.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
roles.delete,
)
class RolesWithStreamingResponse:
def __init__(self, roles: Roles) -> None:
self._roles = roles
self.create = to_streamed_response_wrapper(
roles.create,
)
self.list = to_streamed_response_wrapper(
roles.list,
)
self.delete = to_streamed_response_wrapper(
roles.delete,
)
class AsyncRolesWithStreamingResponse:
def __init__(self, roles: AsyncRoles) -> None:
self._roles = roles
self.create = async_to_streamed_response_wrapper(
roles.create,
)
self.list = async_to_streamed_response_wrapper(
roles.list,
)
self.delete = async_to_streamed_response_wrapper(
roles.delete,
)

View File

@@ -0,0 +1,543 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Optional
import httpx
from ..... import _legacy_response
from .roles import (
Roles,
AsyncRoles,
RolesWithRawResponse,
AsyncRolesWithRawResponse,
RolesWithStreamingResponse,
AsyncRolesWithStreamingResponse,
)
from ....._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
from ....._utils import path_template, maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .....pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ....._base_client import AsyncPaginator, make_request_options
from .....types.admin.organization import user_list_params, user_update_params
from .....types.admin.organization.organization_user import OrganizationUser
from .....types.admin.organization.user_delete_response import UserDeleteResponse
__all__ = ["Users", "AsyncUsers"]
class Users(SyncAPIResource):
@cached_property
def roles(self) -> Roles:
return Roles(self._client)
@cached_property
def with_raw_response(self) -> UsersWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return UsersWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> UsersWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return UsersWithStreamingResponse(self)
def retrieve(
self,
user_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> OrganizationUser:
"""
Retrieves a user by their identifier.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._get(
path_template("/organization/users/{user_id}", user_id=user_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=OrganizationUser,
)
def update(
self,
user_id: str,
*,
developer_persona: Optional[str] | Omit = omit,
role: Optional[str] | Omit = omit,
role_id: Optional[str] | Omit = omit,
technical_level: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> OrganizationUser:
"""
Modifies a user's role in the organization.
Args:
developer_persona: Developer persona metadata.
role: `owner` or `reader`
role_id: Role ID to assign to the user.
technical_level: Technical level metadata.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._post(
path_template("/organization/users/{user_id}", user_id=user_id),
body=maybe_transform(
{
"developer_persona": developer_persona,
"role": role,
"role_id": role_id,
"technical_level": technical_level,
},
user_update_params.UserUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=OrganizationUser,
)
def list(
self,
*,
after: str | Omit = omit,
emails: SequenceNotStr[str] | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[OrganizationUser]:
"""
Lists all of the users in the organization.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
emails: Filter by the email address of users.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/users",
page=SyncConversationCursorPage[OrganizationUser],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"emails": emails,
"limit": limit,
},
user_list_params.UserListParams,
),
security={"admin_api_key_auth": True},
),
model=OrganizationUser,
)
def delete(
self,
user_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> UserDeleteResponse:
"""
Deletes a user from the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return self._delete(
path_template("/organization/users/{user_id}", user_id=user_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=UserDeleteResponse,
)
class AsyncUsers(AsyncAPIResource):
@cached_property
def roles(self) -> AsyncRoles:
return AsyncRoles(self._client)
@cached_property
def with_raw_response(self) -> AsyncUsersWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncUsersWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncUsersWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncUsersWithStreamingResponse(self)
async def retrieve(
self,
user_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> OrganizationUser:
"""
Retrieves a user by their identifier.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._get(
path_template("/organization/users/{user_id}", user_id=user_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=OrganizationUser,
)
async def update(
self,
user_id: str,
*,
developer_persona: Optional[str] | Omit = omit,
role: Optional[str] | Omit = omit,
role_id: Optional[str] | Omit = omit,
technical_level: Optional[str] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> OrganizationUser:
"""
Modifies a user's role in the organization.
Args:
developer_persona: Developer persona metadata.
role: `owner` or `reader`
role_id: Role ID to assign to the user.
technical_level: Technical level metadata.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._post(
path_template("/organization/users/{user_id}", user_id=user_id),
body=await async_maybe_transform(
{
"developer_persona": developer_persona,
"role": role,
"role_id": role_id,
"technical_level": technical_level,
},
user_update_params.UserUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=OrganizationUser,
)
def list(
self,
*,
after: str | Omit = omit,
emails: SequenceNotStr[str] | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[OrganizationUser, AsyncConversationCursorPage[OrganizationUser]]:
"""
Lists all of the users in the organization.
Args:
after: A cursor for use in pagination. `after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
emails: Filter by the email address of users.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/organization/users",
page=AsyncConversationCursorPage[OrganizationUser],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"emails": emails,
"limit": limit,
},
user_list_params.UserListParams,
),
security={"admin_api_key_auth": True},
),
model=OrganizationUser,
)
async def delete(
self,
user_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> UserDeleteResponse:
"""
Deletes a user from the organization.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not user_id:
raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
return await self._delete(
path_template("/organization/users/{user_id}", user_id=user_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"admin_api_key_auth": True},
),
cast_to=UserDeleteResponse,
)
class UsersWithRawResponse:
def __init__(self, users: Users) -> None:
self._users = users
self.retrieve = _legacy_response.to_raw_response_wrapper(
users.retrieve,
)
self.update = _legacy_response.to_raw_response_wrapper(
users.update,
)
self.list = _legacy_response.to_raw_response_wrapper(
users.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
users.delete,
)
@cached_property
def roles(self) -> RolesWithRawResponse:
return RolesWithRawResponse(self._users.roles)
class AsyncUsersWithRawResponse:
def __init__(self, users: AsyncUsers) -> None:
self._users = users
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
users.retrieve,
)
self.update = _legacy_response.async_to_raw_response_wrapper(
users.update,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
users.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
users.delete,
)
@cached_property
def roles(self) -> AsyncRolesWithRawResponse:
return AsyncRolesWithRawResponse(self._users.roles)
class UsersWithStreamingResponse:
def __init__(self, users: Users) -> None:
self._users = users
self.retrieve = to_streamed_response_wrapper(
users.retrieve,
)
self.update = to_streamed_response_wrapper(
users.update,
)
self.list = to_streamed_response_wrapper(
users.list,
)
self.delete = to_streamed_response_wrapper(
users.delete,
)
@cached_property
def roles(self) -> RolesWithStreamingResponse:
return RolesWithStreamingResponse(self._users.roles)
class AsyncUsersWithStreamingResponse:
def __init__(self, users: AsyncUsers) -> None:
self._users = users
self.retrieve = async_to_streamed_response_wrapper(
users.retrieve,
)
self.update = async_to_streamed_response_wrapper(
users.update,
)
self.list = async_to_streamed_response_wrapper(
users.list,
)
self.delete = async_to_streamed_response_wrapper(
users.delete,
)
@cached_property
def roles(self) -> AsyncRolesWithStreamingResponse:
return AsyncRolesWithStreamingResponse(self._users.roles)

View File

@@ -0,0 +1,61 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .audio import (
Audio,
AsyncAudio,
AudioWithRawResponse,
AsyncAudioWithRawResponse,
AudioWithStreamingResponse,
AsyncAudioWithStreamingResponse,
)
from .speech import (
Speech,
AsyncSpeech,
SpeechWithRawResponse,
AsyncSpeechWithRawResponse,
SpeechWithStreamingResponse,
AsyncSpeechWithStreamingResponse,
)
from .translations import (
Translations,
AsyncTranslations,
TranslationsWithRawResponse,
AsyncTranslationsWithRawResponse,
TranslationsWithStreamingResponse,
AsyncTranslationsWithStreamingResponse,
)
from .transcriptions import (
Transcriptions,
AsyncTranscriptions,
TranscriptionsWithRawResponse,
AsyncTranscriptionsWithRawResponse,
TranscriptionsWithStreamingResponse,
AsyncTranscriptionsWithStreamingResponse,
)
__all__ = [
"Transcriptions",
"AsyncTranscriptions",
"TranscriptionsWithRawResponse",
"AsyncTranscriptionsWithRawResponse",
"TranscriptionsWithStreamingResponse",
"AsyncTranscriptionsWithStreamingResponse",
"Translations",
"AsyncTranslations",
"TranslationsWithRawResponse",
"AsyncTranslationsWithRawResponse",
"TranslationsWithStreamingResponse",
"AsyncTranslationsWithStreamingResponse",
"Speech",
"AsyncSpeech",
"SpeechWithRawResponse",
"AsyncSpeechWithRawResponse",
"SpeechWithStreamingResponse",
"AsyncSpeechWithStreamingResponse",
"Audio",
"AsyncAudio",
"AudioWithRawResponse",
"AsyncAudioWithRawResponse",
"AudioWithStreamingResponse",
"AsyncAudioWithStreamingResponse",
]

View File

@@ -0,0 +1,184 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from .speech import (
Speech,
AsyncSpeech,
SpeechWithRawResponse,
AsyncSpeechWithRawResponse,
SpeechWithStreamingResponse,
AsyncSpeechWithStreamingResponse,
)
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from .translations import (
Translations,
AsyncTranslations,
TranslationsWithRawResponse,
AsyncTranslationsWithRawResponse,
TranslationsWithStreamingResponse,
AsyncTranslationsWithStreamingResponse,
)
from .transcriptions import (
Transcriptions,
AsyncTranscriptions,
TranscriptionsWithRawResponse,
AsyncTranscriptionsWithRawResponse,
TranscriptionsWithStreamingResponse,
AsyncTranscriptionsWithStreamingResponse,
)
__all__ = ["Audio", "AsyncAudio"]
class Audio(SyncAPIResource):
@cached_property
def transcriptions(self) -> Transcriptions:
"""Turn audio into text or text into audio."""
return Transcriptions(self._client)
@cached_property
def translations(self) -> Translations:
"""Turn audio into text or text into audio."""
return Translations(self._client)
@cached_property
def speech(self) -> Speech:
"""Turn audio into text or text into audio."""
return Speech(self._client)
@cached_property
def with_raw_response(self) -> AudioWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AudioWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AudioWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AudioWithStreamingResponse(self)
class AsyncAudio(AsyncAPIResource):
@cached_property
def transcriptions(self) -> AsyncTranscriptions:
"""Turn audio into text or text into audio."""
return AsyncTranscriptions(self._client)
@cached_property
def translations(self) -> AsyncTranslations:
"""Turn audio into text or text into audio."""
return AsyncTranslations(self._client)
@cached_property
def speech(self) -> AsyncSpeech:
"""Turn audio into text or text into audio."""
return AsyncSpeech(self._client)
@cached_property
def with_raw_response(self) -> AsyncAudioWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncAudioWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncAudioWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncAudioWithStreamingResponse(self)
class AudioWithRawResponse:
def __init__(self, audio: Audio) -> None:
self._audio = audio
@cached_property
def transcriptions(self) -> TranscriptionsWithRawResponse:
"""Turn audio into text or text into audio."""
return TranscriptionsWithRawResponse(self._audio.transcriptions)
@cached_property
def translations(self) -> TranslationsWithRawResponse:
"""Turn audio into text or text into audio."""
return TranslationsWithRawResponse(self._audio.translations)
@cached_property
def speech(self) -> SpeechWithRawResponse:
"""Turn audio into text or text into audio."""
return SpeechWithRawResponse(self._audio.speech)
class AsyncAudioWithRawResponse:
def __init__(self, audio: AsyncAudio) -> None:
self._audio = audio
@cached_property
def transcriptions(self) -> AsyncTranscriptionsWithRawResponse:
"""Turn audio into text or text into audio."""
return AsyncTranscriptionsWithRawResponse(self._audio.transcriptions)
@cached_property
def translations(self) -> AsyncTranslationsWithRawResponse:
"""Turn audio into text or text into audio."""
return AsyncTranslationsWithRawResponse(self._audio.translations)
@cached_property
def speech(self) -> AsyncSpeechWithRawResponse:
"""Turn audio into text or text into audio."""
return AsyncSpeechWithRawResponse(self._audio.speech)
class AudioWithStreamingResponse:
def __init__(self, audio: Audio) -> None:
self._audio = audio
@cached_property
def transcriptions(self) -> TranscriptionsWithStreamingResponse:
"""Turn audio into text or text into audio."""
return TranscriptionsWithStreamingResponse(self._audio.transcriptions)
@cached_property
def translations(self) -> TranslationsWithStreamingResponse:
"""Turn audio into text or text into audio."""
return TranslationsWithStreamingResponse(self._audio.translations)
@cached_property
def speech(self) -> SpeechWithStreamingResponse:
"""Turn audio into text or text into audio."""
return SpeechWithStreamingResponse(self._audio.speech)
class AsyncAudioWithStreamingResponse:
def __init__(self, audio: AsyncAudio) -> None:
self._audio = audio
@cached_property
def transcriptions(self) -> AsyncTranscriptionsWithStreamingResponse:
"""Turn audio into text or text into audio."""
return AsyncTranscriptionsWithStreamingResponse(self._audio.transcriptions)
@cached_property
def translations(self) -> AsyncTranslationsWithStreamingResponse:
"""Turn audio into text or text into audio."""
return AsyncTranslationsWithStreamingResponse(self._audio.translations)
@cached_property
def speech(self) -> AsyncSpeechWithStreamingResponse:
"""Turn audio into text or text into audio."""
return AsyncSpeechWithStreamingResponse(self._audio.speech)

View File

@@ -0,0 +1,271 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Union
from typing_extensions import Literal
import httpx
from ... import _legacy_response
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ..._utils import maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
StreamedBinaryAPIResponse,
AsyncStreamedBinaryAPIResponse,
to_custom_streamed_response_wrapper,
async_to_custom_streamed_response_wrapper,
)
from ...types.audio import speech_create_params
from ..._base_client import make_request_options
from ...types.audio.speech_model import SpeechModel
__all__ = ["Speech", "AsyncSpeech"]
class Speech(SyncAPIResource):
"""Turn audio into text or text into audio."""
@cached_property
def with_raw_response(self) -> SpeechWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return SpeechWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> SpeechWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return SpeechWithStreamingResponse(self)
def create(
self,
*,
input: str,
model: Union[str, SpeechModel],
voice: speech_create_params.Voice,
instructions: str | Omit = omit,
response_format: Literal["mp3", "opus", "aac", "flac", "wav", "pcm"] | Omit = omit,
speed: float | Omit = omit,
stream_format: Literal["sse", "audio"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> _legacy_response.HttpxBinaryResponseContent:
"""
Generates audio from the input text.
Returns the audio file content, or a stream of audio events.
Args:
input: The text to generate audio for. The maximum length is 4096 characters.
model:
One of the available [TTS models](https://platform.openai.com/docs/models#tts):
`tts-1`, `tts-1-hd`, `gpt-4o-mini-tts`, or `gpt-4o-mini-tts-2025-12-15`.
voice: The voice to use when generating the audio. Supported built-in voices are
`alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`,
`shimmer`, `verse`, `marin`, and `cedar`. You may also provide a custom voice
object with an `id`, for example `{ "id": "voice_1234" }`. Previews of the
voices are available in the
[Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
instructions: Control the voice of your generated audio with additional instructions. Does not
work with `tts-1` or `tts-1-hd`.
response_format: The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`,
`wav`, and `pcm`.
speed: The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is
the default.
stream_format: The format to stream the audio in. Supported formats are `sse` and `audio`.
`sse` is not supported for `tts-1` or `tts-1-hd`.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
return self._post(
"/audio/speech",
body=maybe_transform(
{
"input": input,
"model": model,
"voice": voice,
"instructions": instructions,
"response_format": response_format,
"speed": speed,
"stream_format": stream_format,
},
speech_create_params.SpeechCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=_legacy_response.HttpxBinaryResponseContent,
)
class AsyncSpeech(AsyncAPIResource):
"""Turn audio into text or text into audio."""
@cached_property
def with_raw_response(self) -> AsyncSpeechWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncSpeechWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncSpeechWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncSpeechWithStreamingResponse(self)
async def create(
self,
*,
input: str,
model: Union[str, SpeechModel],
voice: speech_create_params.Voice,
instructions: str | Omit = omit,
response_format: Literal["mp3", "opus", "aac", "flac", "wav", "pcm"] | Omit = omit,
speed: float | Omit = omit,
stream_format: Literal["sse", "audio"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> _legacy_response.HttpxBinaryResponseContent:
"""
Generates audio from the input text.
Returns the audio file content, or a stream of audio events.
Args:
input: The text to generate audio for. The maximum length is 4096 characters.
model:
One of the available [TTS models](https://platform.openai.com/docs/models#tts):
`tts-1`, `tts-1-hd`, `gpt-4o-mini-tts`, or `gpt-4o-mini-tts-2025-12-15`.
voice: The voice to use when generating the audio. Supported built-in voices are
`alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`,
`shimmer`, `verse`, `marin`, and `cedar`. You may also provide a custom voice
object with an `id`, for example `{ "id": "voice_1234" }`. Previews of the
voices are available in the
[Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
instructions: Control the voice of your generated audio with additional instructions. Does not
work with `tts-1` or `tts-1-hd`.
response_format: The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`,
`wav`, and `pcm`.
speed: The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is
the default.
stream_format: The format to stream the audio in. Supported formats are `sse` and `audio`.
`sse` is not supported for `tts-1` or `tts-1-hd`.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
return await self._post(
"/audio/speech",
body=await async_maybe_transform(
{
"input": input,
"model": model,
"voice": voice,
"instructions": instructions,
"response_format": response_format,
"speed": speed,
"stream_format": stream_format,
},
speech_create_params.SpeechCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=_legacy_response.HttpxBinaryResponseContent,
)
class SpeechWithRawResponse:
def __init__(self, speech: Speech) -> None:
self._speech = speech
self.create = _legacy_response.to_raw_response_wrapper(
speech.create,
)
class AsyncSpeechWithRawResponse:
def __init__(self, speech: AsyncSpeech) -> None:
self._speech = speech
self.create = _legacy_response.async_to_raw_response_wrapper(
speech.create,
)
class SpeechWithStreamingResponse:
def __init__(self, speech: Speech) -> None:
self._speech = speech
self.create = to_custom_streamed_response_wrapper(
speech.create,
StreamedBinaryAPIResponse,
)
class AsyncSpeechWithStreamingResponse:
def __init__(self, speech: AsyncSpeech) -> None:
self._speech = speech
self.create = async_to_custom_streamed_response_wrapper(
speech.create,
AsyncStreamedBinaryAPIResponse,
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,382 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Union, Mapping, cast
from typing_extensions import Literal, overload, assert_never
import httpx
from ... import _legacy_response
from ..._files import deepcopy_with_paths
from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given
from ..._utils import extract_files, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ...types.audio import translation_create_params
from ..._base_client import make_request_options
from ...types.audio_model import AudioModel
from ...types.audio.translation import Translation
from ...types.audio_response_format import AudioResponseFormat
from ...types.audio.translation_verbose import TranslationVerbose
__all__ = ["Translations", "AsyncTranslations"]
log: logging.Logger = logging.getLogger("openai.audio.transcriptions")
class Translations(SyncAPIResource):
"""Turn audio into text or text into audio."""
@cached_property
def with_raw_response(self) -> TranslationsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return TranslationsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> TranslationsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return TranslationsWithStreamingResponse(self)
@overload
def create(
self,
*,
file: FileTypes,
model: Union[str, AudioModel],
response_format: Union[Literal["json"], Omit] = omit,
prompt: str | Omit = omit,
temperature: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Translation: ...
@overload
def create(
self,
*,
file: FileTypes,
model: Union[str, AudioModel],
response_format: Literal["verbose_json"],
prompt: str | Omit = omit,
temperature: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> TranslationVerbose: ...
@overload
def create(
self,
*,
file: FileTypes,
model: Union[str, AudioModel],
response_format: Literal["text", "srt", "vtt"],
prompt: str | Omit = omit,
temperature: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> str: ...
def create(
self,
*,
file: FileTypes,
model: Union[str, AudioModel],
prompt: str | Omit = omit,
response_format: Union[Literal["json", "text", "srt", "verbose_json", "vtt"], Omit] = omit,
temperature: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Translation | TranslationVerbose | str:
"""
Translates audio into English.
Args:
file: The audio file object (not file name) translate, in one of these formats: flac,
mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
model: ID of the model to use. Only `whisper-1` (which is powered by our open source
Whisper V2 model) is currently available.
prompt: An optional text to guide the model's style or continue a previous audio
segment. The
[prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)
should be in English.
response_format: The format of the output, in one of these options: `json`, `text`, `srt`,
`verbose_json`, or `vtt`.
temperature: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
output more random, while lower values like 0.2 will make it more focused and
deterministic. If set to 0, the model will use
[log probability](https://en.wikipedia.org/wiki/Log_probability) to
automatically increase the temperature until certain thresholds are hit.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_with_paths(
{
"file": file,
"model": model,
"prompt": prompt,
"response_format": response_format,
"temperature": temperature,
},
[["file"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post( # type: ignore[return-value]
"/audio/translations",
body=maybe_transform(body, translation_create_params.TranslationCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=_get_response_format_type(response_format),
)
class AsyncTranslations(AsyncAPIResource):
"""Turn audio into text or text into audio."""
@cached_property
def with_raw_response(self) -> AsyncTranslationsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncTranslationsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncTranslationsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncTranslationsWithStreamingResponse(self)
@overload
async def create(
self,
*,
file: FileTypes,
model: Union[str, AudioModel],
response_format: Union[Literal["json"], Omit] = omit,
prompt: str | Omit = omit,
temperature: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Translation: ...
@overload
async def create(
self,
*,
file: FileTypes,
model: Union[str, AudioModel],
response_format: Literal["verbose_json"],
prompt: str | Omit = omit,
temperature: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> TranslationVerbose: ...
@overload
async def create(
self,
*,
file: FileTypes,
model: Union[str, AudioModel],
response_format: Literal["text", "srt", "vtt"],
prompt: str | Omit = omit,
temperature: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> str: ...
async def create(
self,
*,
file: FileTypes,
model: Union[str, AudioModel],
prompt: str | Omit = omit,
response_format: Union[AudioResponseFormat, Omit] = omit,
temperature: float | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Translation | TranslationVerbose | str:
"""
Translates audio into English.
Args:
file: The audio file object (not file name) translate, in one of these formats: flac,
mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
model: ID of the model to use. Only `whisper-1` (which is powered by our open source
Whisper V2 model) is currently available.
prompt: An optional text to guide the model's style or continue a previous audio
segment. The
[prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)
should be in English.
response_format: The format of the output, in one of these options: `json`, `text`, `srt`,
`verbose_json`, or `vtt`.
temperature: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
output more random, while lower values like 0.2 will make it more focused and
deterministic. If set to 0, the model will use
[log probability](https://en.wikipedia.org/wiki/Log_probability) to
automatically increase the temperature until certain thresholds are hit.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_with_paths(
{
"file": file,
"model": model,
"prompt": prompt,
"response_format": response_format,
"temperature": temperature,
},
[["file"]],
)
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
"/audio/translations",
body=await async_maybe_transform(body, translation_create_params.TranslationCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=_get_response_format_type(response_format),
)
class TranslationsWithRawResponse:
def __init__(self, translations: Translations) -> None:
self._translations = translations
self.create = _legacy_response.to_raw_response_wrapper(
translations.create,
)
class AsyncTranslationsWithRawResponse:
def __init__(self, translations: AsyncTranslations) -> None:
self._translations = translations
self.create = _legacy_response.async_to_raw_response_wrapper(
translations.create,
)
class TranslationsWithStreamingResponse:
def __init__(self, translations: Translations) -> None:
self._translations = translations
self.create = to_streamed_response_wrapper(
translations.create,
)
class AsyncTranslationsWithStreamingResponse:
def __init__(self, translations: AsyncTranslations) -> None:
self._translations = translations
self.create = async_to_streamed_response_wrapper(
translations.create,
)
def _get_response_format_type(
response_format: AudioResponseFormat | Omit,
) -> type[Translation | TranslationVerbose | str]:
if isinstance(response_format, Omit) or response_format is None: # pyright: ignore[reportUnnecessaryComparison]
return Translation
if response_format == "json":
return Translation
elif response_format == "verbose_json":
return TranslationVerbose
elif response_format == "srt" or response_format == "text" or response_format == "vtt":
return str
elif TYPE_CHECKING and response_format != "diarized_json": # type: ignore[unreachable]
assert_never(response_format)
else:
log.warning("Unexpected audio response format: %s", response_format)
return Translation

View File

@@ -0,0 +1,576 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Optional
from typing_extensions import Literal
import httpx
from .. import _legacy_response
from ..types import batch_list_params, batch_create_params
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from .._utils import path_template, maybe_transform, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ..pagination import SyncCursorPage, AsyncCursorPage
from ..types.batch import Batch
from .._base_client import AsyncPaginator, make_request_options
from ..types.shared_params.metadata import Metadata
__all__ = ["Batches", "AsyncBatches"]
class Batches(SyncAPIResource):
"""Create large batches of API requests to run asynchronously."""
@cached_property
def with_raw_response(self) -> BatchesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return BatchesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> BatchesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return BatchesWithStreamingResponse(self)
def create(
self,
*,
completion_window: Literal["24h"],
endpoint: Literal[
"/v1/responses",
"/v1/chat/completions",
"/v1/embeddings",
"/v1/completions",
"/v1/moderations",
"/v1/images/generations",
"/v1/images/edits",
"/v1/videos",
],
input_file_id: str,
metadata: Optional[Metadata] | Omit = omit,
output_expires_after: batch_create_params.OutputExpiresAfter | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Batch:
"""
Creates and executes a batch from an uploaded file of requests
Args:
completion_window: The time frame within which the batch should be processed. Currently only `24h`
is supported.
endpoint: The endpoint to be used for all requests in the batch. Currently
`/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`,
`/v1/moderations`, `/v1/images/generations`, `/v1/images/edits`, and
`/v1/videos` are supported. Note that `/v1/embeddings` batches are also
restricted to a maximum of 50,000 embedding inputs across all requests in the
batch.
input_file_id: The ID of an uploaded file that contains requests for the new batch.
See [upload file](https://platform.openai.com/docs/api-reference/files/create)
for how to upload a file.
Your input file must be formatted as a
[JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input),
and must be uploaded with the purpose `batch`. The file can contain up to 50,000
requests, and can be up to 200 MB in size.
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
for storing additional information about the object in a structured format, and
querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with
a maximum length of 512 characters.
output_expires_after: The expiration policy for the output and/or error file that are generated for a
batch.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/batches",
body=maybe_transform(
{
"completion_window": completion_window,
"endpoint": endpoint,
"input_file_id": input_file_id,
"metadata": metadata,
"output_expires_after": output_expires_after,
},
batch_create_params.BatchCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=Batch,
)
def retrieve(
self,
batch_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Batch:
"""
Retrieves a batch.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not batch_id:
raise ValueError(f"Expected a non-empty value for `batch_id` but received {batch_id!r}")
return self._get(
path_template("/batches/{batch_id}", batch_id=batch_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=Batch,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncCursorPage[Batch]:
"""List your organization's batches.
Args:
after: A cursor for use in pagination.
`after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/batches",
page=SyncCursorPage[Batch],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
batch_list_params.BatchListParams,
),
security={"bearer_auth": True},
),
model=Batch,
)
def cancel(
self,
batch_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Batch:
"""Cancels an in-progress batch.
The batch will be in status `cancelling` for up to
10 minutes, before changing to `cancelled`, where it will have partial results
(if any) available in the output file.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not batch_id:
raise ValueError(f"Expected a non-empty value for `batch_id` but received {batch_id!r}")
return self._post(
path_template("/batches/{batch_id}/cancel", batch_id=batch_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=Batch,
)
class AsyncBatches(AsyncAPIResource):
"""Create large batches of API requests to run asynchronously."""
@cached_property
def with_raw_response(self) -> AsyncBatchesWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncBatchesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncBatchesWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncBatchesWithStreamingResponse(self)
async def create(
self,
*,
completion_window: Literal["24h"],
endpoint: Literal[
"/v1/responses",
"/v1/chat/completions",
"/v1/embeddings",
"/v1/completions",
"/v1/moderations",
"/v1/images/generations",
"/v1/images/edits",
"/v1/videos",
],
input_file_id: str,
metadata: Optional[Metadata] | Omit = omit,
output_expires_after: batch_create_params.OutputExpiresAfter | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Batch:
"""
Creates and executes a batch from an uploaded file of requests
Args:
completion_window: The time frame within which the batch should be processed. Currently only `24h`
is supported.
endpoint: The endpoint to be used for all requests in the batch. Currently
`/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`,
`/v1/moderations`, `/v1/images/generations`, `/v1/images/edits`, and
`/v1/videos` are supported. Note that `/v1/embeddings` batches are also
restricted to a maximum of 50,000 embedding inputs across all requests in the
batch.
input_file_id: The ID of an uploaded file that contains requests for the new batch.
See [upload file](https://platform.openai.com/docs/api-reference/files/create)
for how to upload a file.
Your input file must be formatted as a
[JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input),
and must be uploaded with the purpose `batch`. The file can contain up to 50,000
requests, and can be up to 200 MB in size.
metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
for storing additional information about the object in a structured format, and
querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with
a maximum length of 512 characters.
output_expires_after: The expiration policy for the output and/or error file that are generated for a
batch.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/batches",
body=await async_maybe_transform(
{
"completion_window": completion_window,
"endpoint": endpoint,
"input_file_id": input_file_id,
"metadata": metadata,
"output_expires_after": output_expires_after,
},
batch_create_params.BatchCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=Batch,
)
async def retrieve(
self,
batch_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Batch:
"""
Retrieves a batch.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not batch_id:
raise ValueError(f"Expected a non-empty value for `batch_id` but received {batch_id!r}")
return await self._get(
path_template("/batches/{batch_id}", batch_id=batch_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=Batch,
)
def list(
self,
*,
after: str | Omit = omit,
limit: int | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[Batch, AsyncCursorPage[Batch]]:
"""List your organization's batches.
Args:
after: A cursor for use in pagination.
`after` is an object ID that defines your place
in the list. For instance, if you make a list request and receive 100 objects,
ending with obj_foo, your subsequent call can include after=obj_foo in order to
fetch the next page of the list.
limit: A limit on the number of objects to be returned. Limit can range between 1 and
100, and the default is 20.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/batches",
page=AsyncCursorPage[Batch],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"limit": limit,
},
batch_list_params.BatchListParams,
),
security={"bearer_auth": True},
),
model=Batch,
)
async def cancel(
self,
batch_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Batch:
"""Cancels an in-progress batch.
The batch will be in status `cancelling` for up to
10 minutes, before changing to `cancelled`, where it will have partial results
(if any) available in the output file.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not batch_id:
raise ValueError(f"Expected a non-empty value for `batch_id` but received {batch_id!r}")
return await self._post(
path_template("/batches/{batch_id}/cancel", batch_id=batch_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=Batch,
)
class BatchesWithRawResponse:
def __init__(self, batches: Batches) -> None:
self._batches = batches
self.create = _legacy_response.to_raw_response_wrapper(
batches.create,
)
self.retrieve = _legacy_response.to_raw_response_wrapper(
batches.retrieve,
)
self.list = _legacy_response.to_raw_response_wrapper(
batches.list,
)
self.cancel = _legacy_response.to_raw_response_wrapper(
batches.cancel,
)
class AsyncBatchesWithRawResponse:
def __init__(self, batches: AsyncBatches) -> None:
self._batches = batches
self.create = _legacy_response.async_to_raw_response_wrapper(
batches.create,
)
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
batches.retrieve,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
batches.list,
)
self.cancel = _legacy_response.async_to_raw_response_wrapper(
batches.cancel,
)
class BatchesWithStreamingResponse:
def __init__(self, batches: Batches) -> None:
self._batches = batches
self.create = to_streamed_response_wrapper(
batches.create,
)
self.retrieve = to_streamed_response_wrapper(
batches.retrieve,
)
self.list = to_streamed_response_wrapper(
batches.list,
)
self.cancel = to_streamed_response_wrapper(
batches.cancel,
)
class AsyncBatchesWithStreamingResponse:
def __init__(self, batches: AsyncBatches) -> None:
self._batches = batches
self.create = async_to_streamed_response_wrapper(
batches.create,
)
self.retrieve = async_to_streamed_response_wrapper(
batches.retrieve,
)
self.list = async_to_streamed_response_wrapper(
batches.list,
)
self.cancel = async_to_streamed_response_wrapper(
batches.cancel,
)

View File

@@ -0,0 +1,61 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .beta import (
Beta,
AsyncBeta,
BetaWithRawResponse,
AsyncBetaWithRawResponse,
BetaWithStreamingResponse,
AsyncBetaWithStreamingResponse,
)
from .chatkit import (
ChatKit,
AsyncChatKit,
ChatKitWithRawResponse,
AsyncChatKitWithRawResponse,
ChatKitWithStreamingResponse,
AsyncChatKitWithStreamingResponse,
)
from .threads import (
Threads,
AsyncThreads,
ThreadsWithRawResponse,
AsyncThreadsWithRawResponse,
ThreadsWithStreamingResponse,
AsyncThreadsWithStreamingResponse,
)
from .assistants import (
Assistants,
AsyncAssistants,
AssistantsWithRawResponse,
AsyncAssistantsWithRawResponse,
AssistantsWithStreamingResponse,
AsyncAssistantsWithStreamingResponse,
)
__all__ = [
"ChatKit",
"AsyncChatKit",
"ChatKitWithRawResponse",
"AsyncChatKitWithRawResponse",
"ChatKitWithStreamingResponse",
"AsyncChatKitWithStreamingResponse",
"Assistants",
"AsyncAssistants",
"AssistantsWithRawResponse",
"AsyncAssistantsWithRawResponse",
"AssistantsWithStreamingResponse",
"AsyncAssistantsWithStreamingResponse",
"Threads",
"AsyncThreads",
"ThreadsWithRawResponse",
"AsyncThreadsWithRawResponse",
"ThreadsWithStreamingResponse",
"AsyncThreadsWithStreamingResponse",
"Beta",
"AsyncBeta",
"BetaWithRawResponse",
"AsyncBetaWithRawResponse",
"BetaWithStreamingResponse",
"AsyncBetaWithStreamingResponse",
]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,199 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from ..._compat import cached_property
from .assistants import (
Assistants,
AsyncAssistants,
AssistantsWithRawResponse,
AsyncAssistantsWithRawResponse,
AssistantsWithStreamingResponse,
AsyncAssistantsWithStreamingResponse,
)
from ..._resource import SyncAPIResource, AsyncAPIResource
from .chatkit.chatkit import (
ChatKit,
AsyncChatKit,
ChatKitWithRawResponse,
AsyncChatKitWithRawResponse,
ChatKitWithStreamingResponse,
AsyncChatKitWithStreamingResponse,
)
from .threads.threads import (
Threads,
AsyncThreads,
ThreadsWithRawResponse,
AsyncThreadsWithRawResponse,
ThreadsWithStreamingResponse,
AsyncThreadsWithStreamingResponse,
)
from ...resources.chat import Chat, AsyncChat
from .realtime.realtime import (
Realtime,
AsyncRealtime,
)
__all__ = ["Beta", "AsyncBeta"]
class Beta(SyncAPIResource):
@cached_property
def chat(self) -> Chat:
return Chat(self._client)
@cached_property
def realtime(self) -> Realtime:
return Realtime(self._client)
@cached_property
def chatkit(self) -> ChatKit:
return ChatKit(self._client)
@cached_property
def assistants(self) -> Assistants:
"""Build Assistants that can call models and use tools."""
return Assistants(self._client)
@cached_property
def threads(self) -> Threads:
"""Build Assistants that can call models and use tools."""
return Threads(self._client)
@cached_property
def with_raw_response(self) -> BetaWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return BetaWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> BetaWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return BetaWithStreamingResponse(self)
class AsyncBeta(AsyncAPIResource):
@cached_property
def chat(self) -> AsyncChat:
return AsyncChat(self._client)
@cached_property
def realtime(self) -> AsyncRealtime:
return AsyncRealtime(self._client)
@cached_property
def chatkit(self) -> AsyncChatKit:
return AsyncChatKit(self._client)
@cached_property
def assistants(self) -> AsyncAssistants:
"""Build Assistants that can call models and use tools."""
return AsyncAssistants(self._client)
@cached_property
def threads(self) -> AsyncThreads:
"""Build Assistants that can call models and use tools."""
return AsyncThreads(self._client)
@cached_property
def with_raw_response(self) -> AsyncBetaWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncBetaWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncBetaWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncBetaWithStreamingResponse(self)
class BetaWithRawResponse:
def __init__(self, beta: Beta) -> None:
self._beta = beta
@cached_property
def chatkit(self) -> ChatKitWithRawResponse:
return ChatKitWithRawResponse(self._beta.chatkit)
@cached_property
def assistants(self) -> AssistantsWithRawResponse:
"""Build Assistants that can call models and use tools."""
return AssistantsWithRawResponse(self._beta.assistants)
@cached_property
def threads(self) -> ThreadsWithRawResponse:
"""Build Assistants that can call models and use tools."""
return ThreadsWithRawResponse(self._beta.threads)
class AsyncBetaWithRawResponse:
def __init__(self, beta: AsyncBeta) -> None:
self._beta = beta
@cached_property
def chatkit(self) -> AsyncChatKitWithRawResponse:
return AsyncChatKitWithRawResponse(self._beta.chatkit)
@cached_property
def assistants(self) -> AsyncAssistantsWithRawResponse:
"""Build Assistants that can call models and use tools."""
return AsyncAssistantsWithRawResponse(self._beta.assistants)
@cached_property
def threads(self) -> AsyncThreadsWithRawResponse:
"""Build Assistants that can call models and use tools."""
return AsyncThreadsWithRawResponse(self._beta.threads)
class BetaWithStreamingResponse:
def __init__(self, beta: Beta) -> None:
self._beta = beta
@cached_property
def chatkit(self) -> ChatKitWithStreamingResponse:
return ChatKitWithStreamingResponse(self._beta.chatkit)
@cached_property
def assistants(self) -> AssistantsWithStreamingResponse:
"""Build Assistants that can call models and use tools."""
return AssistantsWithStreamingResponse(self._beta.assistants)
@cached_property
def threads(self) -> ThreadsWithStreamingResponse:
"""Build Assistants that can call models and use tools."""
return ThreadsWithStreamingResponse(self._beta.threads)
class AsyncBetaWithStreamingResponse:
def __init__(self, beta: AsyncBeta) -> None:
self._beta = beta
@cached_property
def chatkit(self) -> AsyncChatKitWithStreamingResponse:
return AsyncChatKitWithStreamingResponse(self._beta.chatkit)
@cached_property
def assistants(self) -> AsyncAssistantsWithStreamingResponse:
"""Build Assistants that can call models and use tools."""
return AsyncAssistantsWithStreamingResponse(self._beta.assistants)
@cached_property
def threads(self) -> AsyncThreadsWithStreamingResponse:
"""Build Assistants that can call models and use tools."""
return AsyncThreadsWithStreamingResponse(self._beta.threads)

View File

@@ -0,0 +1,47 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .chatkit import (
ChatKit,
AsyncChatKit,
ChatKitWithRawResponse,
AsyncChatKitWithRawResponse,
ChatKitWithStreamingResponse,
AsyncChatKitWithStreamingResponse,
)
from .threads import (
Threads,
AsyncThreads,
ThreadsWithRawResponse,
AsyncThreadsWithRawResponse,
ThreadsWithStreamingResponse,
AsyncThreadsWithStreamingResponse,
)
from .sessions import (
Sessions,
AsyncSessions,
SessionsWithRawResponse,
AsyncSessionsWithRawResponse,
SessionsWithStreamingResponse,
AsyncSessionsWithStreamingResponse,
)
__all__ = [
"Sessions",
"AsyncSessions",
"SessionsWithRawResponse",
"AsyncSessionsWithRawResponse",
"SessionsWithStreamingResponse",
"AsyncSessionsWithStreamingResponse",
"Threads",
"AsyncThreads",
"ThreadsWithRawResponse",
"AsyncThreadsWithRawResponse",
"ThreadsWithStreamingResponse",
"AsyncThreadsWithStreamingResponse",
"ChatKit",
"AsyncChatKit",
"ChatKitWithRawResponse",
"AsyncChatKitWithRawResponse",
"ChatKitWithStreamingResponse",
"AsyncChatKitWithStreamingResponse",
]

View File

@@ -0,0 +1,134 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from .threads import (
Threads,
AsyncThreads,
ThreadsWithRawResponse,
AsyncThreadsWithRawResponse,
ThreadsWithStreamingResponse,
AsyncThreadsWithStreamingResponse,
)
from .sessions import (
Sessions,
AsyncSessions,
SessionsWithRawResponse,
AsyncSessionsWithRawResponse,
SessionsWithStreamingResponse,
AsyncSessionsWithStreamingResponse,
)
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
__all__ = ["ChatKit", "AsyncChatKit"]
class ChatKit(SyncAPIResource):
@cached_property
def sessions(self) -> Sessions:
return Sessions(self._client)
@cached_property
def threads(self) -> Threads:
return Threads(self._client)
@cached_property
def with_raw_response(self) -> ChatKitWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return ChatKitWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> ChatKitWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return ChatKitWithStreamingResponse(self)
class AsyncChatKit(AsyncAPIResource):
@cached_property
def sessions(self) -> AsyncSessions:
return AsyncSessions(self._client)
@cached_property
def threads(self) -> AsyncThreads:
return AsyncThreads(self._client)
@cached_property
def with_raw_response(self) -> AsyncChatKitWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncChatKitWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncChatKitWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncChatKitWithStreamingResponse(self)
class ChatKitWithRawResponse:
def __init__(self, chatkit: ChatKit) -> None:
self._chatkit = chatkit
@cached_property
def sessions(self) -> SessionsWithRawResponse:
return SessionsWithRawResponse(self._chatkit.sessions)
@cached_property
def threads(self) -> ThreadsWithRawResponse:
return ThreadsWithRawResponse(self._chatkit.threads)
class AsyncChatKitWithRawResponse:
def __init__(self, chatkit: AsyncChatKit) -> None:
self._chatkit = chatkit
@cached_property
def sessions(self) -> AsyncSessionsWithRawResponse:
return AsyncSessionsWithRawResponse(self._chatkit.sessions)
@cached_property
def threads(self) -> AsyncThreadsWithRawResponse:
return AsyncThreadsWithRawResponse(self._chatkit.threads)
class ChatKitWithStreamingResponse:
def __init__(self, chatkit: ChatKit) -> None:
self._chatkit = chatkit
@cached_property
def sessions(self) -> SessionsWithStreamingResponse:
return SessionsWithStreamingResponse(self._chatkit.sessions)
@cached_property
def threads(self) -> ThreadsWithStreamingResponse:
return ThreadsWithStreamingResponse(self._chatkit.threads)
class AsyncChatKitWithStreamingResponse:
def __init__(self, chatkit: AsyncChatKit) -> None:
self._chatkit = chatkit
@cached_property
def sessions(self) -> AsyncSessionsWithStreamingResponse:
return AsyncSessionsWithStreamingResponse(self._chatkit.sessions)
@cached_property
def threads(self) -> AsyncThreadsWithStreamingResponse:
return AsyncThreadsWithStreamingResponse(self._chatkit.threads)

View File

@@ -0,0 +1,321 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
import httpx
from .... import _legacy_response
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ...._utils import path_template, maybe_transform, async_maybe_transform
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ...._base_client import make_request_options
from ....types.beta.chatkit import (
ChatSessionWorkflowParam,
ChatSessionRateLimitsParam,
ChatSessionExpiresAfterParam,
ChatSessionChatKitConfigurationParam,
session_create_params,
)
from ....types.beta.chatkit.chat_session import ChatSession
from ....types.beta.chatkit.chat_session_workflow_param import ChatSessionWorkflowParam
from ....types.beta.chatkit.chat_session_rate_limits_param import ChatSessionRateLimitsParam
from ....types.beta.chatkit.chat_session_expires_after_param import ChatSessionExpiresAfterParam
from ....types.beta.chatkit.chat_session_chatkit_configuration_param import ChatSessionChatKitConfigurationParam
__all__ = ["Sessions", "AsyncSessions"]
class Sessions(SyncAPIResource):
@cached_property
def with_raw_response(self) -> SessionsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return SessionsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> SessionsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return SessionsWithStreamingResponse(self)
def create(
self,
*,
user: str,
workflow: ChatSessionWorkflowParam,
chatkit_configuration: ChatSessionChatKitConfigurationParam | Omit = omit,
expires_after: ChatSessionExpiresAfterParam | Omit = omit,
rate_limits: ChatSessionRateLimitsParam | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ChatSession:
"""
Create a ChatKit session.
Args:
user: A free-form string that identifies your end user; ensures this Session can
access other objects that have the same `user` scope.
workflow: Workflow that powers the session.
chatkit_configuration: Optional overrides for ChatKit runtime configuration features
expires_after: Optional override for session expiration timing in seconds from creation.
Defaults to 10 minutes.
rate_limits: Optional override for per-minute request limits. When omitted, defaults to 10.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return self._post(
"/chatkit/sessions",
body=maybe_transform(
{
"user": user,
"workflow": workflow,
"chatkit_configuration": chatkit_configuration,
"expires_after": expires_after,
"rate_limits": rate_limits,
},
session_create_params.SessionCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=ChatSession,
)
def cancel(
self,
session_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ChatSession:
"""
Cancel an active ChatKit session and return its most recent metadata.
Cancelling prevents new requests from using the issued client secret.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not session_id:
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return self._post(
path_template("/chatkit/sessions/{session_id}/cancel", session_id=session_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=ChatSession,
)
class AsyncSessions(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncSessionsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncSessionsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncSessionsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncSessionsWithStreamingResponse(self)
async def create(
self,
*,
user: str,
workflow: ChatSessionWorkflowParam,
chatkit_configuration: ChatSessionChatKitConfigurationParam | Omit = omit,
expires_after: ChatSessionExpiresAfterParam | Omit = omit,
rate_limits: ChatSessionRateLimitsParam | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ChatSession:
"""
Create a ChatKit session.
Args:
user: A free-form string that identifies your end user; ensures this Session can
access other objects that have the same `user` scope.
workflow: Workflow that powers the session.
chatkit_configuration: Optional overrides for ChatKit runtime configuration features
expires_after: Optional override for session expiration timing in seconds from creation.
Defaults to 10 minutes.
rate_limits: Optional override for per-minute request limits. When omitted, defaults to 10.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return await self._post(
"/chatkit/sessions",
body=await async_maybe_transform(
{
"user": user,
"workflow": workflow,
"chatkit_configuration": chatkit_configuration,
"expires_after": expires_after,
"rate_limits": rate_limits,
},
session_create_params.SessionCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=ChatSession,
)
async def cancel(
self,
session_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ChatSession:
"""
Cancel an active ChatKit session and return its most recent metadata.
Cancelling prevents new requests from using the issued client secret.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not session_id:
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return await self._post(
path_template("/chatkit/sessions/{session_id}/cancel", session_id=session_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=ChatSession,
)
class SessionsWithRawResponse:
def __init__(self, sessions: Sessions) -> None:
self._sessions = sessions
self.create = _legacy_response.to_raw_response_wrapper(
sessions.create,
)
self.cancel = _legacy_response.to_raw_response_wrapper(
sessions.cancel,
)
class AsyncSessionsWithRawResponse:
def __init__(self, sessions: AsyncSessions) -> None:
self._sessions = sessions
self.create = _legacy_response.async_to_raw_response_wrapper(
sessions.create,
)
self.cancel = _legacy_response.async_to_raw_response_wrapper(
sessions.cancel,
)
class SessionsWithStreamingResponse:
def __init__(self, sessions: Sessions) -> None:
self._sessions = sessions
self.create = to_streamed_response_wrapper(
sessions.create,
)
self.cancel = to_streamed_response_wrapper(
sessions.cancel,
)
class AsyncSessionsWithStreamingResponse:
def __init__(self, sessions: AsyncSessions) -> None:
self._sessions = sessions
self.create = async_to_streamed_response_wrapper(
sessions.create,
)
self.cancel = async_to_streamed_response_wrapper(
sessions.cancel,
)

View File

@@ -0,0 +1,541 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Any, cast
from typing_extensions import Literal
import httpx
from .... import _legacy_response
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ...._utils import path_template, maybe_transform
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ....pagination import SyncConversationCursorPage, AsyncConversationCursorPage
from ...._base_client import AsyncPaginator, make_request_options
from ....types.beta.chatkit import thread_list_params, thread_list_items_params
from ....types.beta.chatkit.chatkit_thread import ChatKitThread
from ....types.beta.chatkit.thread_delete_response import ThreadDeleteResponse
from ....types.beta.chatkit.chatkit_thread_item_list import Data
__all__ = ["Threads", "AsyncThreads"]
class Threads(SyncAPIResource):
@cached_property
def with_raw_response(self) -> ThreadsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return ThreadsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> ThreadsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return ThreadsWithStreamingResponse(self)
def retrieve(
self,
thread_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ChatKitThread:
"""
Retrieve a ChatKit thread by its identifier.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not thread_id:
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return self._get(
path_template("/chatkit/threads/{thread_id}", thread_id=thread_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=ChatKitThread,
)
def list(
self,
*,
after: str | Omit = omit,
before: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
user: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[ChatKitThread]:
"""
List ChatKit threads with optional pagination and user filters.
Args:
after: List items created after this thread item ID. Defaults to null for the first
page.
before: List items created before this thread item ID. Defaults to null for the newest
results.
limit: Maximum number of thread items to return. Defaults to 20.
order: Sort order for results by creation time. Defaults to `desc`.
user: Filter threads that belong to this user identifier. Defaults to null to return
all users.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return self._get_api_list(
"/chatkit/threads",
page=SyncConversationCursorPage[ChatKitThread],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"before": before,
"limit": limit,
"order": order,
"user": user,
},
thread_list_params.ThreadListParams,
),
security={"bearer_auth": True},
),
model=ChatKitThread,
)
def delete(
self,
thread_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ThreadDeleteResponse:
"""
Delete a ChatKit thread along with its items and stored attachments.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not thread_id:
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return self._delete(
path_template("/chatkit/threads/{thread_id}", thread_id=thread_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=ThreadDeleteResponse,
)
def list_items(
self,
thread_id: str,
*,
after: str | Omit = omit,
before: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncConversationCursorPage[Data]:
"""
List items that belong to a ChatKit thread.
Args:
after: List items created after this thread item ID. Defaults to null for the first
page.
before: List items created before this thread item ID. Defaults to null for the newest
results.
limit: Maximum number of thread items to return. Defaults to 20.
order: Sort order for results by creation time. Defaults to `desc`.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not thread_id:
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return self._get_api_list(
path_template("/chatkit/threads/{thread_id}/items", thread_id=thread_id),
page=SyncConversationCursorPage[Data],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"before": before,
"limit": limit,
"order": order,
},
thread_list_items_params.ThreadListItemsParams,
),
security={"bearer_auth": True},
),
model=cast(Any, Data), # Union types cannot be passed in as arguments in the type system
)
class AsyncThreads(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncThreadsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
"""
return AsyncThreadsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncThreadsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
"""
return AsyncThreadsWithStreamingResponse(self)
async def retrieve(
self,
thread_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ChatKitThread:
"""
Retrieve a ChatKit thread by its identifier.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not thread_id:
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return await self._get(
path_template("/chatkit/threads/{thread_id}", thread_id=thread_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=ChatKitThread,
)
def list(
self,
*,
after: str | Omit = omit,
before: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
user: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[ChatKitThread, AsyncConversationCursorPage[ChatKitThread]]:
"""
List ChatKit threads with optional pagination and user filters.
Args:
after: List items created after this thread item ID. Defaults to null for the first
page.
before: List items created before this thread item ID. Defaults to null for the newest
results.
limit: Maximum number of thread items to return. Defaults to 20.
order: Sort order for results by creation time. Defaults to `desc`.
user: Filter threads that belong to this user identifier. Defaults to null to return
all users.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return self._get_api_list(
"/chatkit/threads",
page=AsyncConversationCursorPage[ChatKitThread],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"before": before,
"limit": limit,
"order": order,
"user": user,
},
thread_list_params.ThreadListParams,
),
security={"bearer_auth": True},
),
model=ChatKitThread,
)
async def delete(
self,
thread_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ThreadDeleteResponse:
"""
Delete a ChatKit thread along with its items and stored attachments.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not thread_id:
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return await self._delete(
path_template("/chatkit/threads/{thread_id}", thread_id=thread_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=ThreadDeleteResponse,
)
def list_items(
self,
thread_id: str,
*,
after: str | Omit = omit,
before: str | Omit = omit,
limit: int | Omit = omit,
order: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[Data, AsyncConversationCursorPage[Data]]:
"""
List items that belong to a ChatKit thread.
Args:
after: List items created after this thread item ID. Defaults to null for the first
page.
before: List items created before this thread item ID. Defaults to null for the newest
results.
limit: Maximum number of thread items to return. Defaults to 20.
order: Sort order for results by creation time. Defaults to `desc`.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not thread_id:
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
extra_headers = {"OpenAI-Beta": "chatkit_beta=v1", **(extra_headers or {})}
return self._get_api_list(
path_template("/chatkit/threads/{thread_id}/items", thread_id=thread_id),
page=AsyncConversationCursorPage[Data],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"after": after,
"before": before,
"limit": limit,
"order": order,
},
thread_list_items_params.ThreadListItemsParams,
),
security={"bearer_auth": True},
),
model=cast(Any, Data), # Union types cannot be passed in as arguments in the type system
)
class ThreadsWithRawResponse:
def __init__(self, threads: Threads) -> None:
self._threads = threads
self.retrieve = _legacy_response.to_raw_response_wrapper(
threads.retrieve,
)
self.list = _legacy_response.to_raw_response_wrapper(
threads.list,
)
self.delete = _legacy_response.to_raw_response_wrapper(
threads.delete,
)
self.list_items = _legacy_response.to_raw_response_wrapper(
threads.list_items,
)
class AsyncThreadsWithRawResponse:
def __init__(self, threads: AsyncThreads) -> None:
self._threads = threads
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
threads.retrieve,
)
self.list = _legacy_response.async_to_raw_response_wrapper(
threads.list,
)
self.delete = _legacy_response.async_to_raw_response_wrapper(
threads.delete,
)
self.list_items = _legacy_response.async_to_raw_response_wrapper(
threads.list_items,
)
class ThreadsWithStreamingResponse:
def __init__(self, threads: Threads) -> None:
self._threads = threads
self.retrieve = to_streamed_response_wrapper(
threads.retrieve,
)
self.list = to_streamed_response_wrapper(
threads.list,
)
self.delete = to_streamed_response_wrapper(
threads.delete,
)
self.list_items = to_streamed_response_wrapper(
threads.list_items,
)
class AsyncThreadsWithStreamingResponse:
def __init__(self, threads: AsyncThreads) -> None:
self._threads = threads
self.retrieve = async_to_streamed_response_wrapper(
threads.retrieve,
)
self.list = async_to_streamed_response_wrapper(
threads.list,
)
self.delete = async_to_streamed_response_wrapper(
threads.delete,
)
self.list_items = async_to_streamed_response_wrapper(
threads.list_items,
)

View File

@@ -0,0 +1,47 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from .realtime import (
Realtime,
AsyncRealtime,
RealtimeWithRawResponse,
AsyncRealtimeWithRawResponse,
RealtimeWithStreamingResponse,
AsyncRealtimeWithStreamingResponse,
)
from .sessions import (
Sessions,
AsyncSessions,
SessionsWithRawResponse,
AsyncSessionsWithRawResponse,
SessionsWithStreamingResponse,
AsyncSessionsWithStreamingResponse,
)
from .transcription_sessions import (
TranscriptionSessions,
AsyncTranscriptionSessions,
TranscriptionSessionsWithRawResponse,
AsyncTranscriptionSessionsWithRawResponse,
TranscriptionSessionsWithStreamingResponse,
AsyncTranscriptionSessionsWithStreamingResponse,
)
__all__ = [
"Sessions",
"AsyncSessions",
"SessionsWithRawResponse",
"AsyncSessionsWithRawResponse",
"SessionsWithStreamingResponse",
"AsyncSessionsWithStreamingResponse",
"TranscriptionSessions",
"AsyncTranscriptionSessions",
"TranscriptionSessionsWithRawResponse",
"AsyncTranscriptionSessionsWithRawResponse",
"TranscriptionSessionsWithStreamingResponse",
"AsyncTranscriptionSessionsWithStreamingResponse",
"Realtime",
"AsyncRealtime",
"RealtimeWithRawResponse",
"AsyncRealtimeWithRawResponse",
"RealtimeWithStreamingResponse",
"AsyncRealtimeWithStreamingResponse",
]

Some files were not shown because too many files have changed in this diff Show More