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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.12"
".": "0.1.0-alpha.13"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 76
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/digitalocean%2Fgradientai-e8b3cbc80e18e4f7f277010349f25e1319156704f359911dc464cc21a0d077a6.yml
configured_endpoints: 77
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/digitalocean%2Fgradientai-391afaae764eb758523b67805cb47ae3bc319dc119d83414afdd66f123ceaf5c.yml
openapi_spec_hash: c773d792724f5647ae25a5ae4ccec208
config_hash: 1c936b3bd798c3fcb25479b19efa999a
config_hash: 0bd094d86a010f7cbd5eb22ef548a29f
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## 0.1.0-alpha.13 (2025-07-15)

Full Changelog: [v0.1.0-alpha.12...v0.1.0-alpha.13](https://github.com/digitalocean/gradientai-python/compare/v0.1.0-alpha.12...v0.1.0-alpha.13)

### Features

* **api:** manual updates ([bd6fecc](https://github.com/digitalocean/gradientai-python/commit/bd6feccf97fa5877085783419f11dad04c57d700))
* **api:** manual updates ([c2b96ce](https://github.com/digitalocean/gradientai-python/commit/c2b96ce3d95cc9b74bffd8d6a499927eefd23b14))
* **api:** share chat completion chunk model between chat and agent.chat ([d67371f](https://github.com/digitalocean/gradientai-python/commit/d67371f9f4d0761ea03097820bc3e77654b4d2bf))
* clean up environment call outs ([64ee5b4](https://github.com/digitalocean/gradientai-python/commit/64ee5b449c0195288d0a1dc55d2725e8cdd6afcf))


### Bug Fixes

* **client:** don't send Content-Type header on GET requests ([507a342](https://github.com/digitalocean/gradientai-python/commit/507a342fbcc7c801ba36708e56ea2d2a28a1a392))
* **parsing:** correctly handle nested discriminated unions ([569e473](https://github.com/digitalocean/gradientai-python/commit/569e473d422928597ccf762133d5e52ac9a8665a))


### Chores

* **internal:** bump pinned h11 dep ([6f4e960](https://github.com/digitalocean/gradientai-python/commit/6f4e960b6cb838cbf5e50301375fcb4b60a2cfb3))
* **internal:** codegen related update ([1df657d](https://github.com/digitalocean/gradientai-python/commit/1df657d9b384cb85d27fe839c0dab212a7773f8f))
* **package:** mark python 3.13 as supported ([1a899b6](https://github.com/digitalocean/gradientai-python/commit/1a899b66a484986672a380e405f09b1ae94b6310))
* **readme:** fix version rendering on pypi ([6fbe83b](https://github.com/digitalocean/gradientai-python/commit/6fbe83b11a9e3dbb40cf7f9f627abbbd086ee24a))

## 0.1.0-alpha.12 (2025-07-02)

Full Changelog: [v0.1.0-alpha.11...v0.1.0-alpha.12](https://github.com/digitalocean/gradientai-python/compare/v0.1.0-alpha.11...v0.1.0-alpha.12)
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GradientAI Python API library

[![PyPI version](<https://img.shields.io/pypi/v/c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python.svg?label=pypi%20(stable)>)](https://pypi.org/project/c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python/)
<!-- prettier-ignore -->
[![PyPI version](https://img.shields.io/pypi/v/c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python.svg?label=pypi%20(stable))](https://pypi.org/project/c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python/)

The GradientAI Python library provides convenient access to the GradientAI REST API from any Python 3.8+
application. The library includes type definitions for all request params and response fields,
Expand Down Expand Up @@ -73,7 +74,7 @@ client = AsyncGradientAI(


async def main() -> None:
completion = await client.agents.chat.completions.create(
completion = await client.chat.completions.create(
messages=[
{
"role": "user",
Expand Down Expand Up @@ -104,18 +105,17 @@ pip install --pre c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python[aiohttp]
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:

```python
import os
import asyncio
from gradientai import DefaultAioHttpClient
from gradientai import AsyncGradientAI


async def main() -> None:
async with AsyncGradientAI(
api_key=os.environ.get("GRADIENTAI_API_KEY"), # This is the default and can be omitted
api_key="My API Key",
http_client=DefaultAioHttpClient(),
) as client:
completion = await client.agents.chat.completions.create(
completion = await client.chat.completions.create(
messages=[
{
"role": "user",
Expand All @@ -139,7 +139,7 @@ from gradientai import GradientAI

client = GradientAI()

stream = client.agents.chat.completions.create(
stream = client.chat.completions.create(
messages=[
{
"role": "user",
Expand All @@ -160,7 +160,7 @@ from gradientai import AsyncGradientAI

client = AsyncGradientAI()

stream = await client.agents.chat.completions.create(
stream = await client.chat.completions.create(
messages=[
{
"role": "user",
Expand Down Expand Up @@ -192,7 +192,7 @@ from gradientai import GradientAI

client = GradientAI()

completion = client.agents.chat.completions.create(
completion = client.chat.completions.create(
messages=[
{
"content": "string",
Expand Down Expand Up @@ -221,7 +221,7 @@ from gradientai import GradientAI
client = GradientAI()

try:
client.agents.chat.completions.create(
client.chat.completions.create(
messages=[
{
"role": "user",
Expand Down Expand Up @@ -272,7 +272,7 @@ client = GradientAI(
)

# Or, configure per-request:
client.with_options(max_retries=5).agents.chat.completions.create(
client.with_options(max_retries=5).chat.completions.create(
messages=[
{
"role": "user",
Expand Down Expand Up @@ -303,7 +303,7 @@ client = GradientAI(
)

# Override per-request:
client.with_options(timeout=5.0).agents.chat.completions.create(
client.with_options(timeout=5.0).chat.completions.create(
messages=[
{
"role": "user",
Expand Down Expand Up @@ -352,7 +352,7 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
from gradientai import GradientAI

client = GradientAI()
response = client.agents.chat.completions.with_raw_response.create(
response = client.chat.completions.with_raw_response.create(
messages=[{
"role": "user",
"content": "What is the capital of France?",
Expand All @@ -361,7 +361,7 @@ response = client.agents.chat.completions.with_raw_response.create(
)
print(response.headers.get('X-My-Header'))

completion = response.parse() # get the object that `agents.chat.completions.create()` would have returned
completion = response.parse() # get the object that `chat.completions.create()` would have returned
print(completion.choices)
```

Expand All @@ -376,7 +376,7 @@ The above interface eagerly reads the full response body when you make the reque
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.

```python
with client.agents.chat.completions.with_streaming_response.create(
with client.chat.completions.with_streaming_response.create(
messages=[
{
"role": "user",
Expand Down
8 changes: 4 additions & 4 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Shared Types

```python
from gradientai.types import APILinks, APIMeta, ChatCompletionTokenLogprob
from gradientai.types import APILinks, APIMeta, ChatCompletionChunk, ChatCompletionTokenLogprob
```

# Agents
Expand Down Expand Up @@ -65,12 +65,12 @@ Methods:
Types:

```python
from gradientai.types.agents.chat import AgentChatCompletionChunk, CompletionCreateResponse
from gradientai.types.agents.chat import CompletionCreateResponse
```

Methods:

- <code title="post /chat/completions">client.agents.chat.completions.<a href="./src/gradientai/resources/agents/chat/completions.py">create</a>(\*\*<a href="src/gradientai/types/agents/chat/completion_create_params.py">params</a>) -> <a href="./src/gradientai/types/agents/chat/completion_create_response.py">CompletionCreateResponse</a></code>
- <code title="post /chat/completions?agent=true">client.agents.chat.completions.<a href="./src/gradientai/resources/agents/chat/completions.py">create</a>(\*\*<a href="src/gradientai/types/agents/chat/completion_create_params.py">params</a>) -> <a href="./src/gradientai/types/agents/chat/completion_create_response.py">CompletionCreateResponse</a></code>

## EvaluationMetrics

Expand Down Expand Up @@ -260,7 +260,7 @@ Methods:
Types:

```python
from gradientai.types.chat import ChatCompletionChunk, CompletionCreateResponse
from gradientai.types.chat import CompletionCreateResponse
```

Methods:
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python"
version = "0.1.0-alpha.12"
version = "0.1.0-alpha.13"
description = "The official Python library for GradientAI"
dynamic = ["readme"]
license = "Apache-2.0"
Expand All @@ -24,6 +24,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: OS Independent",
"Operating System :: POSIX",
"Operating System :: MacOS",
Expand All @@ -38,7 +39,7 @@ Homepage = "https://github.com/digitalocean/gradientai-python"
Repository = "https://github.com/digitalocean/gradientai-python"

[project.optional-dependencies]
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.6"]
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.8"]

[tool.rye]
managed = true
Expand Down
6 changes: 3 additions & 3 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ filelock==3.12.4
frozenlist==1.6.2
# via aiohttp
# via aiosignal
h11==0.14.0
h11==0.16.0
# via httpcore
httpcore==1.0.2
httpcore==1.0.9
# via httpx
httpx==0.28.1
# via c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python
# via httpx-aiohttp
# via respx
httpx-aiohttp==0.1.6
httpx-aiohttp==0.1.8
# via c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python
idna==3.4
# via anyio
Expand Down
6 changes: 3 additions & 3 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ exceptiongroup==1.2.2
frozenlist==1.6.2
# via aiohttp
# via aiosignal
h11==0.14.0
h11==0.16.0
# via httpcore
httpcore==1.0.2
httpcore==1.0.9
# via httpx
httpx==0.28.1
# via c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python
# via httpx-aiohttp
httpx-aiohttp==0.1.6
httpx-aiohttp==0.1.8
# via c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python
idna==3.4
# via anyio
Expand Down
11 changes: 9 additions & 2 deletions src/gradientai/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,15 @@ def _build_request(
# work around https://github.com/encode/httpx/discussions/2880
kwargs["extensions"] = {"sni_hostname": prepared_url.host.replace("_", "-")}

is_body_allowed = options.method.lower() != "get"

if is_body_allowed:
kwargs["json"] = json_data if is_given(json_data) else None
kwargs["files"] = files
else:
headers.pop("Content-Type", None)
kwargs.pop("data", None)

# TODO: report this error to httpx
return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
headers=headers,
Expand All @@ -540,8 +549,6 @@ def _build_request(
# so that passing a `TypedDict` doesn't cause an error.
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
json=json_data if is_given(json_data) else None,
files=files,
**kwargs,
)

Expand Down
18 changes: 18 additions & 0 deletions src/gradientai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ class GradientAI(SyncAPIClient):
# client options
api_key: str | None
inference_key: str | None
agent_key: str | None
agent_domain: str | None

def __init__(
self,
*,
api_key: str | None = None,
inference_key: str | None = None,
agent_key: str | None = None,
agent_domain: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
Expand All @@ -88,6 +90,7 @@ def __init__(
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
- `api_key` from `GRADIENTAI_API_KEY`
- `inference_key` from `GRADIENTAI_INFERENCE_KEY`
- `agent_key` from `GRADIENTAI_AGENT_KEY`
"""
if api_key is None:
api_key = os.environ.get("GRADIENTAI_API_KEY")
Expand All @@ -97,6 +100,10 @@ def __init__(
inference_key = os.environ.get("GRADIENTAI_INFERENCE_KEY")
self.inference_key = inference_key

if agent_key is None:
agent_key = os.environ.get("GRADIENTAI_AGENT_KEY")
self.agent_key = agent_key

self.agent_domain = agent_domain

if base_url is None:
Expand Down Expand Up @@ -200,6 +207,7 @@ def copy(
*,
api_key: str | None = None,
inference_key: str | None = None,
agent_key: str | None = None,
agent_domain: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -236,6 +244,7 @@ def copy(
client = self.__class__(
api_key=api_key or self.api_key,
inference_key=inference_key or self.inference_key,
agent_key=agent_key or self.agent_key,
agent_domain=agent_domain or self.agent_domain,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
Expand Down Expand Up @@ -290,13 +299,15 @@ class AsyncGradientAI(AsyncAPIClient):
# client options
api_key: str | None
inference_key: str | None
agent_key: str | None
agent_domain: str | None

def __init__(
self,
*,
api_key: str | None = None,
inference_key: str | None = None,
agent_key: str | None = None,
agent_domain: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
Expand All @@ -322,6 +333,7 @@ def __init__(
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
- `api_key` from `GRADIENTAI_API_KEY`
- `inference_key` from `GRADIENTAI_INFERENCE_KEY`
- `agent_key` from `GRADIENTAI_AGENT_KEY`
"""
if api_key is None:
api_key = os.environ.get("GRADIENTAI_API_KEY")
Expand All @@ -331,6 +343,10 @@ def __init__(
inference_key = os.environ.get("GRADIENTAI_INFERENCE_KEY")
self.inference_key = inference_key

if agent_key is None:
agent_key = os.environ.get("GRADIENTAI_AGENT_KEY")
self.agent_key = agent_key

self.agent_domain = agent_domain

if base_url is None:
Expand Down Expand Up @@ -434,6 +450,7 @@ def copy(
*,
api_key: str | None = None,
inference_key: str | None = None,
agent_key: str | None = None,
agent_domain: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -470,6 +487,7 @@ def copy(
client = self.__class__(
api_key=api_key or self.api_key,
inference_key=inference_key or self.inference_key,
agent_key=agent_key or self.agent_key,
agent_domain=agent_domain or self.agent_domain,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
Expand Down
Loading