Skip to main content

Python SDK for the Foil Engine NPC API

Project description

Foil Engine Python SDK

Python SDK for the Foil Engine NPC API. Add AI-powered NPC conversations to your game or application.

Installation

pip install foilengine

Quick Start

from foilengine import FoilEngineClient

client = FoilEngineClient(
    api_key="pk_live_...",
    llm_api_key="sk-...",   # your LLM provider API key
    llm_model="gpt-4o",     # any LiteLLM-supported model
)

# Discover your personas
personas = client.personas.list()

# Initialize a session
session = client.chat.init_session(
    persona_id=personas[0].id,
    user_session_id="player-001",
    player_name="Alex",
    player_gender="non-binary",
)
print(session.message)  # NPC's greeting

# Send a message
response = client.chat.send_message(
    persona_id=personas[0].id,
    message="What do you recommend?",
    user_session_id="player-001",
)
print(response.message)       # NPC's reply
print(response.current_state) # State machine state
print(response.score)         # Session score

Async Support

from foilengine import AsyncFoilEngineClient

async with AsyncFoilEngineClient(api_key="pk_live_...", llm_api_key="sk-...", llm_model="gpt-4o") as client:
    personas = await client.personas.list_async()
    response = await client.chat.send_message_async(
        persona_id=personas[0].id,
        message="Hello!",
        user_session_id="player-001",
    )

Configuration

client = FoilEngineClient(
    api_key="pk_live_...",              # required
    llm_api_key="sk-...",              # required – your LLM provider API key
    llm_model="gpt-4o",               # optional – default LLM model
    base_url="http://localhost:8000",   # default: https://api.foilengine.io
    timeout=30.0,                       # default: 30s
    max_retries=3,                      # default: 3
)

LLM Configuration (BYOK)

SDK chat endpoints require your own LLM API key. Foil Engine uses LiteLLM under the hood, so any supported provider and model string works.

# Use OpenAI
client = FoilEngineClient(
    api_key="pk_live_...",
    llm_api_key="sk-...",
    llm_model="gpt-4o",
)

# Use Anthropic
client = FoilEngineClient(
    api_key="pk_live_...",
    llm_api_key="sk-ant-...",
    llm_model="anthropic/claude-sonnet-4-20250514",
)

# Override models per pipeline step
client = FoilEngineClient(
    api_key="pk_live_...",
    llm_api_key="sk-...",
    llm_model="gpt-4o",
    llm_eval_model="gpt-4o-mini",          # cheaper model for evaluation
    llm_response_model="gpt-4o",           # main model for NPC responses
    llm_summarization_model="gpt-4o-mini", # cheaper model for summaries
)

Documentation

Full documentation at foilengine.io/docs/sdk/python

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

foilengine-0.2.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

foilengine-0.2.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file foilengine-0.2.1.tar.gz.

File metadata

  • Download URL: foilengine-0.2.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for foilengine-0.2.1.tar.gz
Algorithm Hash digest
SHA256 13441f55d3ba8fa5c1de7201d74850b60ec6772a28b1347645bf44e93cf287cd
MD5 dfb06d148ed21b7010be61f660e3652e
BLAKE2b-256 8d201cb85d2fccf708ae389cdda4c5c7bbcc0ebfe7eb7c47d038d66456f66b0f

See more details on using hashes here.

File details

Details for the file foilengine-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: foilengine-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for foilengine-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b24bb789ef36f26b16afe508df9cce04fca99514822739a27572790fe2cedb6
MD5 77039040898ea74e6b5e769c63b57d82
BLAKE2b-256 3c6df6791f25607b18bd70ce010829e87366019ef8bc1a77af631013f6789860

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