Overview
Defines the custom exception type CohereError for AWS-specific Cohere SDK errors, capturing a human-readable message and the associated HTTP status code.
Description
The AwsCohereError module provides the CohereError exception class, which extends Python's built-in Exception. It is raised when AWS-deployed Cohere operations encounter errors, such as invalid requests or service failures. The exception stores the error message, the HTTP status code returned by the AWS endpoint, and any associated HTTP response headers, allowing callers to programmatically inspect and handle failures.
Usage
Use this exception class when you need to catch and handle errors originating from Cohere model invocations on AWS SageMaker or Amazon Bedrock. It is raised internally by the AWS client modules and can be caught in application code for custom error handling or retry logic.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/manually_maintained/cohere_aws/error.py
Signature
class CohereError(Exception):
def __init__(
self,
message=None,
http_status=None,
headers=None,
) -> None: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
Import
from cohere.manually_maintained.cohere_aws.error import CohereError
I/O Contract
Constructor Parameters
| Parameter |
Type |
Default |
Description
|
message |
str or None |
None |
A human-readable error message describing what went wrong.
|
http_status |
int or None |
None |
The HTTP status code returned by the AWS endpoint (e.g., 400, 500).
|
headers |
dict or None |
None |
HTTP response headers associated with the error. Defaults to an empty dict if not provided.
|
Instance Attributes
| Attribute |
Type |
Description
|
message |
str or None |
The error message.
|
http_status |
int or None |
The HTTP status code.
|
headers |
dict |
The HTTP response headers (empty dict if none were provided).
|
String Representations
| Method |
Output |
Description
|
__str__() |
message or '<empty message>' |
Returns the error message, or a placeholder if the message is None.
|
__repr__() |
CohereError(message=..., http_status=...) |
Returns a developer-friendly representation including class name, message, and status code.
|
Usage Examples
from cohere.manually_maintained.cohere_aws.error import CohereError
# Raising and catching a CohereError
try:
raise CohereError(
message="Model endpoint returned an invalid response",
http_status=500,
headers={"x-request-id": "abc-123"}
)
except CohereError as e:
print(str(e)) # "Model endpoint returned an invalid response"
print(e.http_status) # 500
print(e.headers) # {"x-request-id": "abc-123"}
print(repr(e)) # CohereError(message='Model endpoint returned an invalid response', http_status=500)
# Error with no message
err = CohereError()
print(str(err)) # "<empty message>"
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.