OpenAI vs Krutrim Cloud Diff

Created Diff never expires
279 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
565 lines
183 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
469 lines
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.


from __future__ import annotations
from __future__ import annotations


import os
import os
from typing import Any, Union, Mapping
from typing import Any, Union, Mapping
from typing_extensions import Self, override
from typing_extensions import Self, override


import httpx
import httpx


from . import _exceptions
from . import resources, _exceptions
from ._qs import Querystring
from ._qs import Querystring
from ._types import (
from ._types import (
NOT_GIVEN,
NOT_GIVEN,
Omit,
Omit,
Timeout,
Timeout,
NotGiven,
NotGiven,
Transport,
Transport,
ProxiesTypes,
ProxiesTypes,
RequestOptions,
RequestOptions,
)
)
from ._utils import (
from ._utils import (
is_given,
is_given,
is_mapping,
get_async_library,
get_async_library,
)
)
from ._version import __version__
from ._version import __version__
from .resources import files, images, models, batches, embeddings, completions, moderations
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
from ._exceptions import OpenAIError, APIStatusError
from ._exceptions import APIStatusError
from ._exceptions import KrutrimCloudError
from ._base_client import (
from ._base_client import (
DEFAULT_MAX_RETRIES,
DEFAULT_MAX_RETRIES,
SyncAPIClient,
SyncAPIClient,
AsyncAPIClient,
AsyncAPIClient,
)
)
from .resources.beta import beta
from .resources.chat import chat
from .resources.audio import audio
from .resources.uploads import uploads
from .resources.fine_tuning import fine_tuning


__all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "OpenAI", "AsyncOpenAI", "Client", "AsyncClient"]
__all__ = [
"Timeout",
"Transport",
"ProxiesTypes",
"RequestOptions",
"resources",
"KrutrimCloud",
"AsyncKrutrimCloud",
"Client",
"AsyncClient",
]




class OpenAI(SyncAPIClient):
class KrutrimCloud(SyncAPIClient):
completions: completions.Completions
images: resources.ImagesResource
chat: chat.Chat
multimodal: resources.MultimodalResource
embeddings: embeddings.Embeddings
audio: resources.AudioResource
files: files.Files
chat: resources.ChatResource
images: images.Images
registry: resources.RegistryResource
audio: audio.Audio
deploy: resources.DeployResource
moderations: moderations.Moderations
videos: resources.VideosResource
models: models.Models
fine_tuning: resources.FineTuningResource
fine_tuning: fine_tuning.FineTuning
languagelabs: resources.LanguageLabsResource
beta: beta.Beta
inference: resources.InferenceResource
batches: batches.Batches
with_raw_response: KrutrimCloudWithRawResponse
uploads: uploads.Uploads
with_streaming_response: KrutrimCloudWithStreamedResponse
with_raw_response: OpenAIWithRawResponse

with_streaming_response: OpenAIWithStreamedResponse


# client options
# client options
api_key: str
organization: str | None
project: str | None

websocket_base_url: str | httpx.URL | None
"""Base URL for WebSocket connections.

If not specified, the default base URL will be used, with 'wss://' replacing the
'http://' or 'https://' scheme. For example: 'http://example.com' becomes
'wss://example.com'
"""


def __init__(
def __init__(
self,
self,
*,
*,
api_key: str | None = None,
api_key: str | None = None,
organization: str | None = None,
project: str | None = None,
base_url: str | httpx.URL | None = None,
base_url: str | httpx.URL | None = None,
websocket_base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
default_query: Mapping[str, object] | None = None,
# Configure a custom httpx client.
# Configure a custom httpx client.
# We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
# We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
# See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
# See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
http_client: httpx.Client | None = None,
http_client: httpx.Client | None = None,
# Enable or disable schema validation for data returned by the API.
# Enable or disable schema validation for data returned by the API.
# When enabled an error APIResponseValidationError is raised
# When enabled an error APIResponseValidationError is raised
# if the API responds with invalid data for the expected schema.
# if the API responds with invalid data for the expected schema.
#
#
# This parameter may be removed or changed in the future.
# This parameter may be removed or changed in the future.
# If you rely on this feature, please open a GitHub issue
# If you rely on this feature, please open a GitHub issue
# outlining your use-case to help us decide if it should be
# outlining your use-case to help us decide if it should be
# part of our public interface in the future.
# part of our public interface in the future.
_strict_response_validation: bool = False,
_strict_response_validation: bool = False,
) -> None:
) -> None:
"""Construct a new synchronous openai client instance.
"""Construct a new synchronous krutrim-cloud client instance.


This automatically infers the following arguments from their corresponding environment variables if they are not provided:
This automatically infers the `api_key` argument from the `KRUTRIM_CLOUD_API_KEY` environment variable if it is not provided.
- `api_key` from `OPENAI_API_KEY`
- `organization` from `OPENAI_ORG_ID`
- `project` from `OPENAI_PROJECT_ID`
"""
"""
if api_key is None:
if api_key is None:
api_key = os.environ.get("OPENAI_API_KEY")
api_key = os.environ.get("KRUTRIM_CLOUD_API_KEY")
if api_key is None:
if api_key is None:
raise OpenAIError(
raise KrutrimCloudError(
"The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable"
"The api_key client option must be set either by passing api_key to the client or by setting the KRUTRIM_CLOUD_API_KEY environment variable"
)
)
self.api_key = api_key
self.api_key = api_key


if organization is None:
organization = os.environ.get("OPENAI_ORG_ID")
self.organization = organization

if project is None:
project = os.environ.get("OPENAI_PROJECT_ID")
self.project = project

self.websocket_base_url = websocket_base_url

if base_url is None:
if base_url is None:
base_url = os.environ.get("OPENAI_BASE_URL")
base_url = os.environ.get("KRUTRIM_CLOUD_BASE_URL")
if base_url is None:
if base_url is None:
base_url = f"https://api.openai.com/v1"
base_url = f"https://cloud.olakrutrim.com"

default_headers = {"user-agent": f"Krutrim-Cloud-Python-SDK/{__version__}"}


super().__init__(
super().__init__(
version=__version__,
version=__version__,
base_url=base_url,
base_url=base_url,
max_retries=max_retries,
max_retries=max_retries,
timeout=timeout,
timeout=timeout,
http_client=http_client,
http_client=http_client,
custom_headers=default_headers,
custom_headers=default_headers,
custom_query=default_query,
custom_query=default_query,
_strict_response_validation=_strict_response_validation,
_strict_response_validation=_strict_response_validation,
)
)

self.images = resources.ImagesResource(self)
self._default_stream_cls = Stream
self.multimodal = resources.MultimodalResource(self)
self.audio = resources.AudioResource(self)
self.chat = resources.ChatResource(self)
self.registry = resources.RegistryResource(self)
self.deploy = resources.DeployResource(self)
self.videos = resources.VideosResource(self)
self.fine_tuning = resources.FineTuningResource(self)
self.inference = resources.InferenceResource(self)
self.languagelabs = resources.LanguageLabsResource(self)
self.with_raw_response = KrutrimCloudWithRawResponse(self)
self.with_streaming_response = KrutrimCloudWithStreamedResponse(self)


self.completions = completions.Completions(self)
self.chat = chat.Chat(self)
self.embeddings = embeddings.Embeddings(self)
self.files = files.Files(self)
self.images = images.Images(self)
self.audio = audio.Audio(self)
self.moderations = moderations.Moderations(self)
self.models = models.Models(self)
self.fine_tuning = fine_tuning.FineTuning(self)
self.beta = beta.Beta(self)
self.batches = batches.Batches(self)
self.uploads = uploads.Uploads(self)
self.with_raw_response = OpenAIWithRawResponse(self)
self.with_streaming_response = OpenAIWithStreamedResponse(self)


@property
@property
@override
@override
def qs(self) -> Querystring:
def qs(self) -> Querystring:
return Querystring(array_format="brackets")
return Querystring(array_format="comma")

Text moved to lines 146-150
@property
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
return {"Authorization": f"Bearer {api_key}"}


@property
@property
@override
@override
def default_headers(self) -> dict[str, str | Omit]:
def default_headers(self) -> dict[str, str | Omit]:
return {
return {
**super().default_headers,
**super().default_headers,
"X-Stainless-Async": "false",
"X-Krutrim-Cloud-Async": "false",
"OpenAI-Organization": self.organization if self.organization is not None else Omit(),
"OpenAI-Project": self.project if self.project is not None else Omit(),
**self._custom_headers,
**self._custom_headers,
}
}


Text moved from lines 163-167
@property
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
return {"Authorization": f"Bearer {api_key}"}

def copy(
def copy(
self,
self,
*,
*,
api_key: str | None = None,
api_key: str | None = None,
organization: str | None = None,
project: str | None = None,
websocket_base_url: str | httpx.URL | None = None,
base_url: str | httpx.URL | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.Client | None = None,
http_client: httpx.Client | None = None,
max_retries: int | NotGiven = NOT_GIVEN,
max_retries: int | NotGiven = NOT_GIVEN,
default_headers: Mapping[str, str] | None = None,
default_headers: Mapping[str, str] | None = None,
set_default_headers: Mapping[str, str] | None = None,
set_default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
default_query: Mapping[str, object] | None = None,
set_default_query: Mapping[str, object] | None = None,
set_default_query: Mapping[str, object] | None = None,
_extra_kwargs: Mapping[str, Any] = {},
_extra_kwargs: Mapping[str, Any] = {},
) -> Self:
) -> Self:
"""
"""
Create a new client instance re-using the same options given to the current client with optional overriding.
Create a new client instance re-using the same options given to the current client with optional overriding.
"""
"""
if default_headers is not None and set_default_headers is not None:
if default_headers is not None and set_default_headers is not None:
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")


if default_query is not None and set_default_query is not None:
if default_query is not None and set_default_query is not None:
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")


headers = self._custom_headers
headers = self._custom_headers
if default_headers is not None:
if default_headers is not None:
headers = {**headers, **default_headers}
headers = {**headers, **default_headers}
elif set_default_headers is not None:
elif set_default_headers is not None:
headers = set_default_headers
headers = set_default_headers


params = self._custom_query
params = self._custom_query
if default_query is not None:
if default_query is not None:
params = {**params, **default_query}
params = {**params, **default_query}
elif set_default_query is not None:
elif set_default_query is not None:
params = set_default_query
params = set_default_query


http_client = http_client or self._client
http_client = http_client or self._client
return self.__class__(
return self.__class__(
api_key=api_key or self.api_key,
organization=organization or self.organization,
project=project or self.project,
websocket_base_url=websocket_base_url or self.websocket_base_url,
base_url=base_url or self.base_url,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
http_client=http_client,
max_retries=max_retries if is_given(max_retries) else self.max_retries,
max_retries=max_retries if is_given(max_retries) else self.max_retries,
default_headers=headers,
default_headers=headers,
default_query=params,
default_query=params,
**_extra_kwargs,
**_extra_kwargs,
)
)


# Alias for `copy` for nicer inline usage, e.g.
# Alias for `copy` for nicer inline usage, e.g.
# client.with_options(timeout=10).foo.create(...)
# client.with_options(timeout=10).foo.create(...)
with_options = copy
with_options = copy


@override
@override
def _make_status_error(
def _make_status_error(
self,
self,
err_msg: str,
err_msg: str,
*,
*,
body: object,
body: object,
response: httpx.Response,
response: httpx.Response,
) -> APIStatusError:
) -> APIStatusError:
data = body.get("error", body) if is_mapping(body) else body
if response.status_code == 400:
if response.status_code == 400:
return _exceptions.BadRequestError(err_msg, response=response, body=data)
return _exceptions.BadRequestError(err_msg, response=response, body=body)


if response.status_code == 401:
if response.status_code == 401:
return _exceptions.AuthenticationError(err_msg, response=response, body=data)
return _exceptions.AuthenticationError(err_msg, response=response, body=body)


if response.status_code == 403:
if response.status_code == 403:
return _exceptions.PermissionDeniedError(err_msg, response=response, body=data)
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)


if response.status_code == 404:
if response.status_code == 404:
return _exceptions.NotFoundError(err_msg, response=response, body=data)
return _exceptions.NotFoundError(err_msg, response=response, body=body)


if response.status_code == 409:
if response.status_code == 409:
return _exceptions.ConflictError(err_msg, response=response, body=data)
return _exceptions.ConflictError(err_msg, response=response, body=body)


if response.status_code == 422:
if response.status_code == 422:
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=data)
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)


if response.status_code == 429:
if response.status_code == 429:
return _exceptions.RateLimitError(err_msg, response=response, body=data)
return _exceptions.RateLimitError(err_msg, response=response, body=body)


if response.status_code >= 500:
if response.status_code >= 500:
return _exceptions.InternalServerError(err_msg, response=response, body=data)
return _exceptions.InternalServerError(err_msg, response=response, body=body)
return APIStatusError(err_msg, response=response, body=data)
return APIStatusError(err_msg, response=response, body=body)




class AsyncOpenAI(AsyncAPIClient):
class AsyncKrutrimCloud(AsyncAPIClient):
completions: completions.AsyncCompletions
images: resources.AsyncImagesResource
chat: chat.AsyncChat
multimodal: resources.AsyncMultimodalResource
embeddings: embeddings.AsyncEmbeddings
audio: resources.AsyncAudioResource
files: files.AsyncFiles
chat: resources.AsyncChatResource
images: images.AsyncImages
deploy: resources.AsyncDeployResource
audio: audio.AsyncAudio
videos: resources.AsyncVideosResource
moderations: moderations.AsyncModerations
fine_tuning: resources.AsyncFineTuningResource
models: models.AsyncModels
inference: resources.AsyncInferenceResource
fine_tuning: fine_tuning.AsyncFineTuning
languagelabs : resources.AsyncLanguageLabsResource
beta: beta.AsyncBeta
with_raw_response: AsyncKrutrimCloudWithRawResponse
batches: batches.AsyncBatches
with_streaming_response: AsyncKrutrimCloudWithStreamedResponse
uploads: uploads.AsyncUploads
with_raw_response: AsyncOpenAIWithRawResponse
with_streaming_response: AsyncOpenAIWithStreamedResponse


# client options
# client options
api_key: str
organization: str | None
project: str | None

websocket_base_url: str | httpx.URL | None
"""Base URL for WebSocket connections.

If not specified, the default base URL will be used, with 'wss://' replacing the
'http://' or 'https://' scheme. For example: 'http://example.com' becomes
'wss://example.com'
"""


def __init__(
def __init__(
self,
self,
*,
*,
api_key: str | None = None,
api_key: str | None = None,
organization: str | None = None,
project: str | None = None,
base_url: str | httpx.URL | None = None,
base_url: str | httpx.URL | None = None,
websocket_base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
default_query: Mapping[str, object] | None = None,
# Configure a custom httpx client.
# Configure a custom httpx client.
# We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
# We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
# See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
# See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
http_client: httpx.AsyncClient | None = None,
http_client: httpx.AsyncClient | None = None,
# Enable or disable schema validation for data returned by the API.
# Enable or disable schema validation for data returned by the API.
# When enabled an error APIResponseValidationError is raised
# When enabled an error APIResponseValidationError is raised
# if the API responds with invalid data for the expected schema.
# if the API responds with invalid data for the expected schema.
#
#
# This parameter may be removed or changed in the future.
# This parameter may be removed or changed in the future.
# If you rely on this feature, please open a GitHub issue
# If you rely on this feature, please open a GitHub issue
# outlining your use-case to help us decide if it should be
# outlining your use-case to help us decide if it should be
# part of our public interface in the future.
# part of our public interface in the future.
_strict_response_validation: bool = False,
_strict_response_validation: bool = False,
) -> None:
) -> None:
"""Construct a new async openai client instance.
"""Construct a new async krutrim-cloud client instance.


This automatically infers the following arguments from their corresponding environment variables if they are not provided:
This automatically infers the `api_key` argument from the `KRUTRIM_CLOUD_API_KEY` environment variable if it is not provided.
- `api_key` from `OPENAI_API_KEY`
- `organization` from `OPENAI_ORG_ID`
- `project` from `OPENAI_PROJECT_ID`
"""
"""
if api_key is None:
if api_key is None:
api_key = os.environ.get("OPENAI_API_KEY")
api_key = os.environ.get("KRUTRIM_CLOUD_API_KEY")
if api_key is None:
if api_key is None:
raise OpenAIError(
raise KrutrimCloudError(
"The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable"
"The api_key client option must be set either by passing api_key to the client or by setting the KRUTRIM_CLOUD_API_KEY environment variable"
)
)
self.api_key = api_key
self.api_key = api_key


if organization is None:
organization = os.environ.get("OPENAI_ORG_ID")
self.organization = organization

if project is None:
project = os.environ.get("OPENAI_PROJECT_ID")
self.project = project

self.websocket_base_url = websocket_base_url

if base_url is None:
if base_url is None:
base_url = os.environ.get("OPENAI_BASE_URL")
base_url = os.environ.get("KRUTRIM_CLOUD_BASE_URL")
if base_url is None:
if base_url is None:
base_url = f"https://api.openai.com/v1"
base_url = f"https://cloud.olakrutrim.com"

default_headers = {"user-agent": f"Krutrim-Cloud-Python-SDK/{__version__}"}


super().__init__(
super().__init__(
version=__version__,
version=__version__,
base_url=base_url,
base_url=base_url,
max_retries=max_retries,
max_retries=max_retries,
timeout=timeout,
timeout=timeout,
http_client=http_client,
http_client=http_client,
custom_headers=default_headers,
custom_headers=default_headers,
custom_query=default_query,
custom_query=default_query,
_strict_response_validation=_strict_response_validation,
_strict_response_validation=_strict_response_validation,
)
)


self._default_stream_cls = AsyncStream
self.images = resources.AsyncImagesResource(self)
self.multimodal = resources.AsyncMultimodalResource(self)
self.audio = resources.AsyncAudioResource(self)
self.chat = resources.AsyncChatResource(self)
self.deploy = resources.AsyncDeployResource(self)
self.videos = resources.AsyncVideosResource(self)
self.fine_tuning = resources.AsyncFineTuningResource(self)
self.inference = resources.AsyncInferenceResource(self)
self.languagelabs = resources.AsyncLanguageLabsResource(self)
self.with_raw_response = AsyncKrutrimCloudWithRawResponse(self)
self.with_streaming_response = AsyncKrutrimCloudWithStreamedResponse(self)


self.completions = completions.AsyncCompletions(self)
self.chat = chat.AsyncChat(self)
self.embeddings = embeddings.AsyncEmbeddings(self)
self.files = files.AsyncFiles(self)
self.images = images.AsyncImages(self)
self.audio = audio.AsyncAudio(self)
self.moderations = moderations.AsyncModerations(self)
self.models = models.AsyncModels(self)
self.fine_tuning = fine_tuning.AsyncFineTuning(self)
self.beta = beta.AsyncBeta(self)
self.batches = batches.AsyncBatches(self)
self.uploads = uploads.AsyncUploads(self)
self.with_raw_response = AsyncOpenAIWithRawResponse(self)
self.with_streaming_response = AsyncOpenAIWithStreamedResponse(self)


@property
@property
@override
@override
def qs(self) -> Querystring:
def qs(self) -> Querystring:
return Querystring(array_format="brackets")
return Querystring(array_format="comma")

Text moved to lines 331-335
@property
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
return {"Authorization": f"Bearer {api_key}"}


@property
@property
@override
@override
def default_headers(self) -> dict[str, str | Omit]:
def default_headers(self) -> dict[str, str | Omit]:
return {
return {
**super().default_headers,
**super().default_headers,
"X-Stainless-Async": f"async:{get_async_library()}",
"X-Krutrim-Cloud-Async": f"async:{get_async_library()}",
"OpenAI-Organization": self.organization if self.organization is not None else Omit(),
"OpenAI-Project": self.project if self.project is not None else Omit(),
**self._custom_headers,
**self._custom_headers,
}
}


Text moved from lines 390-394
@property
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
return {"Authorization": f"Bearer {api_key}"}

def copy(
def copy(
self,
self,
*,
*,
api_key: str | None = None,
api_key: str | None = None,
organization: str | None = None,
project: str | None = None,
websocket_base_url: str | httpx.URL | None = None,
base_url: str | httpx.URL | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.AsyncClient | None = None,
http_client: httpx.AsyncClient | None = None,
max_retries: int | NotGiven = NOT_GIVEN,
max_retries: int | NotGiven = NOT_GIVEN,
default_headers: Mapping[str, str] | None = None,
default_headers: Mapping[str, str] | None = None,
set_default_headers: Mapping[str, str] | None = None,
set_default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
default_query: Mapping[str, object] | None = None,
set_default_query: Mapping[str, object] | None = None,
set_default_query: Mapping[str, object] | None = None,
_extra_kwargs: Mapping[str, Any] = {},
_extra_kwargs: Mapping[str, Any] = {},
) -> Self:
) -> Self:
"""
"""
Create a new client instance re-using the same options given to the current client with optional overriding.
Create a new client instance re-using the same options given to the current client with optional overriding.
"""
"""
if default_headers is not None and set_default_headers is not None:
if default_headers is not None and set_default_headers is not None:
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")


if default_query is not None and set_default_query is not None:
if default_query is not None and set_default_query is not None:
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")


headers = self._custom_headers
headers = self._custom_headers
if default_headers is not None:
if default_headers is not None:
headers = {**headers, **default_headers}
headers = {**headers, **default_headers}
elif set_default_headers is not None:
elif set_default_headers is not None:
headers = set_default_headers
headers = set_default_headers


params = self._custom_query
params = self._custom_query
if default_query is not None:
if default_query is not None:
params = {**params, **default_query}
params = {**params, **default_query}
elif set_default_query is not None:
elif set_default_query is not None:
params = set_default_query
params = set_default_query


http_client = http_client or self._client
http_client = http_client or self._client
return self.__class__(
return self.__class__(
api_key=api_key or self.api_key,
organization=organization or self.organization,
project=project or self.project,
websocket_base_url=websocket_base_url or self.websocket_base_url,
base_url=base_url or self.base_url,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
http_client=http_client,
max_retries=max_retries if is_given(max_retries) else self.max_retries,
max_retries=max_retries if is_given(max_retries) else self.max_retries,
default_headers=headers,
default_headers=headers,
default_query=params,
default_query=params,
**_extra_kwargs,
**_extra_kwargs,
)
)


# Alias for `copy` for nicer inline usage, e.g.
# Alias for `copy` for nicer inline usage, e.g.
# client.with_options(timeout=10).foo.create(...)
# client.with_options(timeout=10).foo.create(...)
with_options = copy
with_options = copy


@override
@override
def _make_status_error(
def _make_status_error(
self,
self,
err_msg: str,
err_msg: str,
*,
*,
body: object,
body: object,
response: httpx.Response,
response: httpx.Response,
) -> APIStatusError:
) -> APIStatusError:
data = body.get("error", body) if is_mapping(body) else body
if response.status_code == 400:
if response.status_code == 400:
return _exceptions.BadRequestError(err_msg, response=response, body=data)
return _exceptions.BadRequestError(err_msg, response=response, body=body)


if response.status_code == 401:
if response.status_code == 401:
return _exceptions.AuthenticationError(err_msg, response=response, body=data)
return _exceptions.AuthenticationError(err_msg, response=response, body=body)


if response.status_code == 403:
if response.status_code == 403:
return _exceptions.PermissionDeniedError(err_msg, response=response, body=data)
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)


if response.status_code == 404:
if response.status_code == 404:
return _exceptions.NotFoundError(err_msg, response=response, body=data)
return _exceptions.NotFoundError(err_msg, response=response, body=body)


if response.status_code == 409:
if response.status_code == 409:
return _exceptions.ConflictError(err_msg, response=response, body=data)
return _exceptions.ConflictError(err_msg, response=response, body=body)


if response.status_code == 422:
if response.status_code == 422:
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=data)
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)


if response.status_code == 429:
if response.status_code == 429:
return _exceptions.RateLimitError(err_msg, response=response, body=data)
return _exceptions.RateLimitError(err_msg, response=response, body=body)


if response.status_code >= 500:
if response.status_code >= 500:
return _exceptions.InternalServerError(err_msg, response=response, body=data)
return _exceptions.InternalServerError(err_msg, response=response, body=body)
return APIStatusError(err_msg, response=response, body=data)
return APIStatusError(err_msg, response=response, body=body)




class OpenAIWithRawResponse:
class KrutrimCloudWithRawResponse:
def __init__(self, client: OpenAI) -> None:
def __init__(self, client: KrutrimCloud) -> None:
self.completions = completions.CompletionsWithRawResponse(client.completions)
self.images = resources.ImagesResourceWithRawResponse(client.images)
self.chat = chat.ChatWithRawResponse(client.chat)
self.multimodal = resources.MultimodalResourceWithRawResponse(client.multimodal)
self.embeddings = embeddings.EmbeddingsWithRawResponse(client.embeddings)
self.audio = resources.AudioResourceWithRawResponse(client.audio)
self.files = files.FilesWithRawResponse(client.files)
self.chat = resources.ChatResourceWithRawResponse(client.chat)
self.images = images.ImagesWithRawResponse(client.images)
self.fine_tuning = resources.FineTuningResourceWithRawResponse(client.fine_tuning)
self.audio = audio.AudioWithRawResponse(client.audio)
self.inference = resources.InferenceResourceWithRawResponse(client.inference)
self.moderations = moderations.ModerationsWithRawResponse(client.moderations)
self.languagelabs = resources.LanguageLabsResourceWithRawResponse(client.languagelabs)
self.models = models.ModelsWithRawResponse(client.models)
self.fine_tuning = fine_tuning.FineTuningWithRawResponse(client.fine_tuning)
self.beta = beta.BetaWithRawResponse(client.beta)
self.batches = batches.BatchesWithRawResponse(client.batches)
self.uploads = uploads.UploadsWithRawResponse(client.uploads)




class AsyncOpenAIWithRawResponse:
class AsyncKrutrimCloudWithRawResponse:
def __init__(self, client: AsyncOpenAI) -> None:
def __init__(self, client: AsyncKrutrimCloud) -> None:
self.completions = completions.AsyncCompletionsWithRawResponse(client.completions)
self.images = resources.AsyncImagesResourceWithRawResponse(client.images)
self.chat = chat.AsyncChatWithRawResponse(client.chat)
self.multimodal = resources.AsyncMultimodalResourceWithRawResponse(client.multimodal)
self.embeddings = embeddings.AsyncEmbeddingsWithRawResponse(client.embeddings)
self.audio = resources.AsyncAudioResourceWithRawResponse(client.audio)
self.files = files.AsyncFilesWithRawResponse(client.files)
self.chat = resources.AsyncChatResourceWithRawResponse(client.chat)
self.images = images.AsyncImagesWithRawResponse(client.images)
self.fine_tuning = resources.AsyncFineTuningResourceWithRawResponse(client.fine_tuning)
self.audio = audio.AsyncAudioWithRawResponse(client.audio)
self.inference = resources.AsyncInferenceResourceWithRawResponse(client.inference)
self.moderations = moderations.AsyncModerationsWithRawResponse(client.moderations)
self.languagelabs = resources.AsyncLanguageLabsResourceWithRawResponse(client.languagelabs)
self.models = models.AsyncModelsWithRawResponse(client.models)
self.fine_tuning = fine_tuning.AsyncFineTuningWithRawResponse(client.fine_tuning)
self.beta = beta.AsyncBetaWithRawResponse(client.beta)
self.batches = batches.AsyncBatchesWithRawResponse(client.batches)
self.uploads = uploads.AsyncUploadsWithRawResponse(client.uploads)




class OpenAIWithStreamedResponse:
class KrutrimCloudWithStreamedResponse:
def __init__(self, client: OpenAI) -> None:
def __init__(self, client: KrutrimCloud) -> None:
self.completions = completions.CompletionsWithStreamingResponse(client.completions)
self.images = resources.ImagesResourceWithStreamingResponse(client.images)
self.chat = chat.ChatWithStreamingResponse(client.chat)
self.multimodal = resources.MultimodalResourceWithStreamingResponse(client.multimodal)
self.embeddings = embeddings.EmbeddingsWithStreamingResponse(client.embeddings)
self.audio = resources.AudioResourceWithStreamingResponse(client.audio)
self.files = files.FilesWithStreamingResponse(client.files)
self.chat = resources.ChatResourceWithStreamingResponse(client.chat)
self.images = images.ImagesWithStreamingResponse(client.images)
self.fine_tuning = resources.FineTuningResourceWithStreamingResponse(client.fine_tuning)
self.audio = audio.AudioWithStreamingResponse(client.audio)
self.inference = resources.InferenceResourceWithStreamingResponse(client.inference)
self.moderations = moderations.ModerationsWithStreamingResponse(client.moderations)
self.languaglabs = resources.LanguageLabsResourceWithStreamingResponse(client.languagelabs)
self.models = models.ModelsWithStreamingResponse(client.models)
self.fine_tuning = fine_tuning.FineTuningWithStreamingResponse(client.fine_tuning)
self.beta = beta.BetaWithStreamingResponse(client.beta)
self.batches = batches.BatchesWithStreamingResponse(client.batches)
self.uploads = uploads.UploadsWithStreamingResponse(client.uploads)




class AsyncOpenAIWithStreamedResponse:

def __init__(self, client: AsyncOpenAI) -> None:
class AsyncKrutrimCloudWithStreamedResponse:
self.completions = completions.AsyncCompletionsWithStreamingResponse(client.completions)
def __init__(self, client: AsyncKrutrimCloud) -> None:
self.chat = chat.AsyncChatWithStreamingResponse(client.chat)
self.images = resources.AsyncImagesResourceWithStreamingResponse(client.images)
self.embeddings = embeddings.AsyncEmbeddingsWithStreamingResponse(client.embeddings)
self.multimodal = resources.AsyncMultimodalResourceWithStreamingResponse(client.multimodal)
self.files = files.AsyncFilesWithStreamingResponse(client.files)
self.audio = resources.AsyncAudioResourceWithStreamingResponse(client.audio)
self.images = images.AsyncImagesWithStreamingResponse(client.images)
self.chat = resources.AsyncChatResourceWithStreamingResponse(client.chat)
self.audio = audio.AsyncAudioWithStreamingResponse(client.audio)
self.fine_tuning = resources.AsyncFineTuningResourceWithStreamingResponse(client.fine_tuning)
self.moderations = moderations.AsyncModerationsWithStreamingResponse(client.moderations)
self.inference = resources.AsyncInferenceResourceWithStreamingResponse(client.inference)
self.models = models.AsyncModelsWithStreamingResponse(client.models)
self.languaglabs = resources.AsyncLanguageLabsResourceWithStreamingResponse(client.languagelabs)
self.fine_tuning = fine_tuning.AsyncFineTuningWithStreamingResponse(client.fine_tuning)
self.beta = beta.AsyncBetaWithStreamingResponse(client.beta)
self.batches = batches.AsyncBatchesWithStreamingResponse(client.batches)
self.uploads = uploads.AsyncUploadsWithStreamingResponse(client.uploads)




Client = OpenAI


AsyncClient = AsyncOpenAI
Client = KrutrimCloud

AsyncClient = AsyncKrutrimCloud