Metadata-Version: 2.5
Name: octpo
Version: 0.1.1
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

For the hosted deployment, set `OCTPO_API_KEY` to its caller bearer token:

```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` and then
`OCTPO_API_TOKEN`. `base_url` can also be set with `OCTPO_BASE_URL`. Remote URLs require a
key; loopback URLs (`localhost`, `127.0.0.1`, or `::1`) may be used without one when the local
Octpo server has authentication disabled. If a key is supplied, requests use
`Authorization: Bearer …`. Custom headers cannot replace `Authorization`, `Accept`, or
`Content-Type`.

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`.
- `POST /chat/completions`: non-streaming chat completions via
  `client.chat.completions.create(...)` when the target supports this endpoint.
- `GET /models`: lists public model IDs configured for the deployment. IDs can vary by
  deployment; source defaults are `octpo-auto` and `octpo-code`.

The Responses API 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 hosted gateway does not expose `/health`, action, or computer-use routes. For a
local Octpo server, set `base_url="http://127.0.0.1:8765/v1"`; it supports model discovery,
text Responses requests, and non-streaming chat completions. Local generation rejects sampling
controls it cannot honor.

### Local server

```python
import octpo

with octpo.Client(base_url="http://127.0.0.1:8765/v1", timeout=300) as client:
    print([model.id for model in client.models.list().data])
    response = client.responses.create(
        model="octpo-auto",
        input="Reply with a short greeting.",
        max_output_tokens=64,
    )
    print(response.output_text)
```

## 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.
