Skip to content

Credentials and models

The SDK needs an LLM provider API key to run queries. There are three ways to supply credentials.

If you omit settings, the session uses a file-backed Config.default(), the same configuration the saber CLI uses. Keys you saved with saber auth are picked up automatically:

from sqlsaber import SQLSaber, SQLSaberOptions
# Uses your stored CLI credentials and configured default model.
options = SQLSaberOptions(database="sqlite:///my.db")

This is the usual choice for local scripts on a machine where you already use SQLsaber. See Authentication.

Both the default and in-memory configs check the provider’s environment variable first:

Terminal window
export ANTHROPIC_API_KEY="sk-..."
options = SQLSaberOptions(
database="sqlite:///my.db",
model_name="anthropic:claude-sonnet-4-5-20250929",
)

Each provider has its own variable:

  • ANTHROPIC_API_KEY
  • OPENAI_API_KEY
  • GOOGLE_API_KEY
  • GROQ_API_KEY
  • MISTRAL_API_KEY
  • COHERE_API_KEY
  • HUGGINGFACE_API_KEY
  • XAI_API_KEY

For servers, CI, or notebooks where you do not want filesystem or keyring I/O, build an in-memory Config and inject it through settings:

from sqlsaber import SQLSaber, SQLSaberOptions
from sqlsaber.config.settings import Config
options = SQLSaberOptions(
database="sqlite:///my.db",
settings=Config.in_memory(
model_name="anthropic:claude-sonnet-4-5-20250929",
api_keys={"anthropic": "sk-..."},
),
)

api_keys maps provider name to key. Supported keys are anthropic, openai, google, groq, mistral, cohere, huggingface, and xai.

For a single key without building a Config, set api_key on SQLSaberOptions. model_name is required so the provider can be determined:

options = SQLSaberOptions(
database="sqlite:///my.db",
model_name="anthropic:claude-sonnet-4-5-20250929",
api_key="sk-...",
)

Models are identified as "provider:model":

SQLSaberOptions(database="...", model_name="anthropic:claude-sonnet-4-5-20250929")
SQLSaberOptions(database="...", model_name="openai:gpt-5-mini")
SQLSaberOptions(database="...", model_name="google:gemini-2.5-pro")
SQLSaberOptions(database="...", model_name="xai:grok-4.6")

If model_name is omitted, the session uses your configured default model. See Models for supported providers.

Reasoning models support extended thinking. Enable it and pick a level:

SQLSaberOptions(
database="...",
model_name="anthropic:claude-sonnet-4-5-20250929",
thinking_level="high", # minimal | low | medium | high | maximum
)

Setting thinking_level implies thinking_enabled=True. Set thinking_enabled on its own to use the model’s default level.