> ## Documentation Index
> Fetch the complete documentation index at: https://www.edenai.co/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Pydantic AI

> Use Pydantic AI with Eden AI to build type-safe agents on 500+ AI models through one API.

export const TechArticleSchema = ({title, description, path, articleSection, about, proficiencyLevel = "Beginner", dependencies, keywords = [], datePublished, dateModified, image, inLanguage = "en"}) => {
  const baseUrl = "https://www.edenai.co/docs";
  const canonicalUrl = `${baseUrl}/${path}`.replace(/\/+$/, "");
  const ogParams = new URLSearchParams({
    division: articleSection || "",
    title: title || "",
    description: description || ""
  });
  const resolvedImage = image || `https://edenai.mintlify.app/_mintlify/api/og?${ogParams.toString()}`;
  const data = {
    "@context": "https://schema.org",
    "@type": "TechArticle",
    "@id": `${canonicalUrl}#techarticle`,
    mainEntityOfPage: {
      "@type": "WebPage",
      "@id": canonicalUrl
    },
    headline: title,
    name: title,
    description: description,
    url: canonicalUrl,
    inLanguage: inLanguage,
    isPartOf: {
      "@type": "WebSite",
      name: "Eden AI Documentation",
      url: baseUrl
    },
    author: [{
      "@type": "Organization",
      name: "Eden AI",
      url: "https://www.edenai.co/"
    }],
    publisher: {
      "@type": "Organization",
      name: "Eden AI",
      url: "https://www.edenai.co/",
      logo: {
        "@type": "ImageObject",
        url: "https://www.edenai.co/assets/logo.png"
      }
    }
  };
  if (articleSection) data.articleSection = articleSection;
  if (about) data.about = {
    "@type": "Thing",
    name: about
  };
  if (proficiencyLevel) data.proficiencyLevel = proficiencyLevel;
  if (dependencies) data.dependencies = dependencies;
  if (keywords && keywords.length) data.keywords = keywords;
  if (datePublished) data.datePublished = datePublished;
  if (dateModified) data.dateModified = dateModified;
  data.image = Array.isArray(resolvedImage) ? resolvedImage : [resolvedImage];
  const json = JSON.stringify(data);
  const schemaId = `techarticle-${canonicalUrl}`;
  React.useEffect(() => {
    if (typeof document === "undefined") return;
    document.querySelectorAll(`script[data-schema-id="${schemaId}"]`).forEach(n => n.remove());
    const script = document.createElement("script");
    script.type = "application/ld+json";
    script.dataset.schemaId = schemaId;
    script.textContent = json;
    document.head.appendChild(script);
    return () => script.remove();
  }, [json, schemaId]);
  return null;
};

<TechArticleSchema title={"Pydantic AI"} description={"Use Pydantic AI with Eden AI to build type-safe agents on 500+ AI models through one API."} path="v3/integrations/pydantic-ai" articleSection="AI Frameworks" about={"LLM Framework Integration"} proficiencyLevel="Intermediate" keywords={["Eden AI", "AI API", "Pydantic AI", "Python", "Agents"]} datePublished="2026-07-16T00:00:00Z" dateModified="2026-07-16T00:00:00Z" />

Use Pydantic AI with Eden AI to build type-safe agents on 500+ AI models through one API.

## Overview

Pydantic AI is a type-safe, structured-output agent framework for Python. It works with any OpenAI-compatible endpoint through `OpenAIChatModel` + `OpenAIProvider`, so you can point it at Eden AI's V3 API and access models from OpenAI, Anthropic, Google, Cohere, Meta, and more — behind one key, with EU-based, GDPR-aligned inference.

## Installation

<CodeGroup>
  ```bash pip theme={null}
  pip install pydantic-ai
  ```

  ```bash poetry theme={null}
  poetry add pydantic-ai
  ```
</CodeGroup>

## Quick Start

Point Pydantic AI's OpenAI model at Eden AI:

<CodeGroup>
  ```python Python theme={null}
  from pydantic_ai import Agent
  from pydantic_ai.models.openai import OpenAIChatModel
  from pydantic_ai.providers.openai import OpenAIProvider

  model = OpenAIChatModel(
      "openai/gpt-5.5",
      provider=OpenAIProvider(
          api_key="YOUR_EDEN_AI_API_KEY",  # Get from https://app.edenai.run
          base_url="https://api.edenai.run/v3",
      ),
  )

  agent = Agent(model)
  result = agent.run_sync("Hello! How are you?")
  print(result.output)
  ```
</CodeGroup>

## Available Models

Access models from multiple providers using the `provider/model` format:

**OpenAI**

* `openai/gpt-5.5`
* `openai/gpt-5-mini`

**Anthropic**

* `anthropic/claude-sonnet-5`
* `anthropic/claude-opus-4-8`
* `anthropic/claude-haiku-4-5`

**Google**

* `google/gemini-2.5-pro`
* `google/gemini-3.5-flash`

**Mistral**

* `mistral/mistral-large-2512`
* `mistral/mistral-small-2603`

## Structured Output

Pydantic AI's signature feature works unchanged — define a Pydantic `output_type` and the agent returns a validated object, whichever Eden AI model you choose:

<CodeGroup>
  ```python Python theme={null}
  from pydantic import BaseModel
  from pydantic_ai import Agent
  from pydantic_ai.models.openai import OpenAIChatModel
  from pydantic_ai.providers.openai import OpenAIProvider

  class City(BaseModel):
      name: str
      country: str
      population: int

  model = OpenAIChatModel(
      "anthropic/claude-sonnet-5",
      provider=OpenAIProvider(
          api_key="YOUR_EDEN_AI_API_KEY",
          base_url="https://api.edenai.run/v3",
      ),
  )

  agent = Agent(model, output_type=City)
  result = agent.run_sync("Tell me about the capital of France.")
  print(result.output)  # City(name='Paris', country='France', population=...)
  ```
</CodeGroup>

## Multi-Turn Conversations

Keep conversation history across runs with `message_history`:

<CodeGroup>
  ```python Python theme={null}
  from pydantic_ai import Agent
  from pydantic_ai.models.openai import OpenAIChatModel
  from pydantic_ai.providers.openai import OpenAIProvider

  model = OpenAIChatModel(
      "anthropic/claude-sonnet-5",
      provider=OpenAIProvider(
          api_key="YOUR_EDEN_AI_API_KEY",
          base_url="https://api.edenai.run/v3",
      ),
  )
  agent = Agent(model, system_prompt="You are a helpful assistant.")

  result = agent.run_sync("What is the capital of France?")
  print(result.output)

  # Continue the conversation with prior context
  result = agent.run_sync(
      "What's its population?",
      message_history=result.all_messages(),
  )
  print(result.output)
  ```
</CodeGroup>

## Error Handling

<CodeGroup>
  ```python Python theme={null}
  from pydantic_ai import Agent
  from pydantic_ai.models.openai import OpenAIChatModel
  from pydantic_ai.providers.openai import OpenAIProvider
  from pydantic_ai.exceptions import ModelHTTPError, UnexpectedModelBehavior

  model = OpenAIChatModel(
      "openai/gpt-5.5",
      provider=OpenAIProvider(
          api_key="YOUR_EDEN_AI_API_KEY",
          base_url="https://api.edenai.run/v3",
      ),
  )
  agent = Agent(model)

  try:
      result = agent.run_sync("Hello!")
      print(result.output)
  except ModelHTTPError as e:
      print(f"Model HTTP error (auth, rate limit, bad request): {e}")
  except UnexpectedModelBehavior as e:
      print(f"Unexpected model behavior: {e}")
  ```
</CodeGroup>

## Environment Variables

<CodeGroup>
  ```bash .env theme={null}
  EDEN_AI_API_KEY=your_api_key_here
  ```

  ```python Python theme={null}
  import os
  from pydantic_ai.models.openai import OpenAIChatModel
  from pydantic_ai.providers.openai import OpenAIProvider

  model = OpenAIChatModel(
      "openai/gpt-5.5",
      provider=OpenAIProvider(
          api_key=os.getenv("EDEN_AI_API_KEY"),
          base_url="https://api.edenai.run/v3",
      ),
  )
  ```
</CodeGroup>

## Next Steps

* [Chat Completions](/docs/v3/llms/chat-completions) - Core LLM endpoint
* [List LLM Models](/docs/v3/llms/listing-models) - Browse available providers and models
* [OpenAI SDK (Python)](/docs/v3/integrations/openai-sdk-python) - Direct SDK usage
