Skip to content
Merged
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ project_return_schema = client.projects.create(
print(project_return_schema.id)
```

While you can provide an `api_key` keyword argument,
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
to add `CODEX_API_KEY="My API Key"` to your `.env` file
so that your API Key is not stored in source control.

## Async usage

Simply import `AsyncCodex` instead of `Codex` and use `await` with each API call:
Expand Down
22 changes: 20 additions & 2 deletions src/codex/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,18 @@ def __init__(
# part of our public interface in the future.
_strict_response_validation: bool = False,
) -> None:
"""Construct a new synchronous Codex client instance."""
"""Construct a new synchronous Codex client instance.

This automatically infers the following arguments from their corresponding environment variables if they are not provided:
- `api_key` from `CODEX_API_KEY`
- `access_key` from `CODEX_ACCESS_KEY`
"""
if api_key is None:
api_key = os.environ.get("CODEX_API_KEY")
self.api_key = api_key

if access_key is None:
access_key = os.environ.get("CODEX_ACCESS_KEY")
self.access_key = access_key

self._environment = environment
Expand Down Expand Up @@ -325,9 +334,18 @@ def __init__(
# part of our public interface in the future.
_strict_response_validation: bool = False,
) -> None:
"""Construct a new async Codex client instance."""
"""Construct a new async Codex client instance.

This automatically infers the following arguments from their corresponding environment variables if they are not provided:
- `api_key` from `CODEX_API_KEY`
- `access_key` from `CODEX_ACCESS_KEY`
"""
if api_key is None:
api_key = os.environ.get("CODEX_API_KEY")
self.api_key = api_key

if access_key is None:
access_key = os.environ.get("CODEX_ACCESS_KEY")
self.access_key = access_key

self._environment = environment
Expand Down