# Python SDK

Install urouter-inference with Python 3.10 or later. Use URouter for synchronous code or AsyncURouter in an async application.

[Source on GitHub](https://github.com/uRouter/urouter-python)

[SDK examples](https://github.com/uRouter/urouter-python/tree/v0.1.0/examples)

## Install the SDK

```sh
python -m pip install "urouter-inference @ git+https://github.com/uRouter/urouter-python.git@v0.1.0"
```

## Send a text request

Create an inference key in Developer → API Keys. Eligible calls use Plan usage first, then paid credit. Keep the key in UROUTER_API_KEY on your server. The clients connect to https://api.urouter.net/v1 by default.

Choose an available text model from Models & Pricing and set UROUTER_MODEL to its exact ID. Review the model’s required credit for a 256-token output limit before running the example.

[Models & Pricing](/developers/catalog/models)

Set UROUTER_OPERATION_ID to a new UUID for this request and save it with your work. Run the example once to send a paid Responses request and print the result.

quickstart.py

```python
import os
from urouter_inference import URouter

with URouter() as client:
    result = client.responses.create(
        model=os.environ["UROUTER_MODEL"],
        input="Explain DNS in one sentence.",
        max_output_tokens=256,
        idempotency_key=os.environ["UROUTER_OPERATION_ID"],
    )
    print("Request ID:", result.http_request_id)
    print(result.output_text)
```

```sh
python quickstart.py
```

## Recover a request

Keep the HTTP request ID (req_…) and the operation’s idempotency key. If a stream disconnects or the outcome is unclear, look up the original request. Read its execution and financial states separately before deciding whether to send another request.

```python
status = client.requests.retrieve(request_id)
```

## Handle an agent’s tool call

Declare the functions your app supports. When the model returns a function_call, check its name and arguments, apply your app’s approval policy, then run the approved action locally. Send a function_call_output with the same call_id. Each continuation is a new inference request.

[Run tools in your client](/developer/api-docs/responses#responses_tools)

[Example with approve, edit, and cancel decisions](https://github.com/uRouter/urouter-python/blob/v0.1.0/examples/review_tools.py)

- [Models & pricing](/developer/api-docs/models)
- [Responses](/developer/api-docs/responses)
- [Errors & recovery](/developer/api-docs/errors)
- [Reseller API](/developer/resellers/api)
