This chapter introduces a fast-evolving landscape of large language model alternatives to OpenAI’s GPT, arguing that the best model depends on task, cost, and deployment needs. While most systems share the Transformer architecture, they differ in training approaches, tokenization, pricing, hosting options, and specialization. The text encourages evaluating general-purpose models against smaller, task-specific ones that may deliver comparable quality at lower cost, and notes that many providers mirror OpenAI-style APIs, making it easier to experiment and switch.
Across major providers, the chapter highlights distinct strengths and common usage patterns. AI21’s Jurassic-2 family offers multiple sizes and a large token vocabulary that can reduce billable tokens; it supports both general completion and cheaper specialized endpoints (e.g., paraphrasing) via web and Python interfaces. Anthropic’s Claude 3 emphasizes safety through “Constitutional AI” and uses a chat-style messages API similar to OpenAI’s. Cohere’s Coral focuses on grounded answers through connectors and retrieval-augmented generation, returning sources and queries alongside responses to curb hallucinations. Google’s Gemini brings multimodal capabilities and tight integration with other Google tools, with a straightforward Python SDK to generate content programmatically.
The chapter also surveys open-source options centered on the Hugging Face ecosystem, contrasting closed, cloud-hosted models with downloadable models that can run locally for cost, privacy, or control reasons. Although typically smaller, open models are abundant and often specialized, enabling strong performance on focused tasks. Using the Transformers library (built on PyTorch), the chapter demonstrates how to load models via simple pipelines—such as a Roberta-based sentiment classifier—without API keys, with assets cached after first use. The takeaway: match model choice to task, constraints, and infrastructure, leveraging specialized or grounded systems when appropriate and open-source models when local control or cost efficiency matter most.
Click on the button labeled “Playground” to chat with AI21’s Jurassic model.
Web interface for chatting with AI21’s Jurassic model: enter a prompt in the field above and click on the button below to generate an answer.
Retrieve your access key for using AI21 via the Python library by clicking on the “API key” item in the drop-down menu above.
Web interface for Anthropic’s chatbot “Claude”.
Web interface for chatting with Cohere’s language model Coral.
Web interface for chatting with Google’s Gemini model. Click on “Settings” to activate additional functionality.
Overview of Hugging Face Transformer models. Click on the “Task filters” to narrow down the selection of models. Click on models in the “Model list” to see details.
Detailed description of Saleforce’s BLIP model (https://huggingface.co/Salesforce/blip-image-captioning-large). Read the description on the left or try out the model via the interface on the right.
Summary
Beyond OpenAI, several other providers offer large language models.
Most providers offer closed-source models via a Cloud API.
Models differ by their generality, output quality, and pricing.
Some providers offer specialized models for tasks like summarization.
Using specialized models can be more efficient for standard tasks.
Most providers offer a Python library to access language models.
Hugging Face Transformers offers various models for free download.
FAQ
Which GPT alternatives does this chapter cover?The chapter explores AI21’s Jurassic-2, Anthropic’s Claude 3, Cohere’s Coral, Google’s Gemini, and a wide range of open-source models available via Hugging Face.Why should I explore GPT alternatives, and how do I choose the right model?Although most models share the Transformer architecture, providers differ in training methods, tokenization, pricing, and delivery. Powerful general models (e.g., GPT-4-class) handle many tasks but may be costly. If a smaller, specialized model exists for your task, it can deliver similar quality at lower cost. Evaluate models by quality on your task, token usage, per-token price, latency, and available tooling.Do different providers use similar APIs?Yes. Many alternatives expose interfaces similar to OpenAI’s, so you can often switch providers with minimal code changes. This reduces the learning curve when experimenting across models.Why isn’t my favorite model listed, and does the order imply priority?Given the rapid growth of models and providers, the chapter can’t be exhaustive. Omission doesn’t imply a model is inferior. Providers are listed alphabetically—no ranking or priority is implied.How does AI21’s large token vocabulary affect pricing?A larger vocabulary can represent the same text with fewer tokens, potentially lowering usage-based fees. However, overall cost depends on both token count and price per token. A lower per-token price doesn’t automatically mean lower total cost—compare both factors for your workload.How do I try and program against AI21 Jurassic-2, and when should I use specialized endpoints?- Try it in the browser at ai21.com (Start Building → Foundation Models). Jurassic-2 comes in multiple sizes to trade speed/cost vs. quality.
- Python: pip install ai21==1.3, set ai21.api_key, then call ai21.Completion.execute(model='j2-mid', prompt=...).
- For standard tasks (e.g., paraphrasing), AI21 offers specialized endpoints (e.g., ai21.Paraphrase.execute). These can be significantly cheaper per token (at the time of writing) if their quality meets your needs.What is Anthropic’s “Constitutional AI,” and how do I call Claude via Python?Constitutional AI trains models with a set of guiding rules (“constitution”) and uses AI-based feedback to produce helpful, harmless outputs. To use Claude: pip install anthropic==0.28; create a key; then use Anthropic’s messages API (e.g., anthropic.messages.create(model='claude-3-opus-20240229', ...)) to send chat-style prompts.How does Cohere’s Coral reduce hallucinations and provide citations?Cohere emphasizes grounding via connectors (e.g., Web search, databases). When enabled, Coral retrieves relevant sources (RAG: Retrieval-Augmented Generation) and shows the queries and documents used, so you can verify answers. In Python (cohere==4.43), call client.chat(prompt, connectors=[{'id': 'web-search'}]) to get both the answer and the supporting sources.What sets Google’s Gemini apart, and how do I use it programmatically?Gemini is multimodal (e.g., images) and integrates with Google tools via Extensions (e.g., access to Gmail). Programmatic use: pip install google-generativeai==0.7; configure with genai.configure(api_key=...); then model = genai.GenerativeModel('gemini-1.5-flash'); reply = model.generate_content(...).Why use Hugging Face models locally, and how do I get started?Open-source models let you run locally (no API keys), which can reduce cost and keep sensitive data in-house. Install transformers==4.36 and torch==2.1.2, then create a task-specific pipeline, e.g., transformers.pipeline(model='cardiffnlp/twitter-roberta-base-sentiment-latest') for sentiment analysis. Local performance depends on your hardware, but specialized open-source models often provide excellent quality/cost for focused tasks.
pro $24.99 per month
access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!