# Async and command line

Source: https://docs.temprl.org/guide/async-and-cli

> Run many Simo requests concurrently with AsyncClient, and call Simo from the terminal with the simo command.

## AsyncClient

`AsyncClient` has the same methods as `Client` (`ask`, `ask_json`, `models`, `health`), as coroutines. `max_concurrency` caps requests in flight.

```python
import asyncio
from simoai import AsyncClient, Noul

async def main(texts):
    async with AsyncClient(max_concurrency=8) as c:     # reads $SIMO_API_KEY
        results = await asyncio.gather(*(c.ask(t, {"spam": Noul("This is spam")}) for t in texts))
    return [r["spam"].noul for r in results]

scores = asyncio.run(main(["Win a free iPhone!!!", "Your invoice for October is attached."]))
```

For a synchronous batch with thresholds, see [`Task.run_many`](https://docs.temprl.org/guide/tasks#many-inputs).

## Command line

The SDK installs a `simo` command (also available as `python -m simoai`):

```bash
export SIMO_API_KEY=simo_sk_...
simo health
simo models
simo ask request.json --full               # request.json: {"state": ..., "questions": {...}}
simo ask - --self-check < request.json     # read the request from stdin
```

`request.json` uses the wire format:

`request.json`

```json
{"state": "The customer wants their money back for order A-1042.",
 "model": "simo-1-pro",
 "questions": {"refund": {"type": "noul", "instructions": "The customer asks for a refund"},
               "order": {"type": "extract", "instructions": "the order number", "kind": "text",
                         "many": false, "max_tokens": 8}}}
```
