Skip to main content

Lightweight, config-driven client for multiple LLM providers

Project description

fj-llm

Lightweight, config-driven Python client for multiple LLM providers. One interface, any provider — no provider SDK required.

Install

pip install fj-llm

Providers

Provider Config key Env var
OpenAI openai OPENAI_API_KEY
Anthropic anthropic ANTHROPIC_API_KEY
DeepSeek deepseek DEEPSEEK_API_KEY
Google google GOOGLE_API_KEY

Configuration

On first use, a default config is created at ~/.config/fj_llm/config.yaml. Edit it to add your API keys and define model aliases:

models:
  gpt-best:
    provider: openai
    model_name: gpt-4o
    api_key_env: OPENAI_API_KEY
    base_url: https://api.openai.com/v1
    max_tokens: 4000
    temperature: 0.1
    pricing:
      input_per_1m_tokens: 2.50
      output_per_1m_tokens: 10.00
    fallback: gpt-light        # optional: alias to use on quota exhaustion

  gpt-light:
    provider: openai
    model_name: gpt-4o-mini
    api_key_env: OPENAI_API_KEY
    base_url: https://api.openai.com/v1
    max_tokens: 4000
    temperature: 0.1
    pricing:
      input_per_1m_tokens: 0.15
      output_per_1m_tokens: 0.60

defaults:
  retry_attempts: 3
  retry_delay: 1.0
  timeout: 30

For Cloud Functions or other environments without filesystem access, set the FJ_LLM_CONFIG environment variable to a JSON string of the same structure.

Usage

from fj_llm import LLMClient

client = LLMClient()
response = client.query("gpt-best", "Summarise this in one sentence.", context=long_text)

if response.success:
    print(response.content)
    print(f"Cost: ${response.cost:.6f}")
else:
    print(f"Error: {response.error}")

Cost logging

Every successful call is appended as a JSONL record to ~/.local/share/fj_llm/costs.jsonl. Override the path via the FJ_LLM_COST_LOG env var, or set cost_log in the config file.

CLI

llm-query gpt-best "What is the capital of France?"

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

fj_llm-0.3.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

fj_llm-0.3.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fj_llm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d98dd0a5d7b16f58018c7bb3cd950544db70755eac6ec04114ae3289b708c040
MD5 ac47c3363c489ca919ed70cda4800e85
BLAKE2b-256 5e586eb94063bc52197b6298d1793355fb2a516ef1555ca2eba6c1aa7f545b0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fj_llm-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for fj_llm-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b211f2bfd5bd12fa07e042f38a1b6d2969fd077d46b914464f953ae7be91c7be
MD5 1cc316f41de310d8a045041daad99077
BLAKE2b-256 4fe8f1ff09af935dca8a5624543bf0c319794d8ac552a6c12f4f67a3a7a9bf6a

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