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

# OpenAI Provider

> Use OpenAI GPT models with PraisonAI TypeScript

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    U[Input] --> A[Agent]
    A --> O[Output]

    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

    class A agent
    class U,O tool
```

# OpenAI Provider

Use OpenAI's GPT models including GPT-4o, GPT-4, and GPT-3.5 with PraisonAI TypeScript.

## Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export OPENAI_API_KEY=sk-...
```

| Variable | Required | Description |
| - | - | - |
| `OPENAI_API_KEY` | Yes | Your OpenAI API key |
| `OPENAI_ORG_ID` | No | Organization ID (optional) |
| `OPENAI_BASE_URL` | No | Custom base URL (for proxies) |

## Supported Modalities

| Modality | Supported |
| - | - |
| Text/Chat | ✅ |
| Embeddings | ✅ |
| Image | ✅ |
| Audio | ✅ |
| Speech | ✅ |
| Tools | ✅ |

## Quick Start

**1. Simple Usage**

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

const agent = new Agent({
  name: 'Assistant',
  instructions: 'You are a helpful assistant.',
  llm: 'openai/gpt-4o-mini'
});

const response = await agent.chat('Hello!');
console.log(response);
```

**2. With Configuration**

Adjust provider credentials and model settings for production — see the sections above.

## Available Models

| Model | Description | Context |
| - | - | - |
| `gpt-4o` | Latest multimodal model | 128K |
| `gpt-4o-mini` | Fast, affordable | 128K |
| `gpt-4-turbo` | High capability | 128K |
| `gpt-4` | Original GPT-4 | 8K |
| `gpt-3.5-turbo` | Fast, cost-effective | 16K |
| `o1` | Reasoning model | 128K |
| `o1-mini` | Fast reasoning | 128K |

## Advanced Configuration

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

const agent = new Agent({
  name: 'CustomAgent',
  instructions: 'You are an expert analyst.',
  llm: 'openai/gpt-4o',
  llmConfig: {
    temperature: 0.7,
    maxTokens: 4096,
    topP: 0.9,
  }
});
```

## With Tools

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

const searchTool = {
  name: 'search',
  description: 'Search the web',
  parameters: {
    type: 'object',
    properties: {
      query: { type: 'string', description: 'Search query' }
    },
    required: ['query']
  },
  execute: async ({ query }) => {
    return `Results for: ${query}`;
  }
};

const agent = new Agent({
  name: 'SearchAgent',
  instructions: 'Search for information when asked.',
  llm: 'openai/gpt-4o-mini',
  tools: [searchTool]
});
```

## Streaming

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent } from 'praisonai';

const agent = new Agent({
  name: 'StreamAgent',
  instructions: 'You are helpful.',
  llm: 'openai/gpt-4o-mini'
});

for await (const chunk of agent.stream('Tell me a story')) {
  process.stdout.write(chunk);
}
```

## Multi-Agent Workflow

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent, AgentTeam } from 'praisonai';

const researcher = new Agent({
  name: 'Researcher',
  instructions: 'Research topics thoroughly.',
  llm: 'openai/gpt-4o'
});

const writer = new Agent({
  name: 'Writer',
  instructions: 'Write clear summaries.',
  llm: 'openai/gpt-4o-mini'
});

const agents = new AgentTeam({
  agents: [researcher, writer],
  tasks: [
    { agent: researcher, description: 'Research {topic}' },
    { agent: writer, description: 'Summarize the research' }
  ]
});

const result = await agents.start({ topic: 'AI trends' });
```

## Troubleshooting

### Invalid API Key

```
Error: Authentication failed
```

**Solution**: Verify your `OPENAI_API_KEY` is set correctly and has not expired.

### Rate Limits

```
Error: Rate limit exceeded
```

**Solution**: Implement retry logic or upgrade your OpenAI plan.

### Model Not Found

```
Error: Model not found
```

**Solution**: Check the model name is correct. Use `gpt-4o-mini` instead of `gpt-4-mini`.

## Related

> [card] [OpenAI CLI Usage](https://praison.ai/docs/js/providers/openai-cli.md)
>
> OpenAI CLI Usage

> [card] [Providers Overview](https://praison.ai/docs/js/providers.md)
>
> Providers Overview


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.