Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c445ed8
fix: sanitize endpoint path params
stainless-app[bot] Mar 19, 2026
57dcc89
feat(api): add random_seed field to fine_tuning cancel and list respo…
stainless-app[bot] Mar 19, 2026
0b4c343
refactor(tests): switch from prism to steady
stainless-app[bot] Mar 19, 2026
f2583ae
chore(tests): bump steady to v0.19.4
stainless-app[bot] Mar 20, 2026
e8de9f6
chore(tests): bump steady to v0.19.5
stainless-app[bot] Mar 20, 2026
6c7113e
chore(internal): update gitignore
stainless-app[bot] Mar 23, 2026
3f935af
chore(tests): bump steady to v0.19.6
stainless-app[bot] Mar 23, 2026
ef08cec
fix(types): correct gpu_type literal in jig, timestamp types in deplo…
stainless-app[bot] Mar 23, 2026
5a27da9
feat: [jig] updated created_at, updated_at format to datetime (#310)
mbrostami Mar 24, 2026
d22b49f
chore(ci): skip lint on metadata-only changes
stainless-app[bot] Mar 24, 2026
859e9ba
chore(tests): bump steady to v0.19.7
stainless-app[bot] Mar 24, 2026
fe89657
docs(api): update voice parameter documentation URL in speech
stainless-app[bot] Mar 25, 2026
4c2075d
chore: Disable translation test temporarily (#313)
blainekasten Mar 25, 2026
e2eef01
test(cli): Test coverage for CLI commands (#311)
blainekasten Mar 25, 2026
a81df45
Add packing parameter (#309)
timofeev1995 Mar 26, 2026
e541c40
chore(internal): regenerate SDK with no functional changes
stainless-app[bot] Mar 26, 2026
f896e54
feat(internal): implement indices array format for query and form ser…
stainless-app[bot] Mar 26, 2026
e06478c
fix(jig): conditionally install pyproject.toml dependancies in docker…
dulaj-me Mar 27, 2026
082d72c
codegen metadata
stainless-app[bot] Mar 27, 2026
b73318c
Fix packing bool flag for cli (#317)
timofeev1995 Mar 30, 2026
e447ab6
feat(api): add bit_rate parameter to speech create method
stainless-app[bot] Mar 30, 2026
6c9613e
codegen metadata
stainless-app[bot] Mar 30, 2026
79eb647
removing typo (#318)
jli-together Mar 30, 2026
a4b6f3d
chore(tests): bump steady to v0.20.1
stainless-app[bot] Mar 31, 2026
b38453b
chore(tests): bump steady to v0.20.2
stainless-app[bot] Mar 31, 2026
2591c99
release: 2.6.0
stainless-app[bot] Mar 31, 2026
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
timeout-minutes: 10
name: lint
runs-on: ${{ github.repository == 'stainless-sdks/togetherai-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
steps:
- uses: actions/checkout@v6

Expand All @@ -38,7 +38,7 @@ jobs:
run: uv run ruff format --check

build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
timeout-minutes: 10
name: build
permissions:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.prism.log
.stdy.log
_dev

__pycache__
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.5.0"
".": "2.6.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 74
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2Ftogetherai-31893d157d3c85caa1d8615b73a5fa431ea2cc126bd2410e0f84f3defd5c7dec.yml
openapi_spec_hash: b652a4d504b4a3dbf585ab803b0f59fc
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2Ftogetherai-d91fd4a37aa010c545f29c4413b9aef8f556d0a63d3c0e5a7ee36abf1671142d.yml
openapi_spec_hash: d3365b580d695d006648441db545aff8
config_hash: 52d213100a0ca1a4b2cdcd2718936b51
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
# Changelog

## 2.6.0 (2026-03-31)

Full Changelog: [v2.5.0...v2.6.0](https://github.com/togethercomputer/together-py/compare/v2.5.0...v2.6.0)

### Features

* [jig] updated created_at, updated_at format to datetime ([#310](https://github.com/togethercomputer/together-py/issues/310)) ([5a27da9](https://github.com/togethercomputer/together-py/commit/5a27da92da7199057d5c1a1c2749044cb325b269))
* **api:** add bit_rate parameter to speech create method ([e447ab6](https://github.com/togethercomputer/together-py/commit/e447ab6b6714e6615bd7285f53bc6a8f71a6edf8))
* **api:** add random_seed field to fine_tuning cancel and list responses ([57dcc89](https://github.com/togethercomputer/together-py/commit/57dcc89748da91dc5e5b70bc24b9e43702fd51ab))
* **internal:** implement indices array format for query and form serialization ([f896e54](https://github.com/togethercomputer/together-py/commit/f896e543c6df5db1657a6ad5ba91925a7d582768))


### Bug Fixes

* **jig:** conditionally install pyproject.toml dependancies in dockerfile only if pyproject.toml is available ([#314](https://github.com/togethercomputer/together-py/issues/314)) ([e06478c](https://github.com/togethercomputer/together-py/commit/e06478cc88c03bfb1915c6bb1e19d1b955bd7065))
* sanitize endpoint path params ([c445ed8](https://github.com/togethercomputer/together-py/commit/c445ed815d6209356ae033cb8408f959fe57c502))
* **types:** correct gpu_type literal in jig, timestamp types in deployment ([ef08cec](https://github.com/togethercomputer/together-py/commit/ef08cec1c13209592ad8547606c2363292589ff0))


### Chores

* **ci:** skip lint on metadata-only changes ([d22b49f](https://github.com/togethercomputer/together-py/commit/d22b49f397c4d9b79290c37f0840eee2b2d3ffea))
* Disable translation test temporarily ([#313](https://github.com/togethercomputer/together-py/issues/313)) ([4c2075d](https://github.com/togethercomputer/together-py/commit/4c2075ddb818c5d156734c851abd3ae28a865a95))
* **internal:** regenerate SDK with no functional changes ([e541c40](https://github.com/togethercomputer/together-py/commit/e541c4017882f28c00dbf711cf6ecba050deef6f))
* **internal:** update gitignore ([6c7113e](https://github.com/togethercomputer/together-py/commit/6c7113e73c0dab048935c14b48f5a7c27501ef33))
* **tests:** bump steady to v0.19.4 ([f2583ae](https://github.com/togethercomputer/together-py/commit/f2583aeb228f05440305b05d03c1b1e1a5926f2a))
* **tests:** bump steady to v0.19.5 ([e8de9f6](https://github.com/togethercomputer/together-py/commit/e8de9f612adbfc2d1612103c87ae5fd5242de766))
* **tests:** bump steady to v0.19.6 ([3f935af](https://github.com/togethercomputer/together-py/commit/3f935afab8e7714da23490d89752515b7ab37ad9))
* **tests:** bump steady to v0.19.7 ([859e9ba](https://github.com/togethercomputer/together-py/commit/859e9ba7b53111631abe46ec0c19c0556162c8f2))
* **tests:** bump steady to v0.20.1 ([a4b6f3d](https://github.com/togethercomputer/together-py/commit/a4b6f3d2472231dda03c4a776bfdebcf21de1fc9))
* **tests:** bump steady to v0.20.2 ([b38453b](https://github.com/togethercomputer/together-py/commit/b38453bac5db8f1c34e1ea945c60a0bb68a632eb))


### Documentation

* **api:** update voice parameter documentation URL in speech ([fe89657](https://github.com/togethercomputer/together-py/commit/fe896570536c106938c4dc1f7585b590bb2913be))


### Refactors

* **tests:** switch from prism to steady ([0b4c343](https://github.com/togethercomputer/together-py/commit/0b4c343fb6f72a4fda7593bdf6ea133cfad1ca29))

## 2.5.0 (2026-03-18)

Full Changelog: [v2.4.0...v2.5.0](https://github.com/togethercomputer/together-py/compare/v2.4.0...v2.5.0)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ $ pip install ./path-to-wheel-file.whl

## Running tests

Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
Most tests require you to [set up a mock server](https://github.com/dgellow/steady) against the OpenAPI spec to run the tests.

```sh
$ ./scripts/mock
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "together"
version = "2.5.0"
version = "2.6.0"
description = "The official Python library for the together API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
26 changes: 13 additions & 13 deletions scripts/mock
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ fi

echo "==> Starting mock server with URL ${URL}"

# Run prism mock on the given spec
# Run steady mock on the given spec
if [ "$1" == "--daemon" ]; then
# Pre-install the package so the download doesn't eat into the startup timeout
npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism --version
npm exec --package=@stdy/cli@0.20.2 -- steady --version

npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" &> .prism.log &
npm exec --package=@stdy/cli@0.20.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log &

# Wait for server to come online (max 30s)
# Wait for server to come online via health endpoint (max 30s)
echo -n "Waiting for server"
attempts=0
while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do
if ! kill -0 $! 2>/dev/null; then
echo
cat .stdy.log
exit 1
fi
attempts=$((attempts + 1))
if [ "$attempts" -ge 300 ]; then
echo
echo "Timed out waiting for Prism server to start"
cat .prism.log
echo "Timed out waiting for Steady server to start"
cat .stdy.log
exit 1
fi
echo -n "."
sleep 0.1
done

if grep -q "✖ fatal" ".prism.log"; then
cat .prism.log
exit 1
fi

echo
else
npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL"
npm exec --package=@stdy/cli@0.20.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL"
fi
16 changes: 8 additions & 8 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

function prism_is_running() {
curl --silent "http://localhost:4010" >/dev/null 2>&1
function steady_is_running() {
curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1
}

kill_server_on_port() {
Expand All @@ -25,7 +25,7 @@ function is_overriding_api_base_url() {
[ -n "$TEST_API_BASE_URL" ]
}

if ! is_overriding_api_base_url && ! prism_is_running ; then
if ! is_overriding_api_base_url && ! steady_is_running ; then
# When we exit this script, make sure to kill the background mock server process
trap 'kill_server_on_port 4010' EXIT

Expand All @@ -36,19 +36,19 @@ fi
if is_overriding_api_base_url ; then
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}"
echo
elif ! prism_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server"
elif ! steady_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Steady server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
echo -e "spec to the prism command:"
echo -e "spec to the steady command:"
echo
echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}"
echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.20.2 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}"
echo

exit 1
else
echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}"
echo -e "${GREEN}✔ Mock steady server is running with your OpenAPI spec${NC}"
echo
fi

Expand Down
5 changes: 4 additions & 1 deletion src/together/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def _stringify_item(
items.extend(self._stringify_item(key, item, opts))
return items
elif array_format == "indices":
raise NotImplementedError("The array indices format is not supported yet")
items = []
for i, item in enumerate(value):
items.extend(self._stringify_item(f"{key}[{i}]", item, opts))
return items
elif array_format == "brackets":
items = []
key = key + "[]"
Expand Down
1 change: 1 addition & 0 deletions src/together/_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._path import path_template as path_template
from ._sync import asyncify as asyncify
from ._proxy import LazyProxy as LazyProxy
from ._utils import (
Expand Down
127 changes: 127 additions & 0 deletions src/together/_utils/_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from __future__ import annotations

import re
from typing import (
Any,
Mapping,
Callable,
)
from urllib.parse import quote

# Matches '.' or '..' where each dot is either literal or percent-encoded (%2e / %2E).
_DOT_SEGMENT_RE = re.compile(r"^(?:\.|%2[eE]){1,2}$")

_PLACEHOLDER_RE = re.compile(r"\{(\w+)\}")


def _quote_path_segment_part(value: str) -> str:
"""Percent-encode `value` for use in a URI path segment.

Considers characters not in `pchar` set from RFC 3986 §3.3 to be unsafe.
https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
"""
# quote() already treats unreserved characters (letters, digits, and -._~)
# as safe, so we only need to add sub-delims, ':', and '@'.
# Notably, unlike the default `safe` for quote(), / is unsafe and must be quoted.
return quote(value, safe="!$&'()*+,;=:@")


def _quote_query_part(value: str) -> str:
"""Percent-encode `value` for use in a URI query string.

Considers &, = and characters not in `query` set from RFC 3986 §3.4 to be unsafe.
https://datatracker.ietf.org/doc/html/rfc3986#section-3.4
"""
return quote(value, safe="!$'()*+,;:@/?")


def _quote_fragment_part(value: str) -> str:
"""Percent-encode `value` for use in a URI fragment.

Considers characters not in `fragment` set from RFC 3986 §3.5 to be unsafe.
https://datatracker.ietf.org/doc/html/rfc3986#section-3.5
"""
return quote(value, safe="!$&'()*+,;=:@/?")


def _interpolate(
template: str,
values: Mapping[str, Any],
quoter: Callable[[str], str],
) -> str:
"""Replace {name} placeholders in `template`, quoting each value with `quoter`.

Placeholder names are looked up in `values`.

Raises:
KeyError: If a placeholder is not found in `values`.
"""
# re.split with a capturing group returns alternating
# [text, name, text, name, ..., text] elements.
parts = _PLACEHOLDER_RE.split(template)

for i in range(1, len(parts), 2):
name = parts[i]
if name not in values:
raise KeyError(f"a value for placeholder {{{name}}} was not provided")
val = values[name]
if val is None:
parts[i] = "null"
elif isinstance(val, bool):
parts[i] = "true" if val else "false"
else:
parts[i] = quoter(str(values[name]))

return "".join(parts)


def path_template(template: str, /, **kwargs: Any) -> str:
"""Interpolate {name} placeholders in `template` from keyword arguments.

Args:
template: The template string containing {name} placeholders.
**kwargs: Keyword arguments to interpolate into the template.

Returns:
The template with placeholders interpolated and percent-encoded.

Safe characters for percent-encoding are dependent on the URI component.
Placeholders in path and fragment portions are percent-encoded where the `segment`
and `fragment` sets from RFC 3986 respectively are considered safe.
Placeholders in the query portion are percent-encoded where the `query` set from
RFC 3986 §3.3 is considered safe except for = and & characters.

Raises:
KeyError: If a placeholder is not found in `kwargs`.
ValueError: If resulting path contains /./ or /../ segments (including percent-encoded dot-segments).
"""
# Split the template into path, query, and fragment portions.
fragment_template: str | None = None
query_template: str | None = None

rest = template
if "#" in rest:
rest, fragment_template = rest.split("#", 1)
if "?" in rest:
rest, query_template = rest.split("?", 1)
path_template = rest

# Interpolate each portion with the appropriate quoting rules.
path_result = _interpolate(path_template, kwargs, _quote_path_segment_part)

# Reject dot-segments (. and ..) in the final assembled path. The check
# runs after interpolation so that adjacent placeholders or a mix of static
# text and placeholders that together form a dot-segment are caught.
# Also reject percent-encoded dot-segments to protect against incorrectly
# implemented normalization in servers/proxies.
for segment in path_result.split("/"):
if _DOT_SEGMENT_RE.match(segment):
raise ValueError(f"Constructed path {path_result!r} contains dot-segment {segment!r} which is not allowed")

result = path_result
if query_template is not None:
result += "?" + _interpolate(query_template, kwargs, _quote_query_part)
if fragment_template is not None:
result += "#" + _interpolate(fragment_template, kwargs, _quote_fragment_part)

return result
2 changes: 1 addition & 1 deletion src/together/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "together"
__version__ = "2.5.0" # x-release-please-version
__version__ = "2.6.0" # x-release-please-version
2 changes: 1 addition & 1 deletion src/together/lib/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def block_requests_for_api_key(_: httpx.Request) -> None:
invoked_command = click.get_current_context().command_path
invoked_command_name = invoked_command.split("together ")[1]
click.secho(
"Error: api key missing.\n\nThe api_key must be set either by passing --api-key to the command or by setting the TOGETHER_API_KEY environment variable",
"Error: api key missing.\n\nThe api key must be set either by passing --api-key to the command or by setting the TOGETHER_API_KEY environment variable",
fg="red",
)
click.secho("\nYou can find your api key at https://api.together.xyz/settings/api-keys", fg="yellow")
Expand Down
Loading
Loading