Python SDK quickstart

Last updated: 2025-01-15
1 min read

Python SDK Quickstart

Build with TaskForceAI using Python.

Installation

pip install taskforceai

Setup

from taskforceai import TaskForceAI
import os

client = TaskForceAI(api_key=os.environ["TASKFORCEAI_API_KEY"])

Basic Usage

response = client.chat.create(
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

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

Streaming

stream = client.chat.create(
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

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

Async Support

from taskforceai import AsyncTaskForceAI

async_client = AsyncTaskForceAI()
response = await async_client.chat.create(...)

Next Steps

See the [full documentation] (https://docs.taskforceai.chat/docs/python-sdk) for advanced usage.

Still need help?

Our support team is available to assist you.

Contact Support