Skip to Content
NineTwo's

SDKs

Official Python and TypeScript SDKs for the NineTwo's public API.

The official SDKs implement the NineTwo's public API with dynamic capability discovery, strict validation, durable replay, and bounded recovery. They never hardcode model identity or context/output limits.

Package registries

Install the SDKs from PyPI and npm.

Python

python -m pip install ninetwos==0.1.0rc1
from ninetwos import Ninetwos

with Ninetwos(
    api_key="ntw_...",                    # or NINETWOS_API_KEY
    base_url="https://api.ninetwos.com",  # or NINETWOS_BASE_URL
) as client:
    model = client.models.list().data[0]
    print(model.id, model.capabilities.limits.max_output_tokens.recommended)

    result = client.chat.completions.create(
        model=model.id,
        messages=[{"role": "user", "content": "Hello"}],
        max_completion_tokens=model.recommended_max_completion_tokens or 128,
        idempotency_key="order-123-attempt-1",
    )
    print(result.output_text)
    print(result.usage)       # server-authoritative usage
    print(result.request_id)  # gateway execution id

Async clients, streaming, same-key replay, and typed errors are supported. A completed streaming request replayed with the same key and payload returns a stored JSON completion rather than a second SSE execution.

TypeScript / Node.js

npm install @ninetwos-/sdk
import { NinetwosClient } from '@ninetwos-/sdk';

const client = new NinetwosClient({
  apiKey: process.env.NINETWOS_API_KEY!,
  baseUrl: 'https://api.ninetwos.com',
});

const model = await client.models.retrieve('zuv-0.5');
const completion = await client.chat.completions.create(
  {
    model: model.id,
    messages: [{ role: 'user', content: 'Hello' }],
    max_completion_tokens:
      model.capabilities.limits.max_output_tokens.recommended ?? 128,
  },
  { idempotencyKey: 'order-123-attempt-1' },
);

console.log(completion.choices[0]?.message.content);
console.log(completion.usage); // server-authoritative

The streaming API exposes replayed, replay, and finalCompletion() so a completed streaming operation can be recovered as stored JSON without a new dispatch.

Shared semantics

  • GET /v1/models is the availability and limits authority.
  • One logical operation keeps one idempotency key and one canonical payload.
  • Safe retries reuse the same key; ambiguous outcomes recover through request lookup and same-key replay, never blind re-execution.
  • Usage, pricing, settlement, and request state are server-authoritative.
  • See Idempotency and recovery and Errors and retries for the complete contract.

On this page