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.4.0.tar.gz (16.3 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.4.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for foilengine-0.4.0.tar.gz
Algorithm Hash digest
SHA256 366057121b8c04d26bbf6440d7640c7597fd8d1733242c89fca86dc9a050d84b
MD5 69cc76fff636a7b7783243cd1f6e751c
BLAKE2b-256 881e470a841cd267de795f33a0d4425b31f6ffc5e5d5c53d91e6f9288a5e3d23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: foilengine-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ccd07df5532b08a314bc793570db3f85c5217f00180607fe6231e907eebc0d9
MD5 e123d018f2ec92f9bdc709b0920683d1
BLAKE2b-256 cc5fe8f541e3bd3f908aa8849f28692b080d5f83f5685ed0fe418a842be4b6b5

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