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

# Integrations

> OpenAI, Anthropic, Google GenAI, LangChain, and Google ADK

The Flint AI Python SDK supports five LLM integrations. Standard LLM clients use `flintai.wrap()`, while Google ADK uses a dedicated plugin.

| Integration                                                         | Method                                    |
| ------------------------------------------------------------------- | ----------------------------------------- |
| OpenAI                                                              | `flintai.wrap()`                          |
| Anthropic                                                           | `flintai.wrap()`                          |
| Google GenAI                                                        | `flintai.wrap()` (requires `llm_api_key`) |
| LangChain (`ChatOpenAI`, `ChatAnthropic`, `ChatGoogleGenerativeAI`) | `flintai.wrap()`                          |
| Google ADK                                                          | `ADKGuardrailsPlugin`                     |

## OpenAI

Wrap an `openai.OpenAI()` client to route completions through the guardrails proxy.

```python theme={null}
import openai
import flintai

client = openai.OpenAI(api_key="your-openai-api-key")
client = flintai.wrap(
    client,
    gateway_url="https://app.flintai.dev",
    api_key="your-flintai-api-key",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
)
```

After wrapping, use the client exactly as before — the SDK redirects traffic transparently.

## Anthropic

Wrap an `anthropic.Anthropic()` client the same way.

```python theme={null}
import anthropic
import flintai

client = anthropic.Anthropic(api_key="your-anthropic-api-key")
client = flintai.wrap(
    client,
    gateway_url="https://app.flintai.dev",
    api_key="your-flintai-api-key",
)

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
```

## Google GenAI

Google GenAI clients don't expose `api_key` as an attribute, so `llm_api_key` can't be auto-extracted. Pass it explicitly if you want to forward your key, or omit it to let the proxy use its own upstream credentials:

```python theme={null}
import google.genai
import flintai

client = google.genai.Client(api_key="your-gemini-api-key")
client = flintai.wrap(
    client,
    gateway_url="https://app.flintai.dev",
    api_key="your-flintai-api-key",
    llm_api_key="your-gemini-api-key",  # optional; omit to use proxy's own credentials
)

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="Hello",
)
```

<Note>
  The SDK automatically normalizes the gateway URL with a trailing slash for Google GenAI — do not add one yourself.
</Note>

## LangChain

`flintai.wrap()` auto-detects LangChain chat models, extracts the underlying SDK client, and applies guardrails routing. Supported models:

* `ChatOpenAI` (from `langchain-openai`)
* `ChatAnthropic` (from `langchain-anthropic`)
* `ChatGoogleGenerativeAI` (from `langchain-google-genai`)

```python theme={null}
from langchain_openai import ChatOpenAI
import flintai

llm = ChatOpenAI(model="gpt-4o", api_key="your-openai-api-key")
llm = flintai.wrap(
    llm,
    gateway_url="https://app.flintai.dev",
    api_key="your-flintai-api-key",
)

response = llm.invoke("Hello")
```

<Tabs>
  <Tab title="ChatAnthropic">
    ```python theme={null}
    from langchain_anthropic import ChatAnthropic
    import flintai

    llm = ChatAnthropic(model="claude-sonnet-4-20250514", api_key="your-anthropic-api-key")
    llm = flintai.wrap(
        llm,
        gateway_url="https://app.flintai.dev",
        api_key="your-flintai-api-key",
    )

    response = llm.invoke("Hello")
    ```
  </Tab>

  <Tab title="ChatGoogleGenerativeAI">
    ```python theme={null}
    from langchain_google_genai import ChatGoogleGenerativeAI
    import flintai

    llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", google_api_key="your-gemini-api-key")
    llm = flintai.wrap(
        llm,
        gateway_url="https://app.flintai.dev",
        api_key="your-flintai-api-key",
    )

    response = llm.invoke("Hello")
    ```
  </Tab>
</Tabs>

For LangChain agents with deeper lifecycle integration (session tracking, agent identity headers), use `LangChainGuardrailsMiddleware` instead:

```python theme={null}
from flintai.plugins.langchain import LangChainGuardrailsMiddleware
from langchain.agents import create_agent

middleware = LangChainGuardrailsMiddleware()

agent = create_agent(
    model="openai:gpt-4o",
    tools=[...],
    middleware=[middleware],
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "Hello!"}]},
    config={"configurable": {"thread_id": "session-456"}},
)
```

See [Usage](/flintai/platform/python-sdk/usage#langchain-middleware) for more details.

## Google ADK

ADK agents lazily create their GenAI client at runtime, so `flintai.wrap()` cannot be used. Use `ADKGuardrailsPlugin` to configure guardrails routing at the agent level:

```python theme={null}
from flintai.plugins.adk import ADKGuardrailsPlugin
from google.adk.agents import LlmAgent

plugin = ADKGuardrailsPlugin(
    gateway_url="https://app.flintai.dev",
    api_key="your-flintai-api-key",
    llm_api_key="your-gemini-api-key",
)

agent = LlmAgent(
    name="my_agent",
    model="gemini-2.5-flash",
    instruction="You are a helpful assistant.",
    tools=[...],
    generate_content_config=plugin.content_config,
    before_model_callback=plugin.before_model_callback,
    on_model_error_callback=plugin.on_model_error,
)
```

<Tip>
  Set `FLINTAI_GATEWAY_URL`, `FLINTAI_API_KEY`, and `FLINTAI_LLM_API_KEY` as environment variables (or in a `.env` file), then create the plugin with no arguments: `ADKGuardrailsPlugin()`.
</Tip>

The plugin handles three concerns:

* **Routing** — `content_config` directs LLM traffic through the guardrails proxy
* **Identity** — `before_model_callback` injects agent name, agent ID, and session ID headers on each call
* **Error handling** — `on_model_error` converts guardrails blocks into an `LlmResponse` the agent can handle gracefully

See [Usage](/flintai/platform/python-sdk/usage#google-adk) for more details on the plugin's behavior and configuration.

## Version compatibility

Pin your provider SDK to the tested ranges to avoid breakage from private API changes:

| Provider SDK             | Supported versions |
| ------------------------ | ------------------ |
| `openai`                 | `>=2.40.0, <3`     |
| `anthropic`              | `>=0.105.2, <1`    |
| `google-genai`           | `>=2.7, <3`        |
| `google-adk`             | `>=2.1, <3`        |
| `langchain-openai`       | `>=1.2, <2`        |
| `langchain-anthropic`    | `>=1.4, <2`        |
| `langchain-google-genai` | `>=4.2, <5`        |

The SDK logs a warning if your installed provider version is outside these ranges.

## Known limitations

* **Private attribute mutation** — `flintai.wrap()` modifies internal attributes of LLM SDK clients (`_base_url`, `_custom_headers`, `_api_client._http_options`) to redirect traffic. These are not part of the providers' public APIs and may change without notice.
* **Async clients** — `AsyncOpenAI` and `AsyncAnthropic` are not supported. Use sync clients only.
* **Google GenAI `api_key`** — Google GenAI clients don't expose `api_key` as an attribute, so `llm_api_key` can't be auto-extracted. Pass it explicitly to forward your key, or omit it to use the proxy's own credentials.
* **Multiple provider keys in environment** — If multiple provider API keys are set (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`), auto-detection fails. Pass `provider` explicitly to `flintai.init()`.

## Next steps

<CardGroup cols={2}>
  <Card title="Usage" icon="code" href="/flintai/platform/python-sdk/usage">
    Advanced patterns, error handling, and best practices
  </Card>

  <Card title="Configuration" icon="sliders" href="/flintai/platform/python-sdk/configuration">
    Environment variables, credentials, and gateway setup
  </Card>
</CardGroup>
