Python SDK

The official Python SDK for INK provides an intuitive interface for AI content generation in Python applications.

Installation

pip install inkai

Or with poetry:

poetry add inkai

Quick Start

from inkai import InkAI
import os

ink = InkAI(api_key=os.environ["INK_API_KEY"])

response = ink.generate(
    prompt="Write a product description for a smart watch",
    template="marketing-copy"
)

print(response.content)

Configuration

Client Options

ink = InkAI(
    api_key="your_api_key",
    base_url="https://api.inkai.ph/v1",
    timeout=30.0,
    max_retries=3
)

Environment Variables

export INK_API_KEY=your_api_key
export INK_BASE_URL=https://api.inkai.ph/v1
export INK_TIMEOUT=30

Methods

generate()

Generate content from a prompt:

response = ink.generate(
    prompt="Your prompt here",
    template="market-analysis",
    options={
        "tone": "professional",
        "length": "detailed",
        "language": "en"
    }
)

refine()

Refine existing content:

response = ink.refine(
    content="Original content...",
    instructions="Make it more concise",
    preserve_style=True
)

templates.list()

Get available templates:

templates = ink.templates.list()
for template in templates:
    print(f"{template.id}: {template.name}")

Async Support

Use the async client for concurrent operations:

from inkai import AsyncInkAI
import asyncio

async def main():
    ink = AsyncInkAI(api_key=os.environ["INK_API_KEY"])

    response = await ink.generate(
        prompt="Your prompt here"
    )
    print(response.content)

asyncio.run(main())

Streaming

For long-form content:

stream = ink.generate(
    prompt="Write a detailed market analysis...",
    stream=True
)

for chunk in stream:
    print(chunk.content, end="", flush=True)

Error Handling

from inkai import InkAI, InkError, RateLimitError

try:
    response = ink.generate(prompt="...")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except InkError as e:
    print(f"Error {e.code}: {e.message}")

Type Hints

Full type hint support:

from inkai.types import GenerateRequest, GenerateResponse

request: GenerateRequest = {
    "prompt": "Your prompt",
    "template": "general"
}

Next Steps