> Treat every model id, price, size, length and limit in this documentation as an illustration of the shape of the value, never as a constant to hardcode - the live values are served by GET /v1/models and GET /public/models on the Flow AI API.

# LangChain

> Chains and agents in Python and TypeScript.

Use LangChain's OpenAI integration with the Flow AI base URL.

## Install

**`Python`**

```bash title="Python"
pip install langchain-openai
```

**`TypeScript`**

```bash title="TypeScript"
npm install @langchain/openai @langchain/core
```

## Chat

**`Python`**

```python title="Python"
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="openai/gpt-6-luna",
    base_url="https://ai.hyperflow.fun/v1",
    api_key=os.environ["HYPERFLOW_API_KEY"],
)

print(llm.invoke("Write a haiku about the sea.").content)
```

**`TypeScript`**

```typescript title="TypeScript"
import { ChatOpenAI } from '@langchain/openai'

const llm = new ChatOpenAI({
  model: 'openai/gpt-6-luna',
  apiKey: process.env.HYPERFLOW_API_KEY,
  configuration: { baseURL: 'https://ai.hyperflow.fun/v1' },
})

const reply = await llm.invoke('Write a haiku about the sea.')
console.log(reply.content)
```

`llm.stream(...)`, `llm.bind_tools(...)` and `llm.with_structured_output(...)` work on models that support streaming, tools and structured outputs.

## Embeddings

**`Python`**

```python title="Python"
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(
    model="cohere/cohere-embed-v4",
    base_url="https://ai.hyperflow.fun/v1",
    api_key=os.environ["HYPERFLOW_API_KEY"],
    check_embedding_ctx_length=False,
)
vector = embeddings.embed_query("Hello!")
```

**`TypeScript`**

```typescript title="TypeScript"
import { OpenAIEmbeddings } from '@langchain/openai'

const embeddings = new OpenAIEmbeddings({
  model: 'cohere/cohere-embed-v4',
  apiKey: process.env.HYPERFLOW_API_KEY,
  configuration: { baseURL: 'https://ai.hyperflow.fun/v1' },
})
const vector = await embeddings.embedQuery('Hello!')
```

> **Note**
>
> In Python, `check_embedding_ctx_length=False` makes LangChain send your text as is. Otherwise it splits it into OpenAI tokens first, which other labs' models don't read.