Tern LogoTern

AI Models

Tern uses AI, and for the Open Beta, we’re bring-your-own-key API key. Tern supports Anthropic Claude (direct API, AWS Bedrock, Google Vertex AI, and Portkey), OpenAI GPT, and Google Gemini models.

Configuration

Onboarding will walk you through inputting a key directly into the product. You can also configure providers through environment variables:

# Anthropic (direct API)
export ANTHROPIC_API_KEY=your_anthropic_key

# OpenAI
export OPENAI_API_KEY=your_openai_key

# Google Gemini
export GEMINI_API_KEY=your_gemini_key

# Anthropic via AWS Bedrock
export BEDROCK_ANTHROPIC_MODEL="global.anthropic.claude-sonnet-4-5-20250929-v1:0"

# Anthropic via Google Vertex AI
export VERTEX_ANTHROPIC_PROJECT="your-gcp-project-id"
export VERTEX_ANTHROPIC_REGION="us-central1"

# Anthropic via Portkey (both required, then UI setup for base model)
export PORTKEY_API_KEY=your_portkey_key
export PORTKEY_MODEL=claude-sonnet-4-5-20250929

Model Precedence

When multiple providers are configured, Tern will try providers in this order:

  1. Anthropic Claude - ANTHROPIC_API_KEY
  2. OpenAI - OPENAI_API_KEY
  3. Google Gemini - GEMINI_API_KEY
  4. Anthropic via AWS Bedrock (requires opt-in) - BEDROCK_ANTHROPIC_MODEL
  5. Anthropic via Google Vertex AI (requires opt-in) - VERTEX_ANTHROPIC_PROJECT + VERTEX_ANTHROPIC_REGION
  6. Anthropic via Portkey (requires opt-in) - PORTKEY_API_KEY + PORTKEY_MODEL + UI setup

Recommended Models

Anthropic Claude

  • Claude Sonnet 4.5 (claude-sonnet-4.5) — Default. Best balance of performance and cost, especially for coding tasks.
  • Claude Haiku 4.5 (claude-haiku-4.5) — Quick, solid performance.
  • Claude Opus 4.1 (claude-opus-4.1) — Top-end model. Highest performance on coding & reasoning benchmarks.

Anthropic via Bedrock

Models are configured through your AWS account, and may vary according to your organizations AWS configuration.

To find available models:

$ aws bedrock list-inference-profiles

Anthropic via Vertex AI

Google Vertex AI provides access to Claude models through Google Cloud. This is useful if your organization already uses Google Cloud and prefers to consolidate AI spending under your GCP billing.

Prerequisites:

  1. A Google Cloud project with Vertex AI API enabled
  2. Claude models enabled in your project (via the Model Garden)
  3. Application Default Credentials configured (gcloud auth application-default login)
  4. IAM permissions: roles/aiplatform.user or aiplatform.endpoints.predict

Configuration:

# Required: Project ID (also accepts GOOGLE_CLOUD_PROJECT or GCLOUD_PROJECT)
export VERTEX_ANTHROPIC_PROJECT="your-gcp-project-id"

# Required: Region (also accepts GOOGLE_CLOUD_LOCATION)
# Available regions: us-central1, us-east5, europe-west1, europe-west4, asia-southeast1
export VERTEX_ANTHROPIC_REGION="us-central1"

# Optional: Model override
export VERTEX_ANTHROPIC_MODEL="claude-sonnet-4-5@20250514"

Available models:

  • claude-sonnet-4-5@20250514 — Best balance of performance and cost
  • claude-opus-4@20250514 — Highest performance
  • claude-haiku-4-5@20251001 — Fastest, most cost-effective

Note: Cost tracking uses the same pricing as direct Anthropic API. Actual costs may vary based on your Google Cloud agreement.

Anthropic via Portkey

Portkey is an AI gateway that provides observability, caching, and routing features for LLM calls. See Portkey’s documentation for setup instructions.

Note: Cost tracking uses the base model you select during setup. Actual costs may vary based on your Portkey configuration.

Configuration (requires opt-in):

Portkey requires both env vars to be set, then setup in Tern to select the base model for pricing:

# Both required - Portkey won't appear unless both are set
export PORTKEY_API_KEY=your_portkey_key
export PORTKEY_MODEL="@anthropic/claude-sonnet-4-5-20250929"

The model uses Portkey’s Model Catalog format: @provider/model. For Anthropic models, use @anthropic/model-name.

Then in Tern’s settings, click “Complete Setup” for Portkey and select the base model (e.g., Claude Sonnet 4.5) that corresponds to your model string. This is used for pricing and capability detection.

OpenAI

  • GPT-5 (gpt-5) - Default. Latest model with excellent reasoning and code generation
  • GPT-5 Mini (gpt-5-mini) - Faster performance, lower cost
  • GPT-5 Nano (gpt-5-nano) - Fastest performance, lowest cost

Google Gemini

  • Gemini 2.5 Pro (gemini-2.5-pro) - Default. State-of-the-art reasoning and coding, 1M+ token context
  • Gemini 2.5 Flash (gemini-2.5-flash) - Best price/performance ratio with thinking capabilities
  • Gemini 2.5 Flash-Lite (gemini-2.5-flash-lite) - Most cost-efficient option

OpenAI-Compatible Routers

Many LLM routers (LiteLLM, vLLM, Ollama, etc.) expose an OpenAI-compatible Chat Completions API. Tern supports these via additional environment variables:

OPENAI_API_KEY="your-router-api-key"
OPENAI_BASE_URL="http://localhost:4000"   # Your router's base URL
OPENAI_MODEL="your-model-name"             # Model identifier for the router

When OPENAI_BASE_URL is set, Tern switches from OpenAI’s Responses API to the Chat Completions API (the industry standard). The model string is passed through opaquely to the router.

Example Configurations

LiteLLM (litellm.ai):

OPENAI_API_KEY="sk-..."
OPENAI_BASE_URL="http://localhost:4000"
OPENAI_MODEL="claude-3-5-sonnet"  # LiteLLM model alias

Ollama (ollama.com):

OPENAI_API_KEY="ollama"  # Ollama doesn't require a real key
OPENAI_BASE_URL="http://localhost:11434"
OPENAI_MODEL="llama3.2"

vLLM (vllm.ai):

OPENAI_API_KEY="your-key"
OPENAI_BASE_URL="http://your-vllm-server:8000"
OPENAI_MODEL="meta-llama/Llama-3.1-8B-Instruct"

Experimenting with Models

Feel free to experiment with other models that are available through these providers. Different models may be better suited for particular types of code transformations or specific programming languages.