Skip to main content

YUA AI SDK — OpenAI-compatible Python client

Project description

yua

Official Python SDK for YUA AI. YUA AI Python SDK.

Installation

pip install yua

Quick Start

from yua import YUA

client = YUA(api_key="yua_sk_...")

# Streaming
stream = client.chat.completions.create(
    model="yua-normal",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
)

for chunk in stream:
    text = chunk.choices[0].delta.content
    if text:
        print(text, end="", flush=True)

Non-Streaming

response = client.chat.completions.create(
    model="yua-normal",
    messages=[{"role": "user", "content": "What is 2+2?"}],
)

print(response.choices[0].message.content)

Models

Model Description
yua-fast Fast responses, single segment
yua-normal Balanced speed and quality (default)
yua-deep Deep reasoning with multi-step thinking

Configuration

client = YUA(
    api_key="yua_sk_...",           # Required (or auth_provider)
    base_url="https://...",         # Default: https://api.yuaone.com
    workspace="ws_...",             # Optional workspace ID
    timeout=30.0,                   # Request timeout in seconds (default: 30)
    max_retries=2,                  # Auto-retry count (default: 2)
)

Context Manager

with YUA(api_key="yua_sk_...") as client:
    stream = client.chat.completions.create(...)
    for chunk in stream:
        ...
# Connection automatically closed

Custom Auth Provider

client = YUA(
    auth_provider=lambda: get_id_token(),
)

Streaming with YUA Events

YUA streams include extended events beyond standard text chunks.

stream = client.chat.completions.create(
    model="yua-deep",
    messages=[{"role": "user", "content": "Explain quantum computing"}],
    stream=True,
    thinking_profile="DEEP",
)

for chunk in stream:
    # Standard text content
    text = chunk.choices[0].delta.content
    if text:
        print(text, end="", flush=True)

    # YUA-specific events
    if chunk.yua_event:
        if chunk.yua_event.type == "activity":
            print(f"[Activity] {chunk.yua_event.data}")
        elif chunk.yua_event.type == "reasoning_block":
            print(f"[Reasoning] {chunk.yua_event.data}")
        elif chunk.yua_event.type == "suggestion":
            print(f"[Suggestions] {chunk.yua_event.data}")

Stream Helper Methods

stream = client.chat.completions.create(..., stream=True)

# Get full text after stream completes
full_text = stream.text_content()

# Get the final assembled message
message = stream.final_message()

Thread Management

# Create thread
thread = client.chat.threads.create()

# List threads
threads = client.chat.threads.list()

# Send message to specific thread
stream = client.chat.completions.create(
    model="yua-normal",
    messages=[{"role": "user", "content": "Continue our discussion"}],
    stream=True,
    thread_id=thread["threadId"],
)

# Update thread title
client.chat.threads.update(thread["threadId"], title="My Chat")

# Delete thread
client.chat.threads.delete(thread["threadId"])

Messages

# List messages in a thread
messages = client.chat.messages.list(thread_id=123)

# Send a message without streaming
client.chat.messages.create(
    thread_id=123,
    role="user",
    content="Hello",
)

Error Handling

from yua import APIError, AuthenticationError, RateLimitError

try:
    res = client.chat.completions.create(...)
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Rate limited, retry later")
except APIError as e:
    print(f"{e.status} {e.code}: {e.message}")

YUA Event Types

Event Description
stage Processing stage changes (thinking, analyzing, answer)
token Text token (mapped to delta.content)
final Final assembled response (mapped to finish_reason="stop")
activity Thinking activities (analyzing, planning, researching)
reasoning_block Deep reasoning block content
reasoning_done Reasoning phase completed
suggestion Follow-up suggestions
memory Memory commit events
answer_unlocked Deep mode: answer text begins

Requirements

  • Python >= 3.8
  • httpx >= 0.24.0
  • pydantic >= 2.0.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yua-0.2.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yua-0.2.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file yua-0.2.0.tar.gz.

File metadata

  • Download URL: yua-0.2.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for yua-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b5d4c4af6581d469aa962ba883429b6466f490ddf7c07f0548bad5ebb176d56b
MD5 412f7d37f68c00c4b10a181917f30c57
BLAKE2b-256 e41ae20ce50f198dc98fd15dab0bc220bef8ed57852629cf4f294e18d8d15138

See more details on using hashes here.

File details

Details for the file yua-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: yua-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for yua-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 542fa2cf93f5ecc94e5135a6b3ef3ebf3fdc89d2143a8f881d6d81c2899a6066
MD5 c23105e55f4bb8a715e8b353e968756d
BLAKE2b-256 3c809f485ad7738d4966ec6c23dd3599589fb3ef72f0bb8b6310985b44939417

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page