teren de test TypeSafe: docs offline + script de proba

Separat de produsele ROA. docs/ = documentatia oficiala descarcata ca Markdown
(111 pagini), reluabila cu update_docs.sh. typesafe_test.py face un apel cu cate
o intrebare din fiecare tip (choice/noul/score) pe o linie de factura de furnizor.
Cheia API se ia din TYPESAFE_API_KEY, nu se versioneaza.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KHLUSsKP99G6ebv2fFUKQV
This commit is contained in:
2026-09-17 21:47:19 +03:00
commit 2d012a969c
116 changed files with 25116 additions and 0 deletions

42
docs/sdk/javascript.md Normal file
View File

@@ -0,0 +1,42 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# JavaScript SDK
JavaScript and TypeScript SDK for [TypeSafe AI](https://typesafe.ai).
## Quickstart
Install the SDK (Node.js 20 or newer):
```sh theme={null}
npm install @typesafe-ai/sdk
```
Set `TYPESAFE_API_KEY` in your environment, then create and use the client:
```ts theme={null}
import { choice, TypeSafeClient } from "@typesafe-ai/sdk";
const client = new TypeSafeClient();
const response = await client.systemOne({
state: { document: "I was charged twice. Please fix this ASAP." },
questions: {
category: choice("What is this ticket about?", {
billing: null,
technical: null,
other: null,
}),
},
});
console.log(response.answers.category.choice);
```
Answer types are inferred from your questions. The package includes ESM, CommonJS, and TypeScript declarations.
## Documentation
Learn what TypeSafe can do in the [TypeSafe docs](https://docs.typesafe.ai/).
See the SDK's [client](https://github.com/typesafe-ai/typesafe-sdk-js/blob/v0.6.0/src/client.ts) and [types](https://github.com/typesafe-ai/typesafe-sdk-js/blob/v0.6.0/src/types.ts) for API options and defaults.

View File

@@ -0,0 +1,70 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# API reference
## Classes
* [APIConnectionError](/sdk/javascript/api/classes/APIConnectionError)
* [APIError](/sdk/javascript/api/classes/APIError)
* [APIPromise](/sdk/javascript/api/classes/APIPromise)
* [APITimeoutError](/sdk/javascript/api/classes/APITimeoutError)
* [APIUserAbortError](/sdk/javascript/api/classes/APIUserAbortError)
* [AuthenticationError](/sdk/javascript/api/classes/AuthenticationError)
* [BadRequestError](/sdk/javascript/api/classes/BadRequestError)
* [InternalServerError](/sdk/javascript/api/classes/InternalServerError)
* [NotFoundError](/sdk/javascript/api/classes/NotFoundError)
* [PermissionDeniedError](/sdk/javascript/api/classes/PermissionDeniedError)
* [RateLimitError](/sdk/javascript/api/classes/RateLimitError)
* [TypeSafeClient](/sdk/javascript/api/classes/TypeSafeClient)
* [TypeSafeError](/sdk/javascript/api/classes/TypeSafeError)
* [UnprocessableEntityError](/sdk/javascript/api/classes/UnprocessableEntityError)
## Interfaces
* [ChoiceQuestion](/sdk/javascript/api/interfaces/ChoiceQuestion)
* [ChoiceResponse](/sdk/javascript/api/interfaces/ChoiceResponse)
* [Logger](/sdk/javascript/api/interfaces/Logger)
* [ModelCard](/sdk/javascript/api/interfaces/ModelCard)
* [Models](/sdk/javascript/api/interfaces/Models)
* [NoulQuestion](/sdk/javascript/api/interfaces/NoulQuestion)
* [NoulResponse](/sdk/javascript/api/interfaces/NoulResponse)
* [Questions](/sdk/javascript/api/interfaces/Questions)
* [RequestOptions](/sdk/javascript/api/interfaces/RequestOptions)
* [RetryPolicy](/sdk/javascript/api/interfaces/RetryPolicy)
* [ScoreQuestion](/sdk/javascript/api/interfaces/ScoreQuestion)
* [ScoreResponse](/sdk/javascript/api/interfaces/ScoreResponse)
* [SystemOneRequest](/sdk/javascript/api/interfaces/SystemOneRequest)
* [SystemOneRequestPayload](/sdk/javascript/api/interfaces/SystemOneRequestPayload)
* [SystemOneResult](/sdk/javascript/api/interfaces/SystemOneResult)
* [TypeSafeClientConfig](/sdk/javascript/api/interfaces/TypeSafeClientConfig)
* [Usage](/sdk/javascript/api/interfaces/Usage)
* [WithResponse](/sdk/javascript/api/interfaces/WithResponse)
## Type Aliases
* [ChoiceCriteria](/sdk/javascript/api/type-aliases/ChoiceCriteria)
* [Description](/sdk/javascript/api/type-aliases/Description)
* [EntryType](/sdk/javascript/api/type-aliases/EntryType)
* [EnvVar](/sdk/javascript/api/type-aliases/EnvVar)
* [Fetch](/sdk/javascript/api/type-aliases/Fetch)
* [JsonValue](/sdk/javascript/api/type-aliases/JsonValue)
* [LogLevel](/sdk/javascript/api/type-aliases/LogLevel)
* [Question](/sdk/javascript/api/type-aliases/Question)
* [ResultFor](/sdk/javascript/api/type-aliases/ResultFor)
* [ScoreCriteria](/sdk/javascript/api/type-aliases/ScoreCriteria)
* [ScoreLegend](/sdk/javascript/api/type-aliases/ScoreLegend)
* [ScoreOf](/sdk/javascript/api/type-aliases/ScoreOf)
## Variables
* [ENV](/sdk/javascript/api/variables/ENV)
* [LOG\_LEVELS](/sdk/javascript/api/variables/LOG_LEVELS)
* [VERSION](/sdk/javascript/api/variables/VERSION)
## Functions
* [choice](/sdk/javascript/api/functions/choice)
* [noul](/sdk/javascript/api/functions/noul)
* [score](/sdk/javascript/api/functions/score)

View File

@@ -0,0 +1,43 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: APIConnectionError
The request or response-body delivery failed (DNS, TLS, connection closed, etc.).
## Extends
* [`TypeSafeError`](/sdk/javascript/api/classes/TypeSafeError)
## Extended by
* [`APITimeoutError`](/sdk/javascript/api/classes/APITimeoutError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new APIConnectionError(message?, options?): APIConnectionError;
```
#### Parameters
##### message?
`string` = `"Connection error."`
##### options?
`ErrorOptions`
#### Returns
`APIConnectionError`
#### Overrides
[`TypeSafeError`](/sdk/javascript/api/classes/TypeSafeError).[`constructor`](/sdk/javascript/api/classes/TypeSafeError#sdk-constructor)

View File

@@ -0,0 +1,144 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: APIError
An unsuccessful HTTP response from the API.
## Extends
* [`TypeSafeError`](/sdk/javascript/api/classes/TypeSafeError)
## Extended by
* [`AuthenticationError`](/sdk/javascript/api/classes/AuthenticationError)
* [`BadRequestError`](/sdk/javascript/api/classes/BadRequestError)
* [`InternalServerError`](/sdk/javascript/api/classes/InternalServerError)
* [`NotFoundError`](/sdk/javascript/api/classes/NotFoundError)
* [`PermissionDeniedError`](/sdk/javascript/api/classes/PermissionDeniedError)
* [`RateLimitError`](/sdk/javascript/api/classes/RateLimitError)
* [`UnprocessableEntityError`](/sdk/javascript/api/classes/UnprocessableEntityError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new APIError(
status,
body,
headers,
message?
): APIError;
```
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
##### message?
`string`
#### Returns
`APIError`
#### Overrides
[`TypeSafeError`](/sdk/javascript/api/classes/TypeSafeError).[`constructor`](/sdk/javascript/api/classes/TypeSafeError#sdk-constructor)
## Properties
<a id="sdk-body" />
### body
```ts theme={null}
readonly body: unknown;
```
Parsed JSON, response text, or `undefined` for an empty body.
***
<a id="sdk-headers" />
### headers
```ts theme={null}
readonly headers: Headers;
```
HTTP response headers.
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
readonly requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
***
<a id="sdk-status" />
### status
```ts theme={null}
readonly status: number;
```
HTTP response status code.
## Methods
<a id="sdk-fromresponse" />
### fromResponse()
```ts theme={null}
static fromResponse(
status,
body,
headers
): APIError;
```
Create the error subclass for an HTTP status code.
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
#### Returns
`APIError`

View File

@@ -0,0 +1,230 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: APIPromise<T>
A promise for the parsed result with access to the HTTP response.
Non-2xx responses reject with an `APIError`, including through `asResponse()`.
## Extends
* `Promise`\<`T`>
## Type Parameters
### T
`T`
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new APIPromise<T>(responsePromise, parseResponse): APIPromise<T>;
```
#### Parameters
##### responsePromise
`Promise`\<`Response`>
##### parseResponse
(`response`) => `Promise`\<`T`>
#### Returns
`APIPromise`\<`T`>
#### Overrides
```ts theme={null}
Promise<T>.constructor
```
## Methods
<a id="sdk-asresponse" />
### asResponse()
```ts theme={null}
asResponse(): Promise<Response>;
```
Resolves to the raw `Response` without parsing the body. SDK requests buffer the full
body under the request timeout before handoff; reading it afterwards is caller-owned.
The caller owns the body; don't also `await` the parsed result on the same promise.
#### Returns
`Promise`\<`Response`>
***
<a id="sdk-catch" />
### catch()
```ts theme={null}
catch<TResult>(onrejected?): Promise<T | TResult>;
```
Attaches a callback for only the rejection of the Promise.
#### Type Parameters
##### TResult
`TResult` = `never`
#### Parameters
##### onrejected?
((`reason`) => `TResult` | `PromiseLike`\<`TResult`>) | `null`
The callback to execute when the Promise is rejected.
#### Returns
`Promise`\<`T` | `TResult`>
A Promise for the completion of the callback.
#### Overrides
```ts theme={null}
Promise.catch
```
***
<a id="sdk-finally" />
### finally()
```ts theme={null}
finally(onfinally?): Promise<T>;
```
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
resolved value cannot be modified from the callback.
#### Parameters
##### onfinally?
(() => `void`) | `null`
The callback to execute when the Promise is settled (fulfilled or rejected).
#### Returns
`Promise`\<`T`>
A Promise for the completion of the callback.
#### Overrides
```ts theme={null}
Promise.finally
```
***
<a id="sdk-map" />
### map()
```ts theme={null}
map<U>(fn): APIPromise<U>;
```
Transform the parsed result, sharing the HTTP response and a single body parse.
#### Type Parameters
##### U
`U`
#### Parameters
##### fn
(`data`) => `U`
#### Returns
`APIPromise`\<`U`>
***
<a id="sdk-then" />
### then()
```ts theme={null}
then<TResult1, TResult2>(onfulfilled?, onrejected?): Promise<TResult1 | TResult2>;
```
Attaches callbacks for the resolution and/or rejection of the Promise.
#### Type Parameters
##### TResult1
`TResult1` = `T`
##### TResult2
`TResult2` = `never`
#### Parameters
##### onfulfilled?
((`value`) => `TResult1` | `PromiseLike`\<`TResult1`>) | `null`
The callback to execute when the Promise is resolved.
##### onrejected?
((`reason`) => `TResult2` | `PromiseLike`\<`TResult2`>) | `null`
The callback to execute when the Promise is rejected.
#### Returns
`Promise`\<`TResult1` | `TResult2`>
A Promise for the completion of which ever callback is executed.
#### Overrides
```ts theme={null}
Promise.then
```
***
<a id="sdk-withresponse" />
### withResponse()
```ts theme={null}
withResponse(): Promise<WithResponse<T>>;
```
Return the parsed result, HTTP response, and request ID.
#### Returns
`Promise`\<[`WithResponse`](/sdk/javascript/api/interfaces/WithResponse)\<`T`>>

View File

@@ -0,0 +1,51 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: APITimeoutError
The full response did not arrive within the timeout. A kind of `APIConnectionError`.
## Extends
* [`APIConnectionError`](/sdk/javascript/api/classes/APIConnectionError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new APITimeoutError(timeoutMs, options?): APITimeoutError;
```
#### Parameters
##### timeoutMs
`number`
##### options?
`ErrorOptions`
#### Returns
`APITimeoutError`
#### Overrides
[`APIConnectionError`](/sdk/javascript/api/classes/APIConnectionError).[`constructor`](/sdk/javascript/api/classes/APIConnectionError#sdk-constructor)
## Properties
<a id="sdk-timeoutms" />
### timeoutMs
```ts theme={null}
readonly timeoutMs: number;
```
Configured timeout in milliseconds.

View File

@@ -0,0 +1,39 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: APIUserAbortError
The caller cancelled the request through an `AbortSignal`.
## Extends
* [`TypeSafeError`](/sdk/javascript/api/classes/TypeSafeError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new APIUserAbortError(message?, options?): APIUserAbortError;
```
#### Parameters
##### message?
`string` = `"Request was aborted."`
##### options?
`ErrorOptions`
#### Returns
`APIUserAbortError`
#### Overrides
[`TypeSafeError`](/sdk/javascript/api/classes/TypeSafeError).[`constructor`](/sdk/javascript/api/classes/TypeSafeError#sdk-constructor)

View File

@@ -0,0 +1,154 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: AuthenticationError
HTTP 401: authentication failed.
## Extends
* [`APIError`](/sdk/javascript/api/classes/APIError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new AuthenticationError(
status,
body,
headers,
message?
): AuthenticationError;
```
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
##### message?
`string`
#### Returns
`AuthenticationError`
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`constructor`](/sdk/javascript/api/classes/APIError#sdk-constructor)
## Properties
<a id="sdk-body" />
### body
```ts theme={null}
readonly body: unknown;
```
Parsed JSON, response text, or `undefined` for an empty body.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`body`](/sdk/javascript/api/classes/APIError#sdk-body)
***
<a id="sdk-headers" />
### headers
```ts theme={null}
readonly headers: Headers;
```
HTTP response headers.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`headers`](/sdk/javascript/api/classes/APIError#sdk-headers)
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
readonly requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`requestId`](/sdk/javascript/api/classes/APIError#sdk-requestid)
***
<a id="sdk-status" />
### status
```ts theme={null}
readonly status: number;
```
HTTP response status code.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`status`](/sdk/javascript/api/classes/APIError#sdk-status)
## Methods
<a id="sdk-fromresponse" />
### fromResponse()
```ts theme={null}
static fromResponse(
status,
body,
headers
): APIError;
```
Create the error subclass for an HTTP status code.
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
#### Returns
[`APIError`](/sdk/javascript/api/classes/APIError)
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`fromResponse`](/sdk/javascript/api/classes/APIError#sdk-fromresponse)

View File

@@ -0,0 +1,154 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: BadRequestError
HTTP 400: the request is invalid.
## Extends
* [`APIError`](/sdk/javascript/api/classes/APIError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new BadRequestError(
status,
body,
headers,
message?
): BadRequestError;
```
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
##### message?
`string`
#### Returns
`BadRequestError`
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`constructor`](/sdk/javascript/api/classes/APIError#sdk-constructor)
## Properties
<a id="sdk-body" />
### body
```ts theme={null}
readonly body: unknown;
```
Parsed JSON, response text, or `undefined` for an empty body.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`body`](/sdk/javascript/api/classes/APIError#sdk-body)
***
<a id="sdk-headers" />
### headers
```ts theme={null}
readonly headers: Headers;
```
HTTP response headers.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`headers`](/sdk/javascript/api/classes/APIError#sdk-headers)
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
readonly requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`requestId`](/sdk/javascript/api/classes/APIError#sdk-requestid)
***
<a id="sdk-status" />
### status
```ts theme={null}
readonly status: number;
```
HTTP response status code.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`status`](/sdk/javascript/api/classes/APIError#sdk-status)
## Methods
<a id="sdk-fromresponse" />
### fromResponse()
```ts theme={null}
static fromResponse(
status,
body,
headers
): APIError;
```
Create the error subclass for an HTTP status code.
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
#### Returns
[`APIError`](/sdk/javascript/api/classes/APIError)
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`fromResponse`](/sdk/javascript/api/classes/APIError#sdk-fromresponse)

View File

@@ -0,0 +1,154 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: InternalServerError
HTTP 5xx: the server failed to handle the request.
## Extends
* [`APIError`](/sdk/javascript/api/classes/APIError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new InternalServerError(
status,
body,
headers,
message?
): InternalServerError;
```
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
##### message?
`string`
#### Returns
`InternalServerError`
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`constructor`](/sdk/javascript/api/classes/APIError#sdk-constructor)
## Properties
<a id="sdk-body" />
### body
```ts theme={null}
readonly body: unknown;
```
Parsed JSON, response text, or `undefined` for an empty body.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`body`](/sdk/javascript/api/classes/APIError#sdk-body)
***
<a id="sdk-headers" />
### headers
```ts theme={null}
readonly headers: Headers;
```
HTTP response headers.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`headers`](/sdk/javascript/api/classes/APIError#sdk-headers)
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
readonly requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`requestId`](/sdk/javascript/api/classes/APIError#sdk-requestid)
***
<a id="sdk-status" />
### status
```ts theme={null}
readonly status: number;
```
HTTP response status code.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`status`](/sdk/javascript/api/classes/APIError#sdk-status)
## Methods
<a id="sdk-fromresponse" />
### fromResponse()
```ts theme={null}
static fromResponse(
status,
body,
headers
): APIError;
```
Create the error subclass for an HTTP status code.
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
#### Returns
[`APIError`](/sdk/javascript/api/classes/APIError)
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`fromResponse`](/sdk/javascript/api/classes/APIError#sdk-fromresponse)

View File

@@ -0,0 +1,154 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: NotFoundError
HTTP 404: the resource was not found.
## Extends
* [`APIError`](/sdk/javascript/api/classes/APIError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new NotFoundError(
status,
body,
headers,
message?
): NotFoundError;
```
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
##### message?
`string`
#### Returns
`NotFoundError`
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`constructor`](/sdk/javascript/api/classes/APIError#sdk-constructor)
## Properties
<a id="sdk-body" />
### body
```ts theme={null}
readonly body: unknown;
```
Parsed JSON, response text, or `undefined` for an empty body.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`body`](/sdk/javascript/api/classes/APIError#sdk-body)
***
<a id="sdk-headers" />
### headers
```ts theme={null}
readonly headers: Headers;
```
HTTP response headers.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`headers`](/sdk/javascript/api/classes/APIError#sdk-headers)
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
readonly requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`requestId`](/sdk/javascript/api/classes/APIError#sdk-requestid)
***
<a id="sdk-status" />
### status
```ts theme={null}
readonly status: number;
```
HTTP response status code.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`status`](/sdk/javascript/api/classes/APIError#sdk-status)
## Methods
<a id="sdk-fromresponse" />
### fromResponse()
```ts theme={null}
static fromResponse(
status,
body,
headers
): APIError;
```
Create the error subclass for an HTTP status code.
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
#### Returns
[`APIError`](/sdk/javascript/api/classes/APIError)
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`fromResponse`](/sdk/javascript/api/classes/APIError#sdk-fromresponse)

View File

@@ -0,0 +1,154 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: PermissionDeniedError
HTTP 403: access is denied.
## Extends
* [`APIError`](/sdk/javascript/api/classes/APIError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new PermissionDeniedError(
status,
body,
headers,
message?
): PermissionDeniedError;
```
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
##### message?
`string`
#### Returns
`PermissionDeniedError`
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`constructor`](/sdk/javascript/api/classes/APIError#sdk-constructor)
## Properties
<a id="sdk-body" />
### body
```ts theme={null}
readonly body: unknown;
```
Parsed JSON, response text, or `undefined` for an empty body.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`body`](/sdk/javascript/api/classes/APIError#sdk-body)
***
<a id="sdk-headers" />
### headers
```ts theme={null}
readonly headers: Headers;
```
HTTP response headers.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`headers`](/sdk/javascript/api/classes/APIError#sdk-headers)
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
readonly requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`requestId`](/sdk/javascript/api/classes/APIError#sdk-requestid)
***
<a id="sdk-status" />
### status
```ts theme={null}
readonly status: number;
```
HTTP response status code.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`status`](/sdk/javascript/api/classes/APIError#sdk-status)
## Methods
<a id="sdk-fromresponse" />
### fromResponse()
```ts theme={null}
static fromResponse(
status,
body,
headers
): APIError;
```
Create the error subclass for an HTTP status code.
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
#### Returns
[`APIError`](/sdk/javascript/api/classes/APIError)
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`fromResponse`](/sdk/javascript/api/classes/APIError#sdk-fromresponse)

View File

@@ -0,0 +1,166 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: RateLimitError
HTTP 429: the rate limit was exceeded.
## Extends
* [`APIError`](/sdk/javascript/api/classes/APIError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new RateLimitError(
status,
body,
headers,
message?
): RateLimitError;
```
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
##### message?
`string`
#### Returns
`RateLimitError`
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`constructor`](/sdk/javascript/api/classes/APIError#sdk-constructor)
## Properties
<a id="sdk-body" />
### body
```ts theme={null}
readonly body: unknown;
```
Parsed JSON, response text, or `undefined` for an empty body.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`body`](/sdk/javascript/api/classes/APIError#sdk-body)
***
<a id="sdk-headers" />
### headers
```ts theme={null}
readonly headers: Headers;
```
HTTP response headers.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`headers`](/sdk/javascript/api/classes/APIError#sdk-headers)
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
readonly requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`requestId`](/sdk/javascript/api/classes/APIError#sdk-requestid)
***
<a id="sdk-retryafterms" />
### retryAfterMs
```ts theme={null}
readonly retryAfterMs: number | undefined;
```
Server retry delay in milliseconds, or `undefined` when absent or invalid.
***
<a id="sdk-status" />
### status
```ts theme={null}
readonly status: number;
```
HTTP response status code.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`status`](/sdk/javascript/api/classes/APIError#sdk-status)
## Methods
<a id="sdk-fromresponse" />
### fromResponse()
```ts theme={null}
static fromResponse(
status,
body,
headers
): APIError;
```
Create the error subclass for an HTTP status code.
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
#### Returns
[`APIError`](/sdk/javascript/api/classes/APIError)
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`fromResponse`](/sdk/javascript/api/classes/APIError#sdk-fromresponse)

View File

@@ -0,0 +1,208 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: TypeSafeClient
Client for the TypeSafe AI API.
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new TypeSafeClient(config?): TypeSafeClient;
```
Create a client for the TypeSafe AI API.
Explicit options take precedence over environment variables, then SDK defaults.
Empty or whitespace-only environment values are ignored.
#### Parameters
##### config?
[`TypeSafeClientConfig`](/sdk/javascript/api/interfaces/TypeSafeClientConfig) = `{}`
#### Returns
`TypeSafeClient`
#### Throws
The API key is missing, configuration is invalid, or the runtime is unsupported.
## Properties
<a id="sdk-baseurl" />
### baseURL
```ts theme={null}
readonly baseURL: string;
```
API root with trailing slashes removed.
***
<a id="sdk-defaultheaders" />
### defaultHeaders
```ts theme={null}
readonly defaultHeaders: Readonly<Record<string, string>>;
```
Additional headers sent with each request.
***
<a id="sdk-defaultmodel" />
### defaultModel
```ts theme={null}
readonly defaultModel: string;
```
Model used when a request omits `model`.
***
<a id="sdk-fetch" />
### fetch
```ts theme={null}
readonly fetch: Fetch;
```
HTTP fetch implementation.
***
<a id="sdk-logger" />
### logger
```ts theme={null}
readonly logger: Logger;
```
The configured logger, filtered to `logLevel`.
***
<a id="sdk-loglevel" />
### logLevel
```ts theme={null}
readonly logLevel: LogLevel;
```
Configured log verbosity.
***
<a id="sdk-models" />
### models
```ts theme={null}
readonly models: Models;
```
The models available to the account.
***
<a id="sdk-retry" />
### retry
```ts theme={null}
readonly retry: RetryPolicy;
```
Retry settings with constructor overrides applied.
***
<a id="sdk-timeout" />
### timeout
```ts theme={null}
readonly timeout: number;
```
Timeout per attempt in milliseconds.
## Methods
<a id="sdk-systemone" />
### systemOne()
```ts theme={null}
systemOne<Q>(request, options?): APIPromise<SystemOneResult<Q>>;
```
Answer named questions about text or structured state.
#### Type Parameters
##### Q
`Q` *extends* [`Questions`](/sdk/javascript/api/interfaces/Questions)
#### Parameters
##### request
[`SystemOneRequest`](/sdk/javascript/api/interfaces/SystemOneRequest)\<`Q`>
State, questions, and an optional model override.
##### options?
[`RequestOptions`](/sdk/javascript/api/interfaces/RequestOptions) = `{}`
Per-call timeout, retry, headers, and cancellation settings.
#### Returns
[`APIPromise`](/sdk/javascript/api/classes/APIPromise)\<[`SystemOneResult`](/sdk/javascript/api/interfaces/SystemOneResult)\<`Q`>>
Answers typed by question name and criteria, with model and token usage.
#### Throws
Questions are empty, or score criteria are not a list of at least two entries.
#### Throws
The server returns a non-2xx response after retries.
#### Throws
The request cannot connect or times out after retries.
#### Throws
The caller aborts the request.
#### Example
```ts theme={null}
const { answers } = await client.systemOne({
state: "I was charged twice. Please help.",
questions: { billing: noul("Is this about billing?") },
});
console.log(answers.billing.noul);
```

View File

@@ -0,0 +1,47 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: TypeSafeError
Base class for SDK errors.
## Extends
* `Error`
## Extended by
* [`APIConnectionError`](/sdk/javascript/api/classes/APIConnectionError)
* [`APIError`](/sdk/javascript/api/classes/APIError)
* [`APIUserAbortError`](/sdk/javascript/api/classes/APIUserAbortError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new TypeSafeError(message, options?): TypeSafeError;
```
#### Parameters
##### message
`string`
##### options?
`ErrorOptions`
#### Returns
`TypeSafeError`
#### Overrides
```ts theme={null}
Error.constructor
```

View File

@@ -0,0 +1,154 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Class: UnprocessableEntityError
HTTP 422: request validation failed.
## Extends
* [`APIError`](/sdk/javascript/api/classes/APIError)
## Constructors
<a id="sdk-constructor" />
### Constructor
```ts theme={null}
new UnprocessableEntityError(
status,
body,
headers,
message?
): UnprocessableEntityError;
```
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
##### message?
`string`
#### Returns
`UnprocessableEntityError`
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`constructor`](/sdk/javascript/api/classes/APIError#sdk-constructor)
## Properties
<a id="sdk-body" />
### body
```ts theme={null}
readonly body: unknown;
```
Parsed JSON, response text, or `undefined` for an empty body.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`body`](/sdk/javascript/api/classes/APIError#sdk-body)
***
<a id="sdk-headers" />
### headers
```ts theme={null}
readonly headers: Headers;
```
HTTP response headers.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`headers`](/sdk/javascript/api/classes/APIError#sdk-headers)
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
readonly requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`requestId`](/sdk/javascript/api/classes/APIError#sdk-requestid)
***
<a id="sdk-status" />
### status
```ts theme={null}
readonly status: number;
```
HTTP response status code.
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`status`](/sdk/javascript/api/classes/APIError#sdk-status)
## Methods
<a id="sdk-fromresponse" />
### fromResponse()
```ts theme={null}
static fromResponse(
status,
body,
headers
): APIError;
```
Create the error subclass for an HTTP status code.
#### Parameters
##### status
`number`
##### body
`unknown`
##### headers
`Headers`
#### Returns
[`APIError`](/sdk/javascript/api/classes/APIError)
#### Inherited from
[`APIError`](/sdk/javascript/api/classes/APIError).[`fromResponse`](/sdk/javascript/api/classes/APIError#sdk-fromresponse)

View File

@@ -0,0 +1,35 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Function: choice()
```ts theme={null}
function choice<T>(instructions, criteria): ChoiceQuestion<T>;
```
Create a question that selects between named alternatives.
## Type Parameters
### T
`T` *extends* [`ChoiceCriteria`](/sdk/javascript/api/type-aliases/ChoiceCriteria)
## Parameters
### instructions
[`EntryType`](/sdk/javascript/api/type-aliases/EntryType)
The question as text, a JSON object or array, or `null`.
### criteria
`T`
Labels mapped to descriptions, or `null` for undescribed labels.
## Returns
[`ChoiceQuestion`](/sdk/javascript/api/interfaces/ChoiceQuestion)\<`T`>

View File

@@ -0,0 +1,58 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Function: noul()
```ts theme={null}
function noul(instructions?, criteria?): NoulQuestion;
```
Create a yes/no question with optional descriptions for either outcome.
## Parameters
### instructions?
[`EntryType`](/sdk/javascript/api/type-aliases/EntryType) = `null`
The question as text, a JSON object or array; defaults to `null`.
### criteria?
\| \{
`false?`: [`EntryType`](/sdk/javascript/api/type-aliases/EntryType);
`true?`: [`EntryType`](/sdk/javascript/api/type-aliases/EntryType);
}
\| `null`
Optional descriptions of the yes and no outcomes.
#### Type Literal
\{
`false?`: [`EntryType`](/sdk/javascript/api/type-aliases/EntryType);
`true?`: [`EntryType`](/sdk/javascript/api/type-aliases/EntryType);
}
Optional descriptions of the yes and no outcomes.
##### false?
[`EntryType`](/sdk/javascript/api/type-aliases/EntryType)
Description of the no outcome.
##### true?
[`EntryType`](/sdk/javascript/api/type-aliases/EntryType)
Description of the yes outcome.
***
`null`
## Returns
[`NoulQuestion`](/sdk/javascript/api/interfaces/NoulQuestion)

View File

@@ -0,0 +1,35 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Function: score()
```ts theme={null}
function score<T>(instructions, criteria): ScoreQuestion<T>;
```
Create a score question using an ordered rubric.
## Type Parameters
### T
`T` *extends* [`ScoreCriteria`](/sdk/javascript/api/type-aliases/ScoreCriteria)
## Parameters
### instructions
[`EntryType`](/sdk/javascript/api/type-aliases/EntryType)
The question as text, a JSON object or array, or `null`.
### criteria
`T`
At least two descriptions indexed by score from zero; entries may be `null`.
## Returns
[`ScoreQuestion`](/sdk/javascript/api/interfaces/ScoreQuestion)\<`T`>

View File

@@ -0,0 +1,47 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: ChoiceQuestion<T>
A question that selects between named alternatives.
## Type Parameters
### T
`T` *extends* [`ChoiceCriteria`](/sdk/javascript/api/type-aliases/ChoiceCriteria) = [`ChoiceCriteria`](/sdk/javascript/api/type-aliases/ChoiceCriteria)
## Properties
<a id="sdk-criteria" />
### criteria
```ts theme={null}
criteria: T;
```
Descriptions of the available outcomes.
***
<a id="sdk-instructions" />
### instructions?
```ts theme={null}
optional instructions?: EntryType;
```
The question as text, a JSON object, or an array; optional or `null`.
***
<a id="sdk-type" />
### type
```ts theme={null}
type: "choice";
```

View File

@@ -0,0 +1,59 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: ChoiceResponse<T>
A selected label and its probabilities.
## Type Parameters
### T
`T` *extends* [`ChoiceCriteria`](/sdk/javascript/api/type-aliases/ChoiceCriteria) = [`ChoiceCriteria`](/sdk/javascript/api/type-aliases/ChoiceCriteria)
## Properties
<a id="sdk-choice" />
### choice
```ts theme={null}
readonly choice: keyof T & string;
```
The selected label.
***
<a id="sdk-confidence" />
### confidence
```ts theme={null}
readonly confidence: number;
```
Reported confidence in the selected label.
***
<a id="sdk-probabilities" />
### probabilities
```ts theme={null}
readonly probabilities: { readonly [label in string | number | symbol]: number };
```
Probabilities keyed by label.
***
<a id="sdk-type" />
### type
```ts theme={null}
readonly type: "choice";
```

View File

@@ -0,0 +1,103 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: Logger
Log methods accepting a message and structured values; compatible with `console`.
## Methods
<a id="sdk-debug" />
### debug()
```ts theme={null}
debug(message, ...args): void;
```
#### Parameters
##### message
`string`
##### args
...`unknown`\[]
#### Returns
`void`
***
<a id="sdk-error" />
### error()
```ts theme={null}
error(message, ...args): void;
```
#### Parameters
##### message
`string`
##### args
...`unknown`\[]
#### Returns
`void`
***
<a id="sdk-info" />
### info()
```ts theme={null}
info(message, ...args): void;
```
#### Parameters
##### message
`string`
##### args
...`unknown`\[]
#### Returns
`void`
***
<a id="sdk-warn" />
### warn()
```ts theme={null}
warn(message, ...args): void;
```
#### Parameters
##### message
`string`
##### args
...`unknown`\[]
#### Returns
`void`

View File

@@ -0,0 +1,37 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: ModelCard
Metadata for an available model.
## Properties
<a id="sdk-description" />
### description
```ts theme={null}
readonly description: string;
```
***
<a id="sdk-name" />
### name
```ts theme={null}
readonly name: string;
```
***
<a id="sdk-release_date" />
### release\_date
```ts theme={null}
readonly release_date: string;
```

View File

@@ -0,0 +1,29 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: Models
Access to the Models API resource.
## Methods
<a id="sdk-list" />
### list()
```ts theme={null}
list(options?): APIPromise<ModelCard[]>;
```
List the models available to the account.
#### Parameters
##### options?
[`RequestOptions`](/sdk/javascript/api/interfaces/RequestOptions) = `{}`
#### Returns
[`APIPromise`](/sdk/javascript/api/classes/APIPromise)\<[`ModelCard`](/sdk/javascript/api/interfaces/ModelCard)\[]>

View File

@@ -0,0 +1,77 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: NoulQuestion
A yes/no question with optional descriptions for either outcome.
## Properties
<a id="sdk-criteria" />
### criteria?
```ts theme={null}
optional criteria?:
| {
false?: EntryType;
true?: EntryType;
}
| null;
```
Optional descriptions of the yes and no outcomes.
#### Union Members
##### Type Literal
```ts theme={null}
{
false?: EntryType;
true?: EntryType;
}
```
##### false?
```ts theme={null}
optional false?: EntryType;
```
Description of the no outcome.
##### true?
```ts theme={null}
optional true?: EntryType;
```
Description of the yes outcome.
***
`null`
***
<a id="sdk-instructions" />
### instructions?
```ts theme={null}
optional instructions?: EntryType;
```
The question as text, a JSON object, or an array; optional or `null`.
***
<a id="sdk-type" />
### type
```ts theme={null}
type: "noul";
```

View File

@@ -0,0 +1,29 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: NoulResponse
A yes/no answer.
## Properties
<a id="sdk-noul" />
### noul
```ts theme={null}
readonly noul: number;
```
Probability of a yes answer, from zero to one.
***
<a id="sdk-type" />
### type
```ts theme={null}
readonly type: "noul";
```

View File

@@ -0,0 +1,13 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: Questions
Questions keyed by the names used to identify their answers.
## Indexable
```ts theme={null}
[name: string]: Question
```

View File

@@ -0,0 +1,55 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: RequestOptions
Per-call options that override client settings.
## Properties
<a id="sdk-headers" />
### headers?
```ts theme={null}
optional headers?: Record<string, string>;
```
Additional headers, merged over `defaultHeaders`.
***
<a id="sdk-retry" />
### retry?
```ts theme={null}
optional retry?: Partial<RetryPolicy>;
```
Retry overrides for this call; omitted fields inherit client settings.
***
<a id="sdk-signal" />
### signal?
```ts theme={null}
optional signal?: AbortSignal;
```
Cancellation signal for the request and pending retries.
***
<a id="sdk-timeout" />
### timeout?
```ts theme={null}
optional timeout?: number;
```
Timeout per attempt in milliseconds; there is no total retry budget.

View File

@@ -0,0 +1,115 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: RetryPolicy
Retry configuration. Partial overrides inherit unset fields from the client or SDK defaults.
## Properties
<a id="sdk-apiconnectionerror" />
### apiConnectionError
```ts theme={null}
readonly apiConnectionError: boolean;
```
Retry connection failures, including interrupted response bodies (`APIConnectionError`). Default: true.
***
<a id="sdk-apitimeouterror" />
### apiTimeoutError
```ts theme={null}
readonly apiTimeoutError: boolean;
```
Whether to retry `APITimeoutError`. Default: true.
***
<a id="sdk-backoffinitialms" />
### backoffInitialMs
```ts theme={null}
readonly backoffInitialMs: number;
```
First backoff delay in milliseconds, doubled up to `backoffMaxMs`. Default: 500.
***
<a id="sdk-backoffjitter" />
### backoffJitter
```ts theme={null}
readonly backoffJitter: number;
```
Fraction of each backoff delay randomly subtracted, from 0 to 1. Default: 0.25.
***
<a id="sdk-backoffmaxms" />
### backoffMaxMs
```ts theme={null}
readonly backoffMaxMs: number;
```
Maximum backoff delay in milliseconds. Default: 5000.
***
<a id="sdk-httpstatuses" />
### httpStatuses
```ts theme={null}
readonly httpStatuses: ReadonlySet<number>;
```
HTTP status codes to retry. Default: 408, 429, and 500–599.
***
<a id="sdk-maxretries" />
### maxRetries
```ts theme={null}
readonly maxRetries: number;
```
Maximum retries after the initial attempt; `0` disables retries. Default: 2.
***
<a id="sdk-maxretryafterms" />
### maxRetryAfterMs
```ts theme={null}
readonly maxRetryAfterMs: number;
```
Maximum server retry delay in milliseconds; longer delays use backoff. Default: 60000.
***
<a id="sdk-respectretryafter" />
### respectRetryAfter
```ts theme={null}
readonly respectRetryAfter: boolean;
```
Honor `Retry-After` and `retry-after-ms` up to `maxRetryAfterMs`. Default: true.

View File

@@ -0,0 +1,47 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: ScoreQuestion<T>
A question that assigns a score using an ordered rubric.
## Type Parameters
### T
`T` *extends* [`ScoreCriteria`](/sdk/javascript/api/type-aliases/ScoreCriteria) = [`ScoreCriteria`](/sdk/javascript/api/type-aliases/ScoreCriteria)
## Properties
<a id="sdk-criteria" />
### criteria
```ts theme={null}
criteria: T;
```
Descriptions of the available outcomes.
***
<a id="sdk-instructions" />
### instructions?
```ts theme={null}
optional instructions?: EntryType;
```
The question as text, a JSON object, or an array; optional or `null`.
***
<a id="sdk-type" />
### type
```ts theme={null}
type: "score";
```

View File

@@ -0,0 +1,71 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: ScoreResponse<T>
An expected score with its rubric and probabilities.
## Type Parameters
### T
`T` *extends* [`ScoreCriteria`](/sdk/javascript/api/type-aliases/ScoreCriteria) = [`ScoreCriteria`](/sdk/javascript/api/type-aliases/ScoreCriteria)
## Properties
<a id="sdk-confidence" />
### confidence
```ts theme={null}
readonly confidence: number;
```
Reported confidence in the score.
***
<a id="sdk-legend" />
### legend
```ts theme={null}
readonly legend: ScoreLegend<T>;
```
Rubric descriptions keyed by score.
***
<a id="sdk-probabilities" />
### probabilities
```ts theme={null}
readonly probabilities: { readonly [score in number | `${number}`]: number };
```
Probabilities keyed by score.
***
<a id="sdk-score" />
### score
```ts theme={null}
readonly score: number;
```
Expected score, which may fall between integer rubric levels.
***
<a id="sdk-type" />
### type
```ts theme={null}
readonly type: "score";
```

View File

@@ -0,0 +1,55 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: SystemOneRequest<Q>
State and named questions for `systemOne`.
Additional properties on a request variable are forwarded, including `null` values.
## Extended by
* [`SystemOneRequestPayload`](/sdk/javascript/api/interfaces/SystemOneRequestPayload)
## Type Parameters
### Q
`Q` *extends* [`Questions`](/sdk/javascript/api/interfaces/Questions) = [`Questions`](/sdk/javascript/api/interfaces/Questions)
## Properties
<a id="sdk-model" />
### model?
```ts theme={null}
optional model?: string;
```
Model override; omitted values inherit `defaultModel`.
***
<a id="sdk-questions" />
### questions
```ts theme={null}
questions: Q;
```
Nonempty questions keyed by the names used to identify their answers.
***
<a id="sdk-state" />
### state
```ts theme={null}
state: EntryType;
```
Text, a JSON object or array, or `null` to evaluate.

View File

@@ -0,0 +1,59 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: SystemOneRequestPayload
Request body for `POST /v1/systemone`, with the model resolved.
## Extends
* [`SystemOneRequest`](/sdk/javascript/api/interfaces/SystemOneRequest)
## Properties
<a id="sdk-model" />
### model
```ts theme={null}
model: string;
```
Model override; omitted values inherit `defaultModel`.
#### Overrides
[`SystemOneRequest`](/sdk/javascript/api/interfaces/SystemOneRequest).[`model`](/sdk/javascript/api/interfaces/SystemOneRequest#sdk-model)
***
<a id="sdk-questions" />
### questions
```ts theme={null}
questions: Questions;
```
Nonempty questions keyed by the names used to identify their answers.
#### Inherited from
[`SystemOneRequest`](/sdk/javascript/api/interfaces/SystemOneRequest).[`questions`](/sdk/javascript/api/interfaces/SystemOneRequest#sdk-questions)
***
<a id="sdk-state" />
### state
```ts theme={null}
state: EntryType;
```
Text, a JSON object or array, or `null` to evaluate.
#### Inherited from
[`SystemOneRequest`](/sdk/javascript/api/interfaces/SystemOneRequest).[`state`](/sdk/javascript/api/interfaces/SystemOneRequest#sdk-state)

View File

@@ -0,0 +1,49 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: SystemOneResult<Q>
Answers keyed by question name, with model and usage metadata.
## Type Parameters
### Q
`Q` *extends* [`Questions`](/sdk/javascript/api/interfaces/Questions)
## Properties
<a id="sdk-answers" />
### answers
```ts theme={null}
readonly answers: { readonly [K in string | number | symbol]: ResultFor<Q[K]> };
```
Answers with types inferred from the supplied questions.
***
<a id="sdk-model" />
### model
```ts theme={null}
readonly model: string;
```
The model used to answer the request.
***
<a id="sdk-usage" />
### usage
```ts theme={null}
readonly usage: Usage;
```
Token usage for the request.

View File

@@ -0,0 +1,129 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: TypeSafeClientConfig
Client options. Explicit values take precedence over environment variables, then SDK defaults.
## Properties
<a id="sdk-apikey" />
### apiKey?
```ts theme={null}
optional apiKey?: string;
```
Required API key; falls back to `TYPESAFE_API_KEY`.
***
<a id="sdk-baseurl" />
### baseURL?
```ts theme={null}
optional baseURL?: string;
```
API root; falls back to `TYPESAFE_BASE_URL`, then `https://api.typesafe.ai`.
***
<a id="sdk-dangerouslyallowbrowser" />
### dangerouslyAllowBrowser?
```ts theme={null}
optional dangerouslyAllowBrowser?: boolean;
```
Allow browser use, exposing the API key to page users. Default: false.
***
<a id="sdk-defaultheaders" />
### defaultHeaders?
```ts theme={null}
optional defaultHeaders?: Record<string, string>;
```
Additional request headers; per-call headers take precedence.
***
<a id="sdk-defaultmodel" />
### defaultModel?
```ts theme={null}
optional defaultModel?: string;
```
Default model; falls back to `TYPESAFE_DEFAULT_MODEL`, then `jev-latest`.
***
<a id="sdk-fetch" />
### fetch?
```ts theme={null}
optional fetch?: Fetch;
```
Custom HTTP fetch implementation for transport configuration or tests. Default: global `fetch`.
***
<a id="sdk-logger" />
### logger?
```ts theme={null}
optional logger?: Logger;
```
Logger filtered to `logLevel` and above. Default: prefixed `console`.
***
<a id="sdk-loglevel" />
### logLevel?
```ts theme={null}
optional logLevel?: LogLevel;
```
Log level; falls back to `TYPESAFE_LOG_LEVEL`, then `warn`.
`info` logs request summaries; `debug` adds headers and bodies.
Known credential headers are redacted; bodies are not.
***
<a id="sdk-retry" />
### retry?
```ts theme={null}
optional retry?: Partial<RetryPolicy>;
```
Retry overrides; omitted fields use the defaults in `RetryPolicy`.
***
<a id="sdk-timeout" />
### timeout?
```ts theme={null}
optional timeout?: number;
```
Timeout per attempt in milliseconds, without a total retry budget. Default: 10000.

View File

@@ -0,0 +1,31 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: Usage
Token usage for a request.
## Properties
<a id="sdk-input_tokens" />
### input\_tokens
```ts theme={null}
readonly input_tokens: number;
```
Number of input tokens used.
***
<a id="sdk-output_tokens" />
### output\_tokens
```ts theme={null}
readonly output_tokens: number;
```
Number of output tokens used.

View File

@@ -0,0 +1,49 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Interface: WithResponse<T>
Parsed data with its HTTP response and request ID.
## Type Parameters
### T
`T`
## Properties
<a id="sdk-data" />
### data
```ts theme={null}
data: T;
```
The parsed response body.
***
<a id="sdk-requestid" />
### requestId
```ts theme={null}
requestId: string | undefined;
```
Request ID from `x-typesafe-request-id`, or `undefined` when absent.
***
<a id="sdk-response" />
### response
```ts theme={null}
response: Response;
```
The HTTP response, with its body consumed by parsing.

View File

@@ -0,0 +1,17 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: ChoiceCriteria
```ts theme={null}
type ChoiceCriteria = object;
```
Labels mapped to descriptions, or `null` for undescribed labels.
## Index Signature
```ts theme={null}
[label: string]: EntryType
```

View File

@@ -0,0 +1,11 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: Description
```ts theme={null}
type Description = EntryType;
```
A criterion description; `null` leaves the label undescribed.

View File

@@ -0,0 +1,17 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: EntryType
```ts theme={null}
type EntryType =
| string
| {
[key: string]: JsonValue;
}
| JsonValue[]
| null;
```
Text, a JSON object or array, or `null` for state, instructions, and criteria.

View File

@@ -0,0 +1,9 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: EnvVar
```ts theme={null}
type EnvVar = typeof ENV[keyof typeof ENV];
```

View File

@@ -0,0 +1,25 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: Fetch
```ts theme={null}
type Fetch = (input, init?) => Promise<Response>;
```
HTTP fetch implementation compatible with the global `fetch`.
## Parameters
### input
`string`
### init?
`RequestInit`
## Returns
`Promise`\<`Response`>

View File

@@ -0,0 +1,19 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: JsonValue
```ts theme={null}
type JsonValue =
| string
| number
| boolean
| null
| JsonValue[]
| {
[key: string]: JsonValue;
};
```
A JSON-compatible value.

View File

@@ -0,0 +1,11 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: LogLevel
```ts theme={null}
type LogLevel = "debug" | "info" | "warn" | "error" | "off";
```
Log verbosity; `off` disables logging.

View File

@@ -0,0 +1,14 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: Question
```ts theme={null}
type Question =
| NoulQuestion
| ScoreQuestion
| ChoiceQuestion;
```
A question identified by its `type` field.

View File

@@ -0,0 +1,17 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: ResultFor<T>
```ts theme={null}
type ResultFor<T> = T extends NoulQuestion ? NoulResponse : T extends ScoreQuestion<infer S> ? ScoreResponse<S> : T extends ChoiceQuestion<infer E> ? ChoiceResponse<E> : never;
```
The answer type for a question, preserving its criteria keys.
## Type Parameters
### T
`T` *extends* [`Question`](/sdk/javascript/api/type-aliases/Question)

View File

@@ -0,0 +1,11 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: ScoreCriteria
```ts theme={null}
type ScoreCriteria = readonly [EntryType, EntryType, ...EntryType[]];
```
At least two descriptions indexed by score from zero; `null` leaves a score undescribed.

View File

@@ -0,0 +1,17 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: ScoreLegend<T>
```ts theme={null}
type ScoreLegend<T> = { readonly [score in ScoreOf<T>]: T[score] };
```
Rubric descriptions keyed by score.
## Type Parameters
### T
`T` *extends* [`ScoreCriteria`](/sdk/javascript/api/type-aliases/ScoreCriteria)

View File

@@ -0,0 +1,17 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Type Alias: ScoreOf<T>
```ts theme={null}
type ScoreOf<T> = number extends T["length"] ? number : Extract<keyof T, `${number}`>;
```
Score keys inferred from the rubric; a fixed-length tuple yields its indices, otherwise `number`.
## Type Parameters
### T
`T` *extends* [`ScoreCriteria`](/sdk/javascript/api/type-aliases/ScoreCriteria)

View File

@@ -0,0 +1,53 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Variable: ENV
```ts theme={null}
const ENV: object;
```
Environment variable names for client configuration. Explicit options take precedence.
## Type Declaration
<a id="sdk-apikey" />
### apiKey
```ts theme={null}
readonly apiKey: "TYPESAFE_API_KEY" = "TYPESAFE_API_KEY";
```
Required API key; used when `apiKey` is omitted.
<a id="sdk-baseurl" />
### baseURL
```ts theme={null}
readonly baseURL: "TYPESAFE_BASE_URL" = "TYPESAFE_BASE_URL";
```
API root; defaults to `https://api.typesafe.ai`.
<a id="sdk-defaultmodel" />
### defaultModel
```ts theme={null}
readonly defaultModel: "TYPESAFE_DEFAULT_MODEL" = "TYPESAFE_DEFAULT_MODEL";
```
Default model name; defaults to `jev-latest`.
<a id="sdk-loglevel" />
### logLevel
```ts theme={null}
readonly logLevel: "TYPESAFE_LOG_LEVEL" = "TYPESAFE_LOG_LEVEL";
```
Log level; defaults to `warn`.

View File

@@ -0,0 +1,11 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Variable: LOG_LEVELS
```ts theme={null}
const LOG_LEVELS: readonly LogLevel[];
```
Supported log levels, from most to least verbose.

View File

@@ -0,0 +1,9 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Variable: VERSION
```ts theme={null}
const VERSION: "0.6.0" = "0.6.0";
```

View File

@@ -0,0 +1,15 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Changelog
## v0.6.0 (2026-09-15)
### Breaking changes
* accept `Score.criteria` as an ordered sequence instead of a dictionary keyed by integers
## v0.5.7 (2026-09-11)
This is the initial public release of TypeSafe JavaScript and TypeScript SDK. Learn more in the [documentation](https://docs.typesafe.ai/sdk/javascript).

99
docs/sdk/python.md Normal file
View File

@@ -0,0 +1,99 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# TypeSafe Python SDK
> Install the TypeSafe Python SDK and get started with asynchronous or synchronous API calls.
<a id="typesafe-python-sdk" />
Asynchronous and synchronous Python clients for the [TypeSafe](https://typesafe.ai) API. Learn how to use TypeSafe [here](https://docs.typesafe.ai/).
<h2 id="quickstart">
Quickstart
</h2>
1. Install the SDK:
<Tabs>
<Tab title="uv">
```sh theme={null}
uv add typesafe-sdk
```
</Tab>
<Tab title="pip">
```sh theme={null}
pip install typesafe-sdk
```
</Tab>
</Tabs>
2. Set `TYPESAFE_API_KEY` in your environment (create it [here](https://console.typesafe.ai/))
3. Call the System One API:
<Tabs>
<Tab title="Async">
With [AsyncTypeSafeClient](/sdk/python/api/clients/async/client):
```python theme={null}
from typesafe_sdk import AsyncTypeSafeClient, Choice, Noul, Score
async def main() -> None:
async with AsyncTypeSafeClient() as client:
response = await client.system_one(
state={"document": "I was charged twice. Please fix this ASAP."},
questions={
"billing": Noul(instructions="Is this ticket about billing?"),
"tone": Choice(
instructions="What is the customer's tone?",
criteria={"calm": None, "frustrated": None, "angry": None},
),
"urgency": Score(
instructions="How urgent is this ticket?",
criteria=["can wait", "this week", "today"],
),
},
)
print(response.nouls["billing"].noul)
print(response.choices["tone"].choice)
print(response.scores["urgency"].score)
```
</Tab>
<Tab title="Sync">
With [TypeSafeClient](/sdk/python/api/clients/sync/client):
```python theme={null}
from typesafe_sdk import Choice, Noul, Score, TypeSafeClient
with TypeSafeClient() as client:
response = client.system_one(
state={"document": "I was charged twice. Please fix this ASAP."},
questions={
"billing": Noul(instructions="Is this ticket about billing?"),
"tone": Choice(
instructions="What is the customer's tone?",
criteria={"calm": None, "frustrated": None, "angry": None},
),
"urgency": Score(
instructions="How urgent is this ticket?",
criteria=["can wait", "this week", "today"],
),
},
)
print(response.nouls["billing"].noul)
print(response.choices["tone"].choice)
print(response.scores["urgency"].score)
```
</Tab>
</Tabs>
<h2 id="usage">
Usage
</h2>
Learn more in the [Usage guide](/sdk/python/usage).

16
docs/sdk/python/api.md Normal file
View File

@@ -0,0 +1,16 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# API reference
> Python clients for the TypeSafe AI API
<a id="api-reference" />
* Sync client: [Client](/sdk/python/api/clients/sync/client) · [Models](/sdk/python/api/clients/sync/models)
* Async client: [Client](/sdk/python/api/clients/async/client) · [Models](/sdk/python/api/clients/async/models)
* Types: [Common](/sdk/python/api/types/common) · [Questions](/sdk/python/api/types/questions) · [Responses](/sdk/python/api/types/responses)
* [Retries](/sdk/python/api/retries)
* [Exceptions](/sdk/python/api/exceptions)
* [Constants](/sdk/python/api/constants)

View File

@@ -0,0 +1,262 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Asynchronous client
> Use AsyncTypeSafeClient to ask questions, list models, and configure asynchronous TypeSafe API requests.
export function SdkSignature({children}) {
async function copy(event) {
const button = event.currentTarget;
const code = button.parentElement.querySelector("pre code");
try {
await navigator.clipboard.writeText(code.textContent);
button.setAttribute("aria-label", "Signature copied");
button.dataset.copied = "true";
} catch {
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
}
setTimeout(() => {
button.setAttribute("aria-label", "Copy signature");
delete button.dataset.copied;
}, 2000);
}
return <div className="sdk-signature not-prose">
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
<rect x="8" y="8" width="12" height="12" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
</button>
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
</div>;
}
<a id="asynchronous-client" />
<h2 id="typesafe_sdk.AsyncTypeSafeClient">
typesafe\_sdk.AsyncTypeSafeClient
</h2>
<SdkSignature>
<span className="nf">{"AsyncTypeSafeClient"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"api_key"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"model"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"transport"}</span><span className="p">{":"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"AsyncBaseTransport"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"http_client"}</span><span className="p">{":"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n"><a href="https://pydantic.dev/docs/httpx2/api/api/#httpx2.AsyncClient">{"AsyncClient"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"base_url"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{"\n"}
</SdkSignature>
Create an asynchronous HTTP client for [TypeSafe AI API](https://typesafe.ai).
Explicit options take precedence over environment variables; empty or whitespace-only environment values are ignored.
<Tip>
**Logging setup**
The SDK logs to the `typesafe_sdk` logger; configure it through standard logging, or set `TYPESAFE_LOG_LEVEL` (`debug`, `info`, ...) for a quick default. Secret headers are redacted from log output; request and response bodies are not.
</Tip>
Parameters:
* **`api_key`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
Required API key; may be set via the `TYPESAFE_API_KEY` environment variable.
* **`model`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
Model name; may be set via the `TYPESAFE_DEFAULT_MODEL` environment variable.
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
A `RetryPolicy` controlling retry behavior; see `RetryPolicy` for the available options and their defaults. Pass `RetryPolicy(max_retries=0)` to disable retries.
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
Timeout for HTTP operations. Inherits `http_client.timeout` when supplied, otherwise the SDK default.
* **`headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
Additional request headers to set.
* **`transport`** (`httpx2.AsyncBaseTransport | None`, default: `None` ) –
Optional custom HTTP transport, closed when this SDK client closes.
* **`http_client`** (<code>httpx2.<a href="https://pydantic.dev/docs/httpx2/api/api/#httpx2.AsyncClient">AsyncClient</a> | None</code>, default: `None` ) –
Optional `httpx2.AsyncClient`; mutually exclusive with `transport`. Closed when this SDK client closes.
* **`base_url`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
API root; may be set via the `TYPESAFE_BASE_URL` environment variable.
Raises:
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code> –
The API key is missing or the timeout is invalid.
* <code><a href="https://docs.python.org/3/builtins/exceptions.html#ValueError">ValueError</a></code> –
Both `transport` and `http_client` are supplied.
Examples:
```python theme={null}
import asyncio
from typesafe_sdk import AsyncTypeSafeClient, Choice, Noul
async def main() -> None:
async with AsyncTypeSafeClient() as client:
result = await client.system_one(
state="I was charged twice. Please help.",
questions={
"billing": Noul(instructions="Is this about billing?"),
"tone": Choice(
instructions="What is the tone?",
criteria={"calm": None, "angry": None},
),
},
)
assert 0 <= result.nouls["billing"].noul <= 1
assert result.choices["tone"].choice in {"calm", "angry"}
asyncio.run(main())
```
<h3 id="typesafe_sdk.AsyncTypeSafeClient.models">
models
</h3>
`cached` `property`
<SdkSignature>
<span className="n">
{"models"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="/sdk/python/api/clients/async/models#typesafe_sdk.AsyncModels">
{"AsyncModels"}
</a>
</span>
{"\n"}
</SdkSignature>
An accessor for the Models API resource.
Examples:
```python theme={null}
async def main() -> None:
async with AsyncTypeSafeClient() as client:
models = await client.models.list()
```
<h3 id="typesafe_sdk.AsyncTypeSafeClient.system_one">
system\_one
</h3>
`async`
<SdkSignature>
<span className="nf">{"system_one"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="n">{"state"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONContent">{"JSONContent"}</a></span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"questions"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/questions#typesafe_sdk.Question">{"Question"}</a></span><span className="p">{"],"}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"model"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_body"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">{"JSONValue"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{" "}<span className="o">{"->"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.SystemOneResponse">{"SystemOneResponse"}</a></span>{"\n"}
</SdkSignature>
Answer named questions about text or structured state.
See [System One](https://docs.typesafe.ai/concepts/system-one) for details.
Parameters:
* **`state`** (<code><a href="/sdk/python/api/types/common#typesafe_sdk.JSONContent">JSONContent</a></code>) –
Text, a JSON object, or an array to evaluate. See [state](https://docs.typesafe.ai/concepts/state) for details.
* **`questions`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="/sdk/python/api/types/questions#typesafe_sdk.Question">Question</a>]</code>) –
Nonempty mapping of names to question objects or raw dictionaries.
* **`model`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
Model override; `None` inherits the client default.
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
An optional retry policy to override the client-level value for this call only.
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
An optional timeout for http operations to override the client-level value for this call only, in seconds.
* **`extra_headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
Additional request headers to set.
* **`extra_body`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">JSONValue</a> | None] | None</code>, default: `None` ) –
Additional top-level request-body fields, shallow-merged over the body after `state`, `model`, and `questions` are set. Merging is last-write-wins: a key that collides with `state`, `model`, or `questions` overrides it, and object values are replaced rather than deep-merged.
Returns:
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.SystemOneResponse">SystemOneResponse</a></code> –
Answers keyed by question name, with model and token usage details.
Raises:
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code> –
Questions are empty or a score question's criteria list is empty.
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code> –
The server returns an unsuccessful HTTP response after any retries.
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code> –
The request cannot connect or times out after any retries.
Examples:
Create questions with named arguments:
```python theme={null}
async def main() -> None:
async with AsyncTypeSafeClient() as client:
result = await client.system_one(
state="I was charged twice. Please help.",
questions={
"billing": Noul(instructions="Is this about billing?"),
"tone": Choice(
instructions="What is the tone?",
criteria={"calm": None, "angry": None},
),
},
)
assert 0 <= result.nouls["billing"].noul <= 1
assert result.choices["tone"].choice in {"calm", "angry"}
```
Pass questions as dictionaries:
```python theme={null}
async def main() -> None:
async with AsyncTypeSafeClient() as client:
result = await client.system_one(
state={"message": "I was charged twice. Please help."},
questions={
"billing": {"type": "noul", "instructions": "Is this about billing?"},
"tone": {
"type": "choice",
"instructions": "What is the tone?",
"criteria": {"calm": None, "angry": None},
},
},
)
assert 0 <= result.nouls["billing"].noul <= 1
assert result.choices["tone"].choice in {"calm", "angry"}
```
<h3 id="typesafe_sdk.AsyncTypeSafeClient.aclose">
aclose
</h3>
`async`
```python theme={null}
aclose() -> None
```
Release network resources and close the underlying HTTP client, including a supplied one.

View File

@@ -0,0 +1,97 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Models resource
> List the models available to your account through the asynchronous client's Models resource.
export function SdkSignature({children}) {
async function copy(event) {
const button = event.currentTarget;
const code = button.parentElement.querySelector("pre code");
try {
await navigator.clipboard.writeText(code.textContent);
button.setAttribute("aria-label", "Signature copied");
button.dataset.copied = "true";
} catch {
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
}
setTimeout(() => {
button.setAttribute("aria-label", "Copy signature");
delete button.dataset.copied;
}, 2000);
}
return <div className="sdk-signature not-prose">
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
<rect x="8" y="8" width="12" height="12" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
</button>
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
</div>;
}
<a id="models-resource" />
Reached through [`AsyncTypeSafeClient.models`](/sdk/python/api/clients/async/client).
<h2 id="typesafe_sdk.AsyncModels">
typesafe\_sdk.AsyncModels
</h2>
Access to the models available to the account, reached through `AsyncTypeSafeClient.models`.
<h3 id="typesafe_sdk.AsyncModels.list">
list
</h3>
`async`
<SdkSignature>
<span className="nf">{"list"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{" "}<span className="o">{"->"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">{"ListModelsResponse"}</a></span>{"\n"}
</SdkSignature>
List the models available to the account.
Parameters:
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
An optional retry policy to override the client-level value for this call only.
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
Per-operation timeout override; `None` inherits the client setting.
* **`extra_headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
Overrides for additional request headers; authentication, SDK identification, and `Accept` remain protected.
Returns:
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">ListModelsResponse</a></code> –
A `ListModelsResponse` whose `models` holds each model's name, description,
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">ListModelsResponse</a></code> –
and release date.
Raises:
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code> –
The server returns an unsuccessful HTTP response after any retries.
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code> –
The request cannot connect or times out after any retries.
Examples:
```python theme={null}
from typesafe_sdk import AsyncTypeSafeClient
async def main() -> None:
async with AsyncTypeSafeClient() as client:
models = await client.models.list()
```

View File

@@ -0,0 +1,248 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Synchronous client
> Use TypeSafeClient to ask questions, list models, and configure synchronous TypeSafe API requests.
export function SdkSignature({children}) {
async function copy(event) {
const button = event.currentTarget;
const code = button.parentElement.querySelector("pre code");
try {
await navigator.clipboard.writeText(code.textContent);
button.setAttribute("aria-label", "Signature copied");
button.dataset.copied = "true";
} catch {
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
}
setTimeout(() => {
button.setAttribute("aria-label", "Copy signature");
delete button.dataset.copied;
}, 2000);
}
return <div className="sdk-signature not-prose">
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
<rect x="8" y="8" width="12" height="12" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
</button>
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
</div>;
}
<a id="synchronous-client" />
<h2 id="typesafe_sdk.TypeSafeClient">
typesafe\_sdk.TypeSafeClient
</h2>
<SdkSignature>
<span className="nf">{"TypeSafeClient"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"api_key"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"model"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"transport"}</span><span className="p">{":"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"BaseTransport"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"http_client"}</span><span className="p">{":"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n"><a href="https://pydantic.dev/docs/httpx2/api/api/#httpx2.Client">{"Client"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"base_url"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{"\n"}
</SdkSignature>
Create an HTTP client for [TypeSafe AI API](https://typesafe.ai).
Explicit options take precedence over environment variables; empty or whitespace-only environment values are ignored.
<Tip>
**Logging setup**
The SDK logs to the `typesafe_sdk` logger; configure it through standard logging, or set `TYPESAFE_LOG_LEVEL` (`debug`, `info`, ...) for a quick default. Secret headers are redacted from log output; request and response bodies are not.
</Tip>
Parameters:
* **`api_key`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
Required API key; may be set via the `TYPESAFE_API_KEY` environment variable.
* **`model`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
Model name; may be set via the `TYPESAFE_DEFAULT_MODEL` environment variable.
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
A `RetryPolicy` controlling retry behavior; see `RetryPolicy` for the available options and their defaults. Pass `RetryPolicy(max_retries=0)` to disable retries.
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
Timeout for HTTP operations. Inherits `http_client.timeout` when supplied, otherwise the SDK default.
* **`headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
Additional request headers to set.
* **`transport`** (`httpx2.BaseTransport | None`, default: `None` ) –
Optional custom HTTP transport, closed when this SDK client closes.
* **`http_client`** (<code>httpx2.<a href="https://pydantic.dev/docs/httpx2/api/api/#httpx2.Client">Client</a> | None</code>, default: `None` ) –
Optional `httpx2.Client`; mutually exclusive with `transport`. Closed when this SDK client closes.
* **`base_url`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
API root; may be set via the `TYPESAFE_BASE_URL` environment variable.
Raises:
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code> –
The API key is missing or the timeout is invalid.
* <code><a href="https://docs.python.org/3/builtins/exceptions.html#ValueError">ValueError</a></code> –
Both `transport` and `http_client` are supplied.
Examples:
```python theme={null}
from typesafe_sdk import Choice, Noul, TypeSafeClient
with TypeSafeClient() as client:
result = client.system_one(
state="I was charged twice. Please help.",
questions={
"billing": Noul(instructions="Is this about billing?"),
"tone": Choice(
instructions="What is the tone?",
criteria={"calm": None, "angry": None},
),
},
)
assert 0 <= result.nouls["billing"].noul <= 1
assert result.choices["tone"].choice in {"calm", "angry"}
```
<h3 id="typesafe_sdk.TypeSafeClient.models">
models
</h3>
`cached` `property`
<SdkSignature>
<span className="n">
{"models"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="/sdk/python/api/clients/sync/models#typesafe_sdk.Models">
{"Models"}
</a>
</span>
{"\n"}
</SdkSignature>
An accessor for the Models API resource.
Examples:
```python theme={null}
with TypeSafeClient() as client:
models = client.models.list()
```
<h3 id="typesafe_sdk.TypeSafeClient.system_one">
system\_one
</h3>
<SdkSignature>
<span className="nf">{"system_one"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="n">{"state"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONContent">{"JSONContent"}</a></span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"questions"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/questions#typesafe_sdk.Question">{"Question"}</a></span><span className="p">{"],"}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"model"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_body"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">{"JSONValue"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{" "}<span className="o">{"->"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.SystemOneResponse">{"SystemOneResponse"}</a></span>{"\n"}
</SdkSignature>
Answer named questions about text or structured state.
See [System One](https://docs.typesafe.ai/concepts/system-one) for details.
Parameters:
* **`state`** (<code><a href="/sdk/python/api/types/common#typesafe_sdk.JSONContent">JSONContent</a></code>) –
Text, a JSON object, or an array to evaluate. See [state](https://docs.typesafe.ai/concepts/state) for details.
* **`questions`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="/sdk/python/api/types/questions#typesafe_sdk.Question">Question</a>]</code>) –
Nonempty mapping of names to question objects or raw dictionaries.
* **`model`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
Model override; `None` inherits the client default.
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
An optional retry policy to override the client-level value for this call only.
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
An optional timeout for http operations to override the client-level value for this call only, in seconds.
* **`extra_headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
Additional request headers to set.
* **`extra_body`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">JSONValue</a> | None] | None</code>, default: `None` ) –
Additional top-level request-body fields, shallow-merged over the body after `state`, `model`, and `questions` are set. Merging is last-write-wins: a key that collides with `state`, `model`, or `questions` overrides it, and object values are replaced rather than deep-merged.
Returns:
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.SystemOneResponse">SystemOneResponse</a></code> –
Answers keyed by question name, with model and token usage details.
Raises:
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code> –
Questions are empty or a score question's criteria list is empty.
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code> –
The server returns an unsuccessful HTTP response after any retries.
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code> –
The request cannot connect or times out after any retries.
Examples:
Create questions with named arguments:
```python theme={null}
with TypeSafeClient() as client:
result = client.system_one(
state="I was charged twice. Please help.",
questions={
"billing": Noul(instructions="Is this about billing?"),
"tone": Choice(
instructions="What is the tone?",
criteria={"calm": None, "angry": None},
),
},
)
assert 0 <= result.nouls["billing"].noul <= 1
assert result.choices["tone"].choice in {"calm", "angry"}
```
Pass questions as dictionaries:
```python theme={null}
with TypeSafeClient() as client:
result = client.system_one(
state={"message": "I was charged twice. Please help."},
questions={
"billing": {"type": "noul", "instructions": "Is this about billing?"},
"tone": {
"type": "choice",
"instructions": "What is the tone?",
"criteria": {"calm": None, "angry": None},
},
},
)
assert 0 <= result.nouls["billing"].noul <= 1
assert result.choices["tone"].choice in {"calm", "angry"}
```
<h3 id="typesafe_sdk.TypeSafeClient.close">
close
</h3>
```python theme={null}
close() -> None
```
Release network resources and close the underlying HTTP client, including a supplied one.

View File

@@ -0,0 +1,93 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Models resource
> List the models available to your account through the synchronous client's Models resource.
export function SdkSignature({children}) {
async function copy(event) {
const button = event.currentTarget;
const code = button.parentElement.querySelector("pre code");
try {
await navigator.clipboard.writeText(code.textContent);
button.setAttribute("aria-label", "Signature copied");
button.dataset.copied = "true";
} catch {
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
}
setTimeout(() => {
button.setAttribute("aria-label", "Copy signature");
delete button.dataset.copied;
}, 2000);
}
return <div className="sdk-signature not-prose">
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
<rect x="8" y="8" width="12" height="12" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
</button>
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
</div>;
}
<a id="models-resource" />
Reached through [`TypeSafeClient.models`](/sdk/python/api/clients/sync/client).
<h2 id="typesafe_sdk.Models">
typesafe\_sdk.Models
</h2>
Access to the models available to the account, reached through `TypeSafeClient.models`.
<h3 id="typesafe_sdk.Models.list">
list
</h3>
<SdkSignature>
<span className="nf">{"list"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{" "}<span className="o">{"->"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">{"ListModelsResponse"}</a></span>{"\n"}
</SdkSignature>
List the models available to the account.
Parameters:
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
An optional retry policy to override the client-level value for this call only.
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
Per-operation timeout override; `None` inherits the client setting.
* **`extra_headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
Overrides for additional request headers; authentication, SDK identification, and `Accept` remain protected.
Returns:
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">ListModelsResponse</a></code> –
A `ListModelsResponse` whose `models` holds each model's name, description,
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">ListModelsResponse</a></code> –
and release date.
Raises:
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code> –
The server returns an unsuccessful HTTP response after any retries.
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code> –
The request cannot connect or times out after any retries.
Examples:
```python theme={null}
from typesafe_sdk import TypeSafeClient
with TypeSafeClient() as client:
models = client.models.list()
```

View File

@@ -0,0 +1,99 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Constants
> Default settings and environment variable names for the TypeSafe Python SDK.
<a id="constants" />
<h2 id="typesafe_sdk.constants">
typesafe\_sdk.constants
</h2>
Public environment-variable names and client defaults.
<h3 id="typesafe_sdk.constants.API_KEY_ENV">
API\_KEY\_ENV
</h3>
`module-attribute`
```python theme={null}
API_KEY_ENV = 'TYPESAFE_API_KEY'
```
Environment variable for the API key.
<h3 id="typesafe_sdk.constants.BASE_URL_ENV">
BASE\_URL\_ENV
</h3>
`module-attribute`
```python theme={null}
BASE_URL_ENV = 'TYPESAFE_BASE_URL'
```
Environment variable for the API base URL.
<h3 id="typesafe_sdk.constants.DEFAULT_MODEL_ENV">
DEFAULT\_MODEL\_ENV
</h3>
`module-attribute`
```python theme={null}
DEFAULT_MODEL_ENV = 'TYPESAFE_DEFAULT_MODEL'
```
Environment variable for the default model.
<h3 id="typesafe_sdk.constants.LOG_LEVEL_ENV">
LOG\_LEVEL\_ENV
</h3>
`module-attribute`
```python theme={null}
LOG_LEVEL_ENV = 'TYPESAFE_LOG_LEVEL'
```
Environment variable for the logging level.
<h3 id="typesafe_sdk.constants.DEFAULT_BASE_URL">
DEFAULT\_BASE\_URL
</h3>
`module-attribute`
```python theme={null}
DEFAULT_BASE_URL = 'https://api.typesafe.ai'
```
Default API base URL.
<h3 id="typesafe_sdk.constants.DEFAULT_MODEL">
DEFAULT\_MODEL
</h3>
`module-attribute`
```python theme={null}
DEFAULT_MODEL = 'jev-latest'
```
Default model name.
<h3 id="typesafe_sdk.constants.DEFAULT_TIMEOUT">
DEFAULT\_TIMEOUT
</h3>
`module-attribute`
```python theme={null}
DEFAULT_TIMEOUT = 10.0
```
Default timeout in seconds for each HTTP operation.

View File

@@ -0,0 +1,288 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Exceptions
> Handle TypeSafe API errors, rate limits, connection failures, and timeouts.
export function SdkSignature({children}) {
async function copy(event) {
const button = event.currentTarget;
const code = button.parentElement.querySelector("pre code");
try {
await navigator.clipboard.writeText(code.textContent);
button.setAttribute("aria-label", "Signature copied");
button.dataset.copied = "true";
} catch {
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
}
setTimeout(() => {
button.setAttribute("aria-label", "Copy signature");
delete button.dataset.copied;
}, 2000);
}
return <div className="sdk-signature not-prose">
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
<rect x="8" y="8" width="12" height="12" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
</button>
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
</div>;
}
<a id="exceptions" />
<h2 id="base-exception">
Base exception
</h2>
<h2 id="typesafe_sdk.TypeSafeError">
typesafe\_sdk.TypeSafeError
</h2>
Bases: <code><a href="https://docs.python.org/3/builtins/exceptions.html#Exception">Exception</a></code>
Base exception for SDK failures.
<h2 id="http-errors">
HTTP errors
</h2>
<h2 id="typesafe_sdk.TypeSafeAPIError">
typesafe\_sdk.TypeSafeAPIError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code>
An unsuccessful HTTP response with its body and request metadata.
<h3 id="typesafe_sdk.TypeSafeAPIError.status">
status
</h3>
`instance-attribute`
```python theme={null}
status = status
```
HTTP response status code.
<h3 id="typesafe_sdk.TypeSafeAPIError.body">
body
</h3>
`instance-attribute`
```python theme={null}
body = body
```
The server's JSON error body, plain response text, or `None` for an empty body.
<h3 id="typesafe_sdk.TypeSafeAPIError.headers">
headers
</h3>
`instance-attribute`
```python theme={null}
headers = headers
```
HTTP response headers.
<h3 id="typesafe_sdk.TypeSafeAPIError.endpoint">
endpoint
</h3>
`instance-attribute`
```python theme={null}
endpoint = endpoint
```
The request method and URL, without credentials, query parameters, or fragment, when available.
<h3 id="typesafe_sdk.TypeSafeAPIError.request_id">
request\_id
</h3>
`property`
<SdkSignature>
<span className="n">
{"request_id"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
{" "}
<span className="o">
{"|"}
</span>
{" "}
<span className="kc">
{"None"}
</span>
{"\n"}
</SdkSignature>
The `x-typesafe-request-id` response header, or `None` if absent.
<h2 id="typesafe_sdk.TypeSafeBadRequestError">
typesafe\_sdk.TypeSafeBadRequestError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
The request was invalid (400).
<h2 id="typesafe_sdk.TypeSafeAuthenticationError">
typesafe\_sdk.TypeSafeAuthenticationError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
Authentication failed (401).
<h2 id="typesafe_sdk.TypeSafePermissionDeniedError">
typesafe\_sdk.TypeSafePermissionDeniedError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
Access was denied (403).
<h2 id="typesafe_sdk.TypeSafeNotFoundError">
typesafe\_sdk.TypeSafeNotFoundError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
The resource was not found (404).
<h2 id="typesafe_sdk.TypeSafeUnprocessableEntityError">
typesafe\_sdk.TypeSafeUnprocessableEntityError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
The request failed server validation (422).
<h2 id="typesafe_sdk.TypeSafeRateLimitError">
typesafe\_sdk.TypeSafeRateLimitError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
The rate limit was exceeded (429).
<h3 id="typesafe_sdk.TypeSafeRateLimitError.retry_after_ms">
retry\_after\_ms
</h3>
`instance-attribute`
```python theme={null}
retry_after_ms = parse_retry_after(headers)
```
The server's requested wait in milliseconds, or `None` if unavailable.
<h2 id="typesafe_sdk.TypeSafeInternalServerError">
typesafe\_sdk.TypeSafeInternalServerError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
The server failed to process the request (5xx).
<h2 id="connection-errors">
Connection errors
</h2>
<h2 id="typesafe_sdk.TypeSafeAPIConnectionError">
typesafe\_sdk.TypeSafeAPIConnectionError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code>, <code><a href="https://docs.python.org/3/builtins/exceptions.html#ConnectionError">ConnectionError</a></code>
A request failed without an HTTP response.
<h2 id="typesafe_sdk.TypeSafeAPITimeoutError">
typesafe\_sdk.TypeSafeAPITimeoutError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code>, <code><a href="https://docs.python.org/3/builtins/exceptions.html#TimeoutError">TimeoutError</a></code>
A request exceeded its configured timeout.
<h3 id="typesafe_sdk.TypeSafeAPITimeoutError.timeout">
timeout
</h3>
`instance-attribute`
```python theme={null}
timeout = timeout
```
The timeout setting used for the request, in seconds or as an `httpx2.Timeout`.
<h2 id="response-validation">
Response validation
</h2>
<h2 id="typesafe_sdk.TypeSafeAPIResponseValidationError">
typesafe\_sdk.TypeSafeAPIResponseValidationError
</h2>
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
A successful HTTP response whose body was missing or structurally invalid required data.
<h3 id="typesafe_sdk.TypeSafeAPIResponseValidationError.field_path">
field\_path
</h3>
`instance-attribute`
```python theme={null}
field_path = field_path
```
Dotted path to the offending field, such as `answers.tone.confidence`.
<h3 id="typesafe_sdk.TypeSafeAPIResponseValidationError.args">
args
</h3>
`instance-attribute`
```python theme={null}
args = (
status,
body,
headers,
field_path,
endpoint,
)
```

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,60 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Common types
> Common types for TypeSafe API SDK.
export function SdkSignature({children}) {
async function copy(event) {
const button = event.currentTarget;
const code = button.parentElement.querySelector("pre code");
try {
await navigator.clipboard.writeText(code.textContent);
button.setAttribute("aria-label", "Signature copied");
button.dataset.copied = "true";
} catch {
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
}
setTimeout(() => {
button.setAttribute("aria-label", "Copy signature");
delete button.dataset.copied;
}, 2000);
}
return <div className="sdk-signature not-prose">
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
<rect x="8" y="8" width="12" height="12" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
</button>
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
</div>;
}
<a id="common-types" />
<h2 id="typesafe_sdk.JSONValue">
typesafe\_sdk.JSONValue
</h2>
`module-attribute`
<SdkSignature>
<span className="n">{"JSONValue"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.TypeAlias">{"TypeAlias"}</a></span>{" "}<span className="o">{"="}</span>{" "}<span className="p">{"("}</span>{"\n"}{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#int">{"int"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#bool">{"bool"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence">{"Sequence"}</a></span><span className="p">{"["}</span><span className="s2">{"\"JSONValue | None\""}</span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="s2">{"\"JSONValue | None\""}</span><span className="p">{"]"}</span>{"\n"}<span className="p">{")"}</span>{"\n"}
</SdkSignature>
A JSON-like value. May be nested and contain `None`.
<h2 id="typesafe_sdk.JSONContent">
typesafe\_sdk.JSONContent
</h2>
`module-attribute`
<SdkSignature>
<span className="n">{"JSONContent"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.TypeAlias">{"TypeAlias"}</a></span>{" "}<span className="o">{"="}</span>{" "}<span className="p">{"("}</span>{"\n"}{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">{"JSONValue"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence">{"Sequence"}</a></span><span className="p">{"["}</span><span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">{"JSONValue"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span><span className="p">{"]"}</span>{"\n"}<span className="p">{")"}</span>{"\n"}
</SdkSignature>
Either a plain string or a mapping/sequence of [`JSONValue`](/sdk/python/api/types/common#typesafe_sdk.JSONValue) entries.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,926 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Answers and responses
> Read answers, confidence scores, token usage, and available models returned by the TypeSafe API.
export function SdkSignature({children}) {
async function copy(event) {
const button = event.currentTarget;
const code = button.parentElement.querySelector("pre code");
try {
await navigator.clipboard.writeText(code.textContent);
button.setAttribute("aria-label", "Signature copied");
button.dataset.copied = "true";
} catch {
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
}
setTimeout(() => {
button.setAttribute("aria-label", "Copy signature");
delete button.dataset.copied;
}, 2000);
}
return <div className="sdk-signature not-prose">
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
<rect x="8" y="8" width="12" height="12" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
</button>
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
</div>;
}
<a id="answers-and-responses" />
<h2 id="response">
Response
</h2>
<h2 id="typesafe_sdk.SystemOneResponse">
typesafe\_sdk.SystemOneResponse
</h2>
Bases: `Response`
Answers grouped by question type with model and usage metadata.
See [System One](https://docs.typesafe.ai/concepts/system-one) for details.
<h3 id="typesafe_sdk.SystemOneResponse.request_id">
request\_id
</h3>
`cached` `property`
<SdkSignature>
<span className="n">
{"request_id"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
{"\n"}
</SdkSignature>
The `x-typesafe-request-id` response header.
<h3 id="typesafe_sdk.SystemOneResponse.raw_http_response">
raw\_http\_response
</h3>
`property`
```python theme={null}
raw_http_response: httpx2.Response
```
The underlying `httpx2.Response`, exposing status, headers, and body.
<h3 id="typesafe_sdk.SystemOneResponse.model">
model
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"model"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
{"\n"}
</SdkSignature>
The model used to answer the request.
<h3 id="typesafe_sdk.SystemOneResponse.usage">
usage
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"usage"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="/sdk/python/api/types/responses#typesafe_sdk.Usage">
{"Usage"}
</a>
</span>
{"\n"}
</SdkSignature>
Token usage for the request.
<h3 id="typesafe_sdk.SystemOneResponse.answers">
answers
</h3>
`class-attribute` `instance-attribute`
<SdkSignature>
<span className="n">{"answers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#dict">{"dict"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.Answer">{"Answer"}</a></span><span className="p">{"]"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="n"><a href="https://msgspec.dev/api.html#msgspec.field">{"field"}</a></span><span className="p">{"("}</span>{"\n"}{" "}<span className="n">{"default_factory"}</span><span className="o">{"="}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#dict">{"dict"}</a></span>{"\n"}<span className="p">{")"}</span>{"\n"}
</SdkSignature>
All answer objects keyed by question name.
<h3 id="typesafe_sdk.SystemOneResponse.nouls">
nouls
</h3>
`cached` `property`
<SdkSignature>
<span className="n">
{"nouls"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
{"dict"}
</a>
</span>
<span className="p">
{"["}
</span>
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
<span className="p">
{","}
</span>
{" "}
<span className="n">
<a href="/sdk/python/api/types/responses#typesafe_sdk.NoulAnswer">
{"NoulAnswer"}
</a>
</span>
<span className="p">
{"]"}
</span>
{"\n"}
</SdkSignature>
Yes/no answers keyed by question name.
<h3 id="typesafe_sdk.SystemOneResponse.choices">
choices
</h3>
`cached` `property`
<SdkSignature>
<span className="n">
{"choices"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
{"dict"}
</a>
</span>
<span className="p">
{"["}
</span>
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
<span className="p">
{","}
</span>
{" "}
<span className="n">
<a href="/sdk/python/api/types/responses#typesafe_sdk.ChoiceAnswer">
{"ChoiceAnswer"}
</a>
</span>
<span className="p">
{"]"}
</span>
{"\n"}
</SdkSignature>
Choice answers keyed by question name.
<h3 id="typesafe_sdk.SystemOneResponse.scores">
scores
</h3>
`cached` `property`
<SdkSignature>
<span className="n">
{"scores"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
{"dict"}
</a>
</span>
<span className="p">
{"["}
</span>
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
<span className="p">
{","}
</span>
{" "}
<span className="n">
<a href="/sdk/python/api/types/responses#typesafe_sdk.ScoreAnswer">
{"ScoreAnswer"}
</a>
</span>
<span className="p">
{"]"}
</span>
{"\n"}
</SdkSignature>
Score answers keyed by question name.
<h2 id="typesafe_sdk.Usage">
typesafe\_sdk.Usage
</h2>
Bases: <code>msgspec.<a href="https://msgspec.dev/api.html#msgspec.Struct">Struct</a></code>
Token counts for a request, when reported by the API.
<h3 id="typesafe_sdk.Usage.input_tokens">
input\_tokens
</h3>
`class-attribute` `instance-attribute`
<SdkSignature>
<span className="n">
{"input_tokens"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#int">
{"int"}
</a>
</span>
{" "}
<span className="o">
{"|"}
</span>
{" "}
<span className="kc">
{"None"}
</span>
{" "}
<span className="o">
{"="}
</span>
{" "}
<span className="kc">
{"None"}
</span>
{"\n"}
</SdkSignature>
Number of input tokens used, or `None` when the API did not report it.
<h3 id="typesafe_sdk.Usage.output_tokens">
output\_tokens
</h3>
`class-attribute` `instance-attribute`
<SdkSignature>
<span className="n">
{"output_tokens"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#int">
{"int"}
</a>
</span>
{" "}
<span className="o">
{"|"}
</span>
{" "}
<span className="kc">
{"None"}
</span>
{" "}
<span className="o">
{"="}
</span>
{" "}
<span className="kc">
{"None"}
</span>
{"\n"}
</SdkSignature>
Number of output tokens used, or `None` when the API did not report it.
<h2 id="answers">
Answers
</h2>
<h2 id="typesafe_sdk.NoulAnswer">
typesafe\_sdk.NoulAnswer
</h2>
Bases: `wire.NoulAnswer`
A yes/no answer.
See the [noul primitive](https://docs.typesafe.ai/primitives/noul) for details.
<h3 id="typesafe_sdk.NoulAnswer.noul">
noul
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"noul"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#float">
{"float"}
</a>
</span>
{"\n"}
</SdkSignature>
Probability of a yes answer, from zero to one.
<h2 id="typesafe_sdk.ChoiceAnswer">
typesafe\_sdk.ChoiceAnswer
</h2>
Bases: `wire.ChoiceAnswer`
A selected label and its probabilities.
See the [choice primitive](https://docs.typesafe.ai/primitives/choice) for details.
<h3 id="typesafe_sdk.ChoiceAnswer.choice">
choice
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"choice"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
{"\n"}
</SdkSignature>
The selected label.
<h3 id="typesafe_sdk.ChoiceAnswer.confidence">
confidence
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"confidence"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#float">
{"float"}
</a>
</span>
{"\n"}
</SdkSignature>
Reported confidence in the selected label.
<h3 id="typesafe_sdk.ChoiceAnswer.probabilities">
probabilities
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"probabilities"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
{"dict"}
</a>
</span>
<span className="p">
{"["}
</span>
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
<span className="p">
{","}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#float">
{"float"}
</a>
</span>
<span className="p">
{"]"}
</span>
{"\n"}
</SdkSignature>
Probabilities keyed by label.
<h2 id="typesafe_sdk.ScoreAnswer">
typesafe\_sdk.ScoreAnswer
</h2>
Bases: `wire.ScoreAnswer`
An expected score with its rubric and probabilities.
See the [score primitive](https://docs.typesafe.ai/primitives/score) for details.
<h3 id="typesafe_sdk.ScoreAnswer.score">
score
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"score"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#float">
{"float"}
</a>
</span>
{"\n"}
</SdkSignature>
Expected score, which may fall between the integer rubric levels.
<h3 id="typesafe_sdk.ScoreAnswer.confidence">
confidence
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"confidence"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#float">
{"float"}
</a>
</span>
{"\n"}
</SdkSignature>
Reported confidence in the score.
<h3 id="typesafe_sdk.ScoreAnswer.legend">
legend
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">{"legend"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#dict">{"dict"}</a></span><span className="p">{"["}</span>{"\n"}{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#int">{"int"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#dict">{"dict"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.Any">{"Any"}</a></span><span className="p">{"]"}</span>{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#list">{"list"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.Any">{"Any"}</a></span><span className="p">{"]"}</span>{"\n"}<span className="p">{"]"}</span>{"\n"}
</SdkSignature>
Rubric descriptions keyed by integer score.
<h3 id="typesafe_sdk.ScoreAnswer.probabilities">
probabilities
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"probabilities"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
{"dict"}
</a>
</span>
<span className="p">
{"["}
</span>
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#int">
{"int"}
</a>
</span>
<span className="p">
{","}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/functions.html#float">
{"float"}
</a>
</span>
<span className="p">
{"]"}
</span>
{"\n"}
</SdkSignature>
Probabilities keyed by integer score.
<h2 id="typesafe_sdk.Answer">
typesafe\_sdk.Answer
</h2>
`module-attribute`
<SdkSignature>
<span className="n">{"Answer"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.TypeAlias">{"TypeAlias"}</a></span>{" "}<span className="o">{"="}</span>{" "}<span className="p">{"("}</span>{"\n"}{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.NoulAnswer">{"NoulAnswer"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.ChoiceAnswer">{"ChoiceAnswer"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.ScoreAnswer">{"ScoreAnswer"}</a></span>{"\n"}<span className="p">{")"}</span>{"\n"}
</SdkSignature>
An answer to a single question, identified by its `type`.
<h2 id="available-models">
Available models
</h2>
<h2 id="typesafe_sdk.ListModelsResponse">
typesafe\_sdk.ListModelsResponse
</h2>
Bases: `Response`
The models available to the account.
<h3 id="typesafe_sdk.ListModelsResponse.request_id">
request\_id
</h3>
`cached` `property`
<SdkSignature>
<span className="n">
{"request_id"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
{"\n"}
</SdkSignature>
The `x-typesafe-request-id` response header.
<h3 id="typesafe_sdk.ListModelsResponse.raw_http_response">
raw\_http\_response
</h3>
`property`
```python theme={null}
raw_http_response: httpx2.Response
```
The underlying `httpx2.Response`, exposing status, headers, and body.
<h3 id="typesafe_sdk.ListModelsResponse.models">
models
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"models"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#tuple">
{"tuple"}
</a>
</span>
<span className="p">
{"["}
</span>
<span className="n">
<a href="/sdk/python/api/types/responses#typesafe_sdk.ModelMetadata">
{"ModelMetadata"}
</a>
</span>
<span className="p">
{","}
</span>
{" "}
<span className="o">
{"..."}
</span>
<span className="p">
{"]"}
</span>
{"\n"}
</SdkSignature>
The available models.
<h2 id="typesafe_sdk.ModelMetadata">
typesafe\_sdk.ModelMetadata
</h2>
Bases: <code><a href="https://msgspec.dev/api.html#msgspec.Struct">Struct</a></code>
<h3 id="typesafe_sdk.ModelMetadata.name">
name
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"name"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
{"\n"}
</SdkSignature>
<h3 id="typesafe_sdk.ModelMetadata.description">
description
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"description"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
{"\n"}
</SdkSignature>
<h3 id="typesafe_sdk.ModelMetadata.release_date">
release\_date
</h3>
`instance-attribute`
<SdkSignature>
<span className="n">
{"release_date"}
</span>
<span className="p">
{":"}
</span>
{" "}
<span className="n">
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
{"str"}
</a>
</span>
{"\n"}
</SdkSignature>

View File

@@ -0,0 +1,45 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Changelog
> Python clients for the TypeSafe AI API
<a id="changelog" />
<h2 id="v060-2026-09-15">
v0.6.0 (2026-09-15)
</h2>
<h3 id="breaking-changes">
Breaking Changes
</h3>
* accept `Score.criteria` as an ordered sequence instead of a dictionary keyed by integers
<h3 id="features">
Features
</h3>
* improve type annotations on SDK inputs to accept abstract types like `Mapping` and `Sequence`
* improve error messages to include http details and metadata
<h3 id="bug-fixes">
Bug fixes
</h3>
* handle invalid values in `RetryPolicy`
* make exceptions and responses picklable
<h3 id="documentation">
Documentation
</h3>
* link more concepts from main [docs](https://docs.typesafe.ai/)
<h2 id="v057-2026-09-14">
v0.5.7 (2026-09-14)
</h2>
This is the initial public release of TypeSafe Python SDK. Learn more in the [documentation](https://docs.typesafe.ai/sdk/python).

220
docs/sdk/python/usage.md Normal file
View File

@@ -0,0 +1,220 @@
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
> Use this file to discover all available pages before exploring further.
# Usage
> Guides and patterns for working with the TypeSafe Python SDK.
<a id="usage" />
<h2 id="calling-the-system-one-api">
Calling the System One API
</h2>
<Tabs>
<Tab title="Async">
```python theme={null}
import asyncio
from typesafe_sdk import AsyncTypeSafeClient, Choice, Noul, Score
async def main() -> None:
async with AsyncTypeSafeClient() as client:
result = await client.system_one(
"I was charged twice. Please help ASAP.",
{
"billing": Noul(instructions="Is this about billing?"),
"tone": Choice(
instructions="What is the tone?",
criteria={"calm": None, "angry": None},
),
"urgency": Score(
instructions="How urgent is this?",
criteria=["low", "medium", "high"],
),
},
)
print(
result.nouls["billing"].noul,
result.choices["tone"].choice,
result.scores["urgency"].score,
)
asyncio.run(main())
```
</Tab>
<Tab title="Sync">
```python theme={null}
from typesafe_sdk import Choice, Noul, Score, TypeSafeClient
client = TypeSafeClient()
state = "I was charged twice. Please help ASAP."
questions = {
"billing": Noul(instructions="Is this about billing?"),
"tone": Choice(
instructions="What is the tone?", criteria={"calm": None, "angry": None}
),
"urgency": Score(
instructions="How urgent is this?", criteria=["low", "medium", "high"]
),
}
result = client.system_one(state, questions)
print(
result.nouls["billing"].noul,
result.choices["tone"].choice,
result.scores["urgency"].score,
)
```
</Tab>
</Tabs>
<h2 id="choosing-a-model">
Choosing a model
</h2>
Inspect the available models:
```python theme={null}
from typesafe_sdk import TypeSafeClient
print(TypeSafeClient().models.list())
```
Select the model when constructing a client:
```python theme={null}
client = TypeSafeClient(model="jev")
```
See [Models](/models) for available models, pricing, rate limits, and aliases.
<h2 id="retries">
Retries
</h2>
Pass a custom [`RetryPolicy`](/sdk/python/api/retries) as `retry` on the client or per call.
<Tabs>
<Tab title="Client">
```python theme={null}
from typesafe_sdk import RetryPolicy, TypeSafeClient
client = TypeSafeClient(retry=RetryPolicy(max_retries=3, backoff_max=0.2, timeout=1.0))
```
</Tab>
<Tab title="Per-call">
```python theme={null}
from typesafe_sdk import RetryPolicy
client.system_one(
state, questions, retry=RetryPolicy(max_retries=3, backoff_max=0.2, timeout=1.0)
)
```
</Tab>
</Tabs>
<h2 id="error-handling">
Error handling
</h2>
Handle [exceptions](/sdk/python/api/exceptions) raised by the SDK:
```python theme={null}
from typesafe_sdk import TypeSafeAPIError
try:
client.system_one(state, questions)
except TypeSafeAPIError as error:
print(error.status, error.request_id)
```
<h2 id="logging">
Logging
</h2>
The SDK logs to the `typesafe_sdk` logger. Configure it according to [standard logging](https://docs.python.org/3/library/logging.html) guide:
```python theme={null}
import logging
logging.getLogger("typesafe_sdk").setLevel(logging.DEBUG)
```
Or set `TYPESAFE_LOG_LEVEL` to one of `debug`, `info`, `warning`, `error`, or `off` before importing the SDK.
`info` logs one summary line per request; `debug` also logs request and response headers and bodies. Secret headers — authorization, API keys, cookies, and any header whose name contains `token` or `secret` — are redacted from log output. Request and response bodies are **not** redacted.
<h2 id="environment-variables">
Environment variables
</h2>
The SDK reads and uses the following environment variables:
| Variable | Configures | Default |
| ------------------------ | --------------------------------------------------- | ------------------------- |
| `TYPESAFE_API_KEY` | API key (required) | — |
| `TYPESAFE_BASE_URL` | API root URL | `https://api.typesafe.ai` |
| `TYPESAFE_DEFAULT_MODEL` | Default model | `jev-latest` |
| `TYPESAFE_LOG_LEVEL` | `typesafe_sdk` logger level, applied once at import | unset |
See the [constants reference](/sdk/python/api/constants) for SDK defaults.
<h2 id="forward-compatibility">
Forward compatibility
</h2>
The SDK keeps working as the TypeSafe API evolves, so you can adopt new API features before an SDK release adds first-class support for them.
<h3 id="extra-request-fields">
Extra request fields
</h3>
Send request fields this SDK version predates with [`extra_body`](/sdk/python/api/clients/sync/client):
```python theme={null}
from typesafe_sdk import Noul, TypeSafeClient
with TypeSafeClient() as client:
client.system_one(
"I was charged twice.",
{"billing": Noul(instructions="About billing?")},
extra_body={"beam_width": 4},
)
```
<h3 id="raw-question-dictionaries">
Raw question dictionaries
</h3>
Pass a question as a plain dictionary to include fields this SDK version does not model yet:
```python theme={null}
from typesafe_sdk import TypeSafeClient
with TypeSafeClient() as client:
client.system_one(
"I was charged twice.",
{"billing": {"type": "noul", "instructions": "About billing?", "weight": 2}},
)
```
<h3 id="unknown-answer-kinds">
Unknown answer kinds
</h3>
The SDK logs a warning and skips unrecognized answer kinds. Use `raw_http_response` to inspect the complete API response, including those answers:
```python theme={null}
raw_answers = result.raw_http_response.json()["answers"]
```
<h3 id="unknown-response-fields">
Unknown response fields
</h3>
Unknown extra fields on recognized responses are ignored.