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.3.0.tar.gz (11.1 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.3.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for foilengine-0.3.0.tar.gz
Algorithm Hash digest
SHA256 dc8e2d774c16209f60e38e2e4419e7b8468dd493a872beec9e577fa7cc47e782
MD5 55206d1a95773a33b4d1318252f2a208
BLAKE2b-256 5b999fc75b9cf8824aafb508c7d88e77d1d575290a081ac72f648489a72c8024

See more details on using hashes here.

File details

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

File metadata

  • Download URL: foilengine-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42a58dedc1734b4049d8706955b096152b4b5b4485da58d08ab54c0ab2fe8baf
MD5 92d26c8ada702852f3cb72be28eb6a44
BLAKE2b-256 c7eb74fb731bae99c38abd79735351f0cc9f7efb55dae4beb982b36bc4950fb4

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