Skip to main content

Overview

OpenAI provides industry-leading language models with the GPT-5 series. This guide covers setup, configuration, and best practices for using OpenAI models with the MCP Server.
GPT-5 is OpenAI’s latest flagship model with enhanced reasoning, multimodal capabilities, and improved efficiency.

Available Models

Recommended: gpt-5.1 for production (best performance/cost ratio)

Quick Start

1

Get API Key

  1. Go to https://platform.openai.com/api-keys
  2. Click “Create new secret key”
  3. Copy the key (starts with sk-...)
  4. Store securely (never commit to Git!)
2

Configure

Using Infisical (Recommended):
Using Environment Variables (Development only):
3

Test

Configuration Options

Basic Configuration

Advanced Configuration

Model Selection Strategy

Features

Function Calling (Tools)

Vision (GPT-5, GPT-5 Pro)

Structured Output (JSON Mode)

Streaming

System Prompts

Response Format (JSON Mode)

Production Deployment

Kubernetes Configuration

Rate Limiting

Error Handling

Performance Optimization

Batching

Token Management

Caching

Cost Optimization

Model Selection

Usage Tracking

Budget Limits

Monitoring

LangSmith Integration

Custom Metrics

Troubleshooting

Error: 401 Incorrect API key providedSolutions:
Error: 429 Rate limit reachedSolutions:
Error: This model's maximum context length is 128000 tokensSolutions:
Error: APITimeoutError: Request timed outSolutions:

Best Practices

  • Never commit API keys to Git
  • Use Infisical or similar secret manager
  • Rotate API keys quarterly
  • Monitor for unusual usage patterns
  • Implement per-user rate limiting
  • Validate and sanitize all inputs
  • Use streaming for better UX
  • Batch similar requests when possible
  • Choose appropriate model for task complexity
  • Implement connection pooling
  • Set reasonable timeouts
  • Cache responses when appropriate
  • Track usage per user/team
  • Set budget alerts
  • Use cheaper models for simple tasks (gpt-5.1-nano, gpt-5-mini)
  • Implement token limits
  • Monitor and optimize prompt efficiency
  • Use gpt-5-mini or gpt-5.1-nano for development/testing
  • Implement exponential backoff
  • Handle rate limits gracefully
  • Add fallback to other providers
  • Log all errors with context
  • Monitor latency and error rates
  • Set up alerting for failures

Next Steps

Multi-LLM Setup

Configure multiple providers

Google Gemini

Set up Gemini models

Anthropic Claude

Set up Claude models

Observability

Monitor OpenAI usage

OpenAI Ready: Leverage GPT-5 series models in your MCP Server!