Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/timeout_retry-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Timeout and Retry Configuration

## Basic Usage

from langchain_gradient import ChatGradient
from langchain_gradient.exceptions import APITimeoutError, APIRetryError

Initialize with timeout and retry configuration
llm = ChatGradient(
model="llama3.3-70b-instruct",
timeout=30.0,
max_retries=3
)

try:
response = llm.invoke("Hello world!")
print(response)
except APITimeoutError as e:
print(f"Request timed out: {e}")
except APIRetryError as e:
print(f"Max retries exceeded: {e}")


## Advanced Configuration

from langchain_gradient import ChatGradient
from langchain_gradient.retry_config import RetryConfig

Custom retry configuration with exponential backoff
custom_retry = RetryConfig(
max_retries=5,
initial_delay=1.0,
max_delay=60.0,
exponential_base=2.0,
jitter=True
)

llm = ChatGradient(
model="llama3.3-70b-instruct",
timeout=60.0,
retry_config=custom_retry
)


Comment on lines +5 to +44

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing markdown code fence markers around the Python code. The code examples should be wrapped in triple backticks with the python language identifier for proper rendering.

Suggested change
from langchain_gradient import ChatGradient
from langchain_gradient.exceptions import APITimeoutError, APIRetryError
Initialize with timeout and retry configuration
llm = ChatGradient(
model="llama3.3-70b-instruct",
timeout=30.0,
max_retries=3
)
try:
response = llm.invoke("Hello world!")
print(response)
except APITimeoutError as e:
print(f"Request timed out: {e}")
except APIRetryError as e:
print(f"Max retries exceeded: {e}")
## Advanced Configuration
from langchain_gradient import ChatGradient
from langchain_gradient.retry_config import RetryConfig
Custom retry configuration with exponential backoff
custom_retry = RetryConfig(
max_retries=5,
initial_delay=1.0,
max_delay=60.0,
exponential_base=2.0,
jitter=True
)
llm = ChatGradient(
model="llama3.3-70b-instruct",
timeout=60.0,
retry_config=custom_retry
)
```python
from langchain_gradient import ChatGradient
from langchain_gradient.exceptions import APITimeoutError, APIRetryError
# Initialize with timeout and retry configuration
llm = ChatGradient(
model="llama3.3-70b-instruct",
timeout=30.0,
max_retries=3
)
try:
response = llm.invoke("Hello world!")
print(response)
except APITimeoutError as e:
print(f"Request timed out: {e}")
except APIRetryError as e:
print(f"Max retries exceeded: {e}")

Advanced Configuration

from langchain_gradient import ChatGradient
from langchain_gradient.retry_config import RetryConfig

# Custom retry configuration with exponential backoff
custom_retry = RetryConfig(
    max_retries=5,
    initial_delay=1.0,
    max_delay=60.0,
    exponential_base=2.0,
    jitter=True
)

llm = ChatGradient(
    model="llama3.3-70b-instruct",
    timeout=60.0,
    retry_config=custom_retry
)

Copilot uses AI. Check for mistakes.
## Exponential Backoff

The retry mechanism uses exponential backoff with jitter to prevent retry storms:
- Delay = initial_delay × (base^attempt)
- Random jitter (±20%) added by default
- Maximum delay capped at max_delay
Loading