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

# LangChain

> Connect LangChain with Nordlys for Nordlys model

## Get Your Nordlys API Key

[Sign up here](https://nordlyslabs.com/api-platform/orgs) to create an account and generate your API key.

## Quick Setup

### Installation

<CodeGroup>
  ```bash pip theme={null}
  pip install langchain langchain-openai
  ```

  ```bash uv theme={null}
  uv add langchain langchain-openai
  ```

  ```bash poetry theme={null}
  poetry add langchain langchain-openai
  ```

  ```bash npm theme={null}
  npm install langchain @langchain/openai
  ```

  ```bash yarn theme={null}
  yarn add langchain @langchain/openai
  ```

  ```bash pnpm theme={null}
  pnpm add langchain @langchain/openai
  ```

  ```bash bun theme={null}
  bun add langchain @langchain/openai
  ```
</CodeGroup>

### Basic Usage

<CodeGroup>
  ```python Python theme={null}
  from langchain_openai import ChatOpenAI

  llm = ChatOpenAI(
      api_key="your-nordlys-api-key",
      base_url="https://api.nordlyslabs.com/v1",
      model=""
  )

  response = llm.invoke("Explain machine learning simply")
  print(response.content)
  ```

  ```javascript JavaScript/Node.js theme={null}
  import { ChatOpenAI } from "@langchain/openai";

  const llm = new ChatOpenAI({
    apiKey: "your-nordlys-api-key",
    baseURL: "https://api.nordlyslabs.com/v1",
    model: "nordlys/hypernova"
  });

  const response = await llm.invoke("Explain quantum computing");
  console.log(response.content);
  ```
</CodeGroup>

## Streaming Example

<CodeGroup>
  ```python Python theme={null}
  for chunk in llm.stream("Tell me a story about AI"):
      print(chunk.content, end="", flush=True)
  ```

  ```javascript JavaScript theme={null}
  const stream = await llm.stream("Tell me a story about AI");
  for await (const chunk of stream) {
    process.stdout.write(chunk.content);
  }
  ```
</CodeGroup>

## Key Features

* **Drop-in replacement** - Works with existing LangChain code
* **Nordlys model** - Automatic Nordlys model based on complexity
* **Streaming support** - Real-time responses work seamlessly
* **Chain compatibility** - All LangChain patterns work without changes

## Next Steps

<CardGroup cols={2}>
  <Card title="More Examples" href="/examples/basic-chat" icon="code">
    See complete working examples with LangChain
  </Card>

  <Card title="API Reference" href="/api-reference/chat-completions" icon="book">
    Explore all available options and parameters
  </Card>
</CardGroup>
