Metadata-Version: 2.5
Name: octpo
Version: 0.1.0
Summary: Official Python client for the Octpo hosted model API
Author: Aadil Fazal
License: MIT License
        
        Copyright (c) 2026 Aadil Fazal
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: api,llm,octpo,sdk
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: httpx<1,>=0.27
Provides-Extra: test
Requires-Dist: build>=1.2; extra == 'test'
Requires-Dist: mypy>=1.11; extra == 'test'
Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
Requires-Dist: pytest>=8; extra == 'test'
Requires-Dist: respx>=0.21; extra == 'test'
Requires-Dist: ruff>=0.6; extra == 'test'
Description-Content-Type: text/markdown

# Octpo Python SDK

`octpo` is the Python client for Octpo's hosted API at `https://platform-octpo.vercel.app/v1`.
It uses HTTPX and supports synchronous and asynchronous calls.

## Installation

```bash
python -m pip install octpo
```

For a local checkout:

```bash
cd octpo_python_lib
python -m venv .venv
. .venv/bin/activate  # Windows: .venv\Scripts\activate
python -m pip install -e '.[test]'
```

## Quick start

Set `OCTPO_API_KEY` to the caller bearer token configured for your Octpo deployment:

```bash
export OCTPO_API_KEY="your-token"
```

```python
import octpo

client = octpo.Client(
    default_headers={"X-Client-Name": "Octpo", "X-Client-Version": "1.0.0"},
)
response = client.responses.create(model="octpo-auto", input="Hello! Introduce yourself briefly.")
print(response.output_text)
client.close()
```

The equivalent async call is:

```python
import asyncio
import octpo

async def main():
    async with octpo.AsyncClient() as client:
        response = await client.responses.create(model="octpo-auto", input="Hello!")
        print(response.output_text)

asyncio.run(main())
```

## Configuration

Both clients accept `api_key`, `base_url`, `default_headers`, `timeout` (seconds or
`httpx.Timeout`), `max_retries` (default 2), and an optional HTTPX client as
`http_client`. If `api_key` is omitted, the client reads `OCTPO_API_KEY`. Authorization is
always set to the supplied API key; custom headers cannot replace `Authorization`, `Accept`,
or `Content-Type`. Requests use `Authorization: Bearer …`.

Retries are limited to idempotent model discovery (`GET /models`) for transport failures,
timeouts, 429, and selected transient 5xx responses. `Retry-After` is honored up to 30 seconds.
Response creation is never automatically retried because it is a non-idempotent POST.

## Supported API

The SDK matches the Vercel gateway implementation:

- `POST /responses`: text-only input, `model`, `instructions`, `max_output_tokens`,
  `temperature`, `top_p`, and `metadata`. Returns a typed `Response` with `output_text`.
- `GET /models`: lists public model IDs configured for the deployment. IDs can vary by
  deployment; source defaults are `octpo-auto` and `octpo-code`.
- `POST /chat/completions` is implemented by the gateway, but is not exposed in this first
  SDK release; use the Responses API for supported text generation.

The Responses gateway does not support image/audio inputs, tool calling, or streaming. It
rejects unsupported request fields instead of silently ignoring them. Streaming is not
implemented in this SDK. The gateway has no documented OpenAPI schema or additional endpoints
in its route configuration; `/health`, action, and computer-use routes are not part of this
hosted gateway.

## Errors

All SDK exceptions derive from `OctpoError`. HTTP errors derive from `APIError` and expose
`status_code`, `response`, and `body`. Common status codes map to `AuthenticationError`,
`InvalidRequestError`, `RateLimitError`, and `ServerError`. Connection failures raise
`NetworkError`; timeouts raise `APITimeoutError`; incompatible successful payloads raise
`ResponseFormatError`. API error messages are retained.

## Troubleshooting

- **503 `API is not configured`**: the deployment has not configured its caller token.
- **401 invalid/missing API token**: verify `OCTPO_API_KEY` matches the deployment's
  `OCTPO_API_TOKEN`. Never include it in source control or logs.
- **400 unsupported fields**: this gateway accepts only the fields listed above and text
  message input. Remove unsupported options.
- **502/504 upstream errors**: the hosted gateway could not obtain a valid response from the
  configured Octpo model server; check the deployment's upstream configuration.

## Local checks

```bash
python -m pytest
python -m ruff check src tests
python -m mypy src
python -m build
```

Integration tests run only when `OCTPO_API_KEY` is explicitly set. They do not print the key.
