From 2718f4b8f33771777048d98734b577430dc0abad Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 2 Apr 2026 22:11:02 +0000 Subject: [PATCH 1/2] feat(api): api update --- .stats.yml | 2 +- README.md | 14 +++++++++++--- src/retell/_client.py | 28 +++++++++++++++++++++++----- tests/test_client.py | 12 +++++++++++- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/.stats.yml b/.stats.yml index 165b478c..64de1d31 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 73 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/retell%2Fretell-56de19127afbdf111fd60a0aa1188496712acbcf9069d535396af6e66a0afd70.yml openapi_spec_hash: a56e1bcb7ab38d9fade4a42840e7e15f -config_hash: bf63cd880955c4d6be170f4c6c68959e +config_hash: 5936ef3375d1ec06069b8f2794dd1dd2 diff --git a/README.md b/README.md index ad1b355d..67f7c7a8 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,11 @@ pip install retell-sdk The full API of this library can be found in [api.md](api.md). ```python +import os from retell import Retell client = Retell( - api_key="YOUR_RETELL_API_KEY", + api_key=os.environ.get("RETELL_API_KEY"), # This is the default and can be omitted ) agent_response = client.agent.create( @@ -48,16 +49,22 @@ agent_response = client.agent.create( print(agent_response.agent_id) ``` +While you can provide an `api_key` keyword argument, +we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/) +to add `RETELL_API_KEY="YOUR_RETELL_API_KEY"` to your `.env` file +so that your API Key is not stored in source control. + ## Async usage Simply import `AsyncRetell` instead of `Retell` and use `await` with each API call: ```python +import os import asyncio from retell import AsyncRetell client = AsyncRetell( - api_key="YOUR_RETELL_API_KEY", + api_key=os.environ.get("RETELL_API_KEY"), # This is the default and can be omitted ) @@ -91,6 +98,7 @@ pip install retell-sdk[aiohttp] Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`: ```python +import os import asyncio from retell import DefaultAioHttpClient from retell import AsyncRetell @@ -98,7 +106,7 @@ from retell import AsyncRetell async def main() -> None: async with AsyncRetell( - api_key="YOUR_RETELL_API_KEY", + api_key=os.environ.get("RETELL_API_KEY"), # This is the default and can be omitted http_client=DefaultAioHttpClient(), ) as client: agent_response = await client.agent.create( diff --git a/src/retell/_client.py b/src/retell/_client.py index 91c8723e..ad7a428d 100644 --- a/src/retell/_client.py +++ b/src/retell/_client.py @@ -23,7 +23,7 @@ from ._compat import cached_property from ._version import __version__ from ._streaming import Stream as Stream, AsyncStream as AsyncStream -from ._exceptions import APIStatusError +from ._exceptions import RetellError, APIStatusError from ._base_client import ( DEFAULT_MAX_RETRIES, SyncAPIClient, @@ -76,7 +76,7 @@ class Retell(SyncAPIClient): def __init__( self, *, - api_key: str, + api_key: str | None = None, base_url: str | httpx.URL | None = None, timeout: float | Timeout | None | NotGiven = not_given, max_retries: int = DEFAULT_MAX_RETRIES, @@ -96,7 +96,16 @@ def __init__( # part of our public interface in the future. _strict_response_validation: bool = False, ) -> None: - """Construct a new synchronous Retell client instance.""" + """Construct a new synchronous Retell client instance. + + This automatically infers the `api_key` argument from the `RETELL_API_KEY` environment variable if it is not provided. + """ + if api_key is None: + api_key = os.environ.get("RETELL_API_KEY") + if api_key is None: + raise RetellError( + "The api_key client option must be set either by passing api_key to the client or by setting the RETELL_API_KEY environment variable" + ) self.api_key = api_key self.verify = verify # type: ignore @@ -320,7 +329,7 @@ class AsyncRetell(AsyncAPIClient): def __init__( self, *, - api_key: str, + api_key: str | None = None, base_url: str | httpx.URL | None = None, timeout: float | Timeout | None | NotGiven = not_given, max_retries: int = DEFAULT_MAX_RETRIES, @@ -340,7 +349,16 @@ def __init__( # part of our public interface in the future. _strict_response_validation: bool = False, ) -> None: - """Construct a new async AsyncRetell client instance.""" + """Construct a new async AsyncRetell client instance. + + This automatically infers the `api_key` argument from the `RETELL_API_KEY` environment variable if it is not provided. + """ + if api_key is None: + api_key = os.environ.get("RETELL_API_KEY") + if api_key is None: + raise RetellError( + "The api_key client option must be set either by passing api_key to the client or by setting the RETELL_API_KEY environment variable" + ) self.api_key = api_key if base_url is None: diff --git a/tests/test_client.py b/tests/test_client.py index ba298f60..65b5beb7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -23,7 +23,7 @@ from retell._types import Omit from retell._utils import asyncify from retell._models import BaseModel, FinalRequestOptions -from retell._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError +from retell._exceptions import RetellError, APIStatusError, APITimeoutError, APIResponseValidationError from retell._base_client import ( DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, @@ -402,6 +402,11 @@ def test_validate_headers(self) -> None: request = client._build_request(FinalRequestOptions(method="get", url="/foo")) assert request.headers.get("Authorization") == f"Bearer {api_key}" + with pytest.raises(RetellError): + with update_env(**{"RETELL_API_KEY": Omit()}): + client2 = Retell(base_url=base_url, api_key=None, _strict_response_validation=True) + _ = client2 + def test_default_query_option(self) -> None: client = Retell( base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} @@ -1316,6 +1321,11 @@ def test_validate_headers(self) -> None: request = client._build_request(FinalRequestOptions(method="get", url="/foo")) assert request.headers.get("Authorization") == f"Bearer {api_key}" + with pytest.raises(RetellError): + with update_env(**{"RETELL_API_KEY": Omit()}): + client2 = AsyncRetell(base_url=base_url, api_key=None, _strict_response_validation=True) + _ = client2 + async def test_default_query_option(self) -> None: client = AsyncRetell( base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} From cb589710e3bd991f362a950833769564300a2110 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 2 Apr 2026 22:11:21 +0000 Subject: [PATCH 2/2] release: 5.25.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- src/retell/_version.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 969c522a..8f3c6b87 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "5.24.0" + ".": "5.25.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 13339fae..e7ff9f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 5.25.0 (2026-04-02) + +Full Changelog: [v5.24.0...v5.25.0](https://github.com/RetellAI/retell-python-sdk/compare/v5.24.0...v5.25.0) + +### Features + +* **api:** api update ([2718f4b](https://github.com/RetellAI/retell-python-sdk/commit/2718f4b8f33771777048d98734b577430dc0abad)) + ## 5.24.0 (2026-04-01) Full Changelog: [v5.23.0...v5.24.0](https://github.com/RetellAI/retell-python-sdk/compare/v5.23.0...v5.24.0) diff --git a/pyproject.toml b/pyproject.toml index b6e9474c..c0ab189b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "retell-sdk" -version = "5.24.0" +version = "5.25.0" description = "The official Python library for the retell API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/retell/_version.py b/src/retell/_version.py index 22a8ad54..350f586d 100644 --- a/src/retell/_version.py +++ b/src/retell/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "retell" -__version__ = "5.24.0" # x-release-please-version +__version__ = "5.25.0" # x-release-please-version