# This file was auto-generated by Fern from our API Definition. import typing from ..core.client_wrapper import SyncClientWrapper from ..core.request_options import RequestOptions from ..types.list_embed_job_response import ListEmbedJobResponse from ..core.unchecked_base_model import construct_type from ..errors.bad_request_error import BadRequestError from ..errors.unauthorized_error import UnauthorizedError from ..errors.forbidden_error import ForbiddenError from ..errors.not_found_error import NotFoundError from ..errors.unprocessable_entity_error import UnprocessableEntityError from ..errors.too_many_requests_error import TooManyRequestsError from ..errors.invalid_token_error import InvalidTokenError from ..errors.client_closed_request_error import ClientClosedRequestError from ..errors.internal_server_error import InternalServerError from ..errors.not_implemented_error import NotImplementedError from ..errors.service_unavailable_error import ServiceUnavailableError from ..errors.gateway_timeout_error import GatewayTimeoutError from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..types.embed_input_type import EmbedInputType from ..types.embedding_type import EmbeddingType from .types.create_embed_job_request_truncate import CreateEmbedJobRequestTruncate from ..types.create_embed_job_response import CreateEmbedJobResponse from ..types.embed_job import EmbedJob from ..core.jsonable_encoder import jsonable_encoder from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) class EmbedJobsClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._client_wrapper = client_wrapper def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> ListEmbedJobResponse: """ The list embed job endpoint allows users to view all embed jobs history for that specific user. Parameters ---------- request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- ListEmbedJobResponse OK Examples -------- from cohere import Client client = Client( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) client.embed_jobs.list() """ _response = self._client_wrapper.httpx_client.request( "v1/embed-jobs", method="GET", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return typing.cast( ListEmbedJobResponse, construct_type( type_=ListEmbedJobResponse, # type: ignore object_=_response.json(), ), ) if _response.status_code == 400: raise BadRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 401: raise UnauthorizedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 403: raise ForbiddenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 404: raise NotFoundError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 422: raise UnprocessableEntityError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 429: raise TooManyRequestsError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 498: raise InvalidTokenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 499: raise ClientClosedRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 500: raise InternalServerError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 501: raise NotImplementedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 503: raise ServiceUnavailableError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 504: raise GatewayTimeoutError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) def create( self, *, model: str, dataset_id: str, input_type: EmbedInputType, name: typing.Optional[str] = OMIT, embedding_types: typing.Optional[typing.Sequence[EmbeddingType]] = OMIT, truncate: typing.Optional[CreateEmbedJobRequestTruncate] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> CreateEmbedJobResponse: """ This API launches an async Embed job for a [Dataset](https://docs.cohere.com/docs/datasets) of type `embed-input`. The result of a completed embed job is new Dataset of type `embed-output`, which contains the original text entries and the corresponding embeddings. Parameters ---------- model : str ID of the embedding model. Available models and corresponding embedding dimensions: - `embed-english-v3.0` : 1024 - `embed-multilingual-v3.0` : 1024 - `embed-english-light-v3.0` : 384 - `embed-multilingual-light-v3.0` : 384 dataset_id : str ID of a [Dataset](https://docs.cohere.com/docs/datasets). The Dataset must be of type `embed-input` and must have a validation status `Validated` input_type : EmbedInputType name : typing.Optional[str] The name of the embed job. embedding_types : typing.Optional[typing.Sequence[EmbeddingType]] Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types. * `"float"`: Use this when you want to get back the default float embeddings. Valid for all models. * `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models. * `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models. * `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models. * `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models. truncate : typing.Optional[CreateEmbedJobRequestTruncate] One of `START|END` to specify how the API will handle inputs longer than the maximum token length. Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- CreateEmbedJobResponse OK Examples -------- from cohere import Client client = Client( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) client.embed_jobs.create( model="model", dataset_id="dataset_id", input_type="search_document", ) """ _response = self._client_wrapper.httpx_client.request( "v1/embed-jobs", method="POST", json={ "model": model, "dataset_id": dataset_id, "input_type": input_type, "name": name, "embedding_types": embedding_types, "truncate": truncate, }, headers={ "content-type": "application/json", }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: return typing.cast( CreateEmbedJobResponse, construct_type( type_=CreateEmbedJobResponse, # type: ignore object_=_response.json(), ), ) if _response.status_code == 400: raise BadRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 401: raise UnauthorizedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 403: raise ForbiddenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 404: raise NotFoundError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 422: raise UnprocessableEntityError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 429: raise TooManyRequestsError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 498: raise InvalidTokenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 499: raise ClientClosedRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 500: raise InternalServerError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 501: raise NotImplementedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 503: raise ServiceUnavailableError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 504: raise GatewayTimeoutError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EmbedJob: """ This API retrieves the details about an embed job started by the same user. Parameters ---------- id : str The ID of the embed job to retrieve. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- EmbedJob OK Examples -------- from cohere import Client client = Client( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) client.embed_jobs.get( id="id", ) """ _response = self._client_wrapper.httpx_client.request( f"v1/embed-jobs/{jsonable_encoder(id)}", method="GET", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return typing.cast( EmbedJob, construct_type( type_=EmbedJob, # type: ignore object_=_response.json(), ), ) if _response.status_code == 400: raise BadRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 401: raise UnauthorizedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 403: raise ForbiddenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 404: raise NotFoundError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 422: raise UnprocessableEntityError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 429: raise TooManyRequestsError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 498: raise InvalidTokenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 499: raise ClientClosedRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 500: raise InternalServerError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 501: raise NotImplementedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 503: raise ServiceUnavailableError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 504: raise GatewayTimeoutError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) def cancel(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None: """ This API allows users to cancel an active embed job. Once invoked, the embedding process will be terminated, and users will be charged for the embeddings processed up to the cancellation point. It's important to note that partial results will not be available to users after cancellation. Parameters ---------- id : str The ID of the embed job to cancel. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- None Examples -------- from cohere import Client client = Client( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) client.embed_jobs.cancel( id="id", ) """ _response = self._client_wrapper.httpx_client.request( f"v1/embed-jobs/{jsonable_encoder(id)}/cancel", method="POST", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return if _response.status_code == 400: raise BadRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 401: raise UnauthorizedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 403: raise ForbiddenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 404: raise NotFoundError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 422: raise UnprocessableEntityError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 429: raise TooManyRequestsError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 498: raise InvalidTokenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 499: raise ClientClosedRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 500: raise InternalServerError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 501: raise NotImplementedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 503: raise ServiceUnavailableError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 504: raise GatewayTimeoutError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) class AsyncEmbedJobsClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._client_wrapper = client_wrapper async def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> ListEmbedJobResponse: """ The list embed job endpoint allows users to view all embed jobs history for that specific user. Parameters ---------- request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- ListEmbedJobResponse OK Examples -------- import asyncio from cohere import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) async def main() -> None: await client.embed_jobs.list() asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( "v1/embed-jobs", method="GET", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return typing.cast( ListEmbedJobResponse, construct_type( type_=ListEmbedJobResponse, # type: ignore object_=_response.json(), ), ) if _response.status_code == 400: raise BadRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 401: raise UnauthorizedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 403: raise ForbiddenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 404: raise NotFoundError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 422: raise UnprocessableEntityError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 429: raise TooManyRequestsError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 498: raise InvalidTokenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 499: raise ClientClosedRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 500: raise InternalServerError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 501: raise NotImplementedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 503: raise ServiceUnavailableError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 504: raise GatewayTimeoutError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) async def create( self, *, model: str, dataset_id: str, input_type: EmbedInputType, name: typing.Optional[str] = OMIT, embedding_types: typing.Optional[typing.Sequence[EmbeddingType]] = OMIT, truncate: typing.Optional[CreateEmbedJobRequestTruncate] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> CreateEmbedJobResponse: """ This API launches an async Embed job for a [Dataset](https://docs.cohere.com/docs/datasets) of type `embed-input`. The result of a completed embed job is new Dataset of type `embed-output`, which contains the original text entries and the corresponding embeddings. Parameters ---------- model : str ID of the embedding model. Available models and corresponding embedding dimensions: - `embed-english-v3.0` : 1024 - `embed-multilingual-v3.0` : 1024 - `embed-english-light-v3.0` : 384 - `embed-multilingual-light-v3.0` : 384 dataset_id : str ID of a [Dataset](https://docs.cohere.com/docs/datasets). The Dataset must be of type `embed-input` and must have a validation status `Validated` input_type : EmbedInputType name : typing.Optional[str] The name of the embed job. embedding_types : typing.Optional[typing.Sequence[EmbeddingType]] Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types. * `"float"`: Use this when you want to get back the default float embeddings. Valid for all models. * `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models. * `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models. * `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models. * `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models. truncate : typing.Optional[CreateEmbedJobRequestTruncate] One of `START|END` to specify how the API will handle inputs longer than the maximum token length. Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- CreateEmbedJobResponse OK Examples -------- import asyncio from cohere import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) async def main() -> None: await client.embed_jobs.create( model="model", dataset_id="dataset_id", input_type="search_document", ) asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( "v1/embed-jobs", method="POST", json={ "model": model, "dataset_id": dataset_id, "input_type": input_type, "name": name, "embedding_types": embedding_types, "truncate": truncate, }, headers={ "content-type": "application/json", }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: return typing.cast( CreateEmbedJobResponse, construct_type( type_=CreateEmbedJobResponse, # type: ignore object_=_response.json(), ), ) if _response.status_code == 400: raise BadRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 401: raise UnauthorizedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 403: raise ForbiddenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 404: raise NotFoundError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 422: raise UnprocessableEntityError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 429: raise TooManyRequestsError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 498: raise InvalidTokenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 499: raise ClientClosedRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 500: raise InternalServerError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 501: raise NotImplementedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 503: raise ServiceUnavailableError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 504: raise GatewayTimeoutError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EmbedJob: """ This API retrieves the details about an embed job started by the same user. Parameters ---------- id : str The ID of the embed job to retrieve. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- EmbedJob OK Examples -------- import asyncio from cohere import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) async def main() -> None: await client.embed_jobs.get( id="id", ) asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( f"v1/embed-jobs/{jsonable_encoder(id)}", method="GET", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return typing.cast( EmbedJob, construct_type( type_=EmbedJob, # type: ignore object_=_response.json(), ), ) if _response.status_code == 400: raise BadRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 401: raise UnauthorizedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 403: raise ForbiddenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 404: raise NotFoundError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 422: raise UnprocessableEntityError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 429: raise TooManyRequestsError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 498: raise InvalidTokenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 499: raise ClientClosedRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 500: raise InternalServerError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 501: raise NotImplementedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 503: raise ServiceUnavailableError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 504: raise GatewayTimeoutError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) async def cancel(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None: """ This API allows users to cancel an active embed job. Once invoked, the embedding process will be terminated, and users will be charged for the embeddings processed up to the cancellation point. It's important to note that partial results will not be available to users after cancellation. Parameters ---------- id : str The ID of the embed job to cancel. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- None Examples -------- import asyncio from cohere import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) async def main() -> None: await client.embed_jobs.cancel( id="id", ) asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( f"v1/embed-jobs/{jsonable_encoder(id)}/cancel", method="POST", request_options=request_options, ) try: if 200 <= _response.status_code < 300: return if _response.status_code == 400: raise BadRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 401: raise UnauthorizedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 403: raise ForbiddenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 404: raise NotFoundError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 422: raise UnprocessableEntityError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 429: raise TooManyRequestsError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 498: raise InvalidTokenError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 499: raise ClientClosedRequestError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 500: raise InternalServerError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 501: raise NotImplementedError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 503: raise ServiceUnavailableError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) if _response.status_code == 504: raise GatewayTimeoutError( typing.cast( typing.Optional[typing.Any], construct_type( type_=typing.Optional[typing.Any], # type: ignore object_=_response.json(), ), ) ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json)