> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bespokelabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeSafe SDK

> Call Nimble with TypeSafe's Python SDK.

Nimble accepts the System One request format, so you can call it with TypeSafe's Python SDK, [`typesafe-sdk`](https://pypi.org/project/typesafe-sdk/).

## Install

```bash theme={null}
pip install typesafe-sdk
```

## Point the SDK at Nimble

Set the base URL to Bespoke Labs, the key to your Bespoke Labs key, and the model to `nimble-latest`.

```python theme={null}
import os

from typesafe_sdk import TypeSafeClient

client = TypeSafeClient(
    api_key=os.environ["BESPOKE_API_KEY"],
    base_url="https://api.bespokelabs.ai",
    model="nimble-latest",
)
```

You can also set these with environment variables and create the client with no arguments.

```bash theme={null}
export TYPESAFE_API_KEY="$BESPOKE_API_KEY"
export TYPESAFE_BASE_URL="https://api.bespokelabs.ai"
export TYPESAFE_DEFAULT_MODEL="nimble-latest"
```

## Ask questions

```python theme={null}
from typesafe_sdk import Choice, Noul, Score

response = client.system_one(
    "The customer was charged twice and asks for a refund. The service still works.",
    {
        "refund": Noul(instructions="Does the customer request a refund?"),
        "department": Choice(
            instructions="Which department should handle this request?",
            criteria={
                "billing": "Charges, payments and refunds",
                "technical": "Software bugs and outages",
            },
        ),
        "urgency": Score(
            instructions="How urgent is this request?",
            criteria=[
                "Routine billing request; service works",
                "Some functionality unavailable",
                "Complete service outage",
            ],
        ),
    },
)

print(response.answers["refund"].noul)
print(response.answers["department"].choice)
print(response.answers["urgency"].score)
```

## Choose a model for one request

The client's `model` is the default for every request. Pass `model` to `system_one` to use another model for one request, e.g., fact check.

```python theme={null}
response = client.system_one(
    "The board moved the vote to Tuesday because the CFO was travelling.",
    {
        "moved": Noul(instructions="The vote was moved to Tuesday."),
        "ceo": Noul(instructions="The CEO was travelling."),
    },
    model="nimble-factcheck",
)

print(response.answers["moved"].noul)
```

The [overview](/nimble/overview) lists every model name.

## Async

```python theme={null}
import asyncio
import os

from typesafe_sdk import AsyncTypeSafeClient, Noul


async def main():
    async with AsyncTypeSafeClient(
        api_key=os.environ["BESPOKE_API_KEY"],
        base_url="https://api.bespokelabs.ai",
        model="nimble-latest",
    ) as client:
        response = await client.system_one(
            "The service has been down for an hour.",
            {"outage": Noul(instructions="Is the service down?")},
        )
        print(response.answers["outage"].noul)


asyncio.run(main())
```
