GPT-4.1 API

GPT-4.1 is OpenAI's large-context language model with up to 1M token input and improved instruction following.

Modalities
Text, ImageText
In / Out price
$2/$8per 1M
Context window
1.05M tokens
Released
Apr 14, 2025

GPT-4.1 overview

The pelican test: one prompt, every text model, unedited SVG output from Nov 3, 2026.

SVG of a pelican riding a bicycle, written by GPT-4.1 through AI/ML API

GPT-4.1 by OpenAI

GPT-4.1 advanced coding-focused AI with million-token context and superior instruction following.

GPT-4.1 specs

Model ID
openai/gpt-4.1-2025-04-14
Developer
OpenAI
Context window
1,047,576 tokens
Max output
32,768 tokens
Input
Text, Image
Output
Text
API
OpenAI-compatible, base URL https://api.aimlapi.com/v1

GPT-4.1 Description

GPT-4.1 is OpenAI's advanced large language model designed with significant improvements in coding capabilities, instruction following, and long context processing. The model represents a substantial step forward from GPT-4o, offering enhanced performance while maintaining a lower cost profile than GPT-4.5. GPT-4.1 excels particularly in software engineering tasks, with optimizations for real-world developer use cases including frontend coding, cleaner code editing, and precise instruction adherence.

Context Window and Token Capacity

GPT-4.1 processes input contexts of up to 1,047,576 tokens (approximately 750,000 words). The model generates outputs of up to 32,768 tokens in a single response.

All training data for GPT-4.1 extends to May 31, 2024, which serves as its knowledge cutoff date.

Performance Benchmarks

  • SWE-bench Verified: 52-54.6% (21.4% improvement over GPT-4o)
  • Instruction Following (IFEval): 87.4% (6.4% improvement over GPT-4o)
  • Long Context Reasoning (OpenAI-MRCR): 84% accuracy with 8,000 tokens, degrading to 50% with 1 million tokens
  • Graph Reasoning (Graphwalks): 61.7% (19.7% improvement over GPT-4o)
  • Multi-challenge Benchmark: 38.3% (10.5% improvement over GPT-4o)

Programming and Software Development

GPT-4.1 delivers enhanced frontend coding with significantly fewer unnecessary edits. The model provides improved code refactoring and debugging capabilities for complex software projects. It follows programming best practices with superior accuracy compared to previous models. GPT-4.1 generates optimized diffs through extensive training on recommended formats. The system supports advanced agentic development workflows for autonomous coding tasks. It achieves state-of-the-art performance across standard coding benchmarks, particularly in practical software engineering tasks.

Long Context Processing

GPT-4.1 processes and reasons over documents containing up to 1 million tokens with maintained coherence. The model effectively retrieves specific information from large corpuses even when relevant data is deeply embedded. It analyzes entire codebases at once, maintaining context across multiple files and functions. GPT-4.1 handles multi-document analysis with improved accuracy for complex research and legal applications. The system is optimized for XML-style delimiters that enhance structure and information retention in long-context inputs.

Instruction Following

GPT-4.1 adheres precisely to explicit formatting instructions with higher consistency than previous models. The system handles negative instructions (what not to do) with improved accuracy and reliability. It performs multi-step ordered instructions with enhanced sequential understanding and context retention. GPT-4.1 executes ranking and sorting tasks with greater accuracy based on specified criteria. The model interprets prompts more literally, which provides greater control but requires more explicit instructions from users.

Use cases

  • AI pair programming and software development assistance
  • Technical documentation generation and automated report writing
  • Multimodal content creation and analysis
  • Complex customer support and conversational AI
  • Research applications requiring advanced reasoning and long-context understanding

Capabilities

  • Function calling
  • Streaming
  • Structured outputs
  • Reasoning

GPT-4.1 benchmarks by Artificial Analysis

See how GPT-4.1 compares in generation speed and latency. Data retrieved Nov 3, 2026.

Speed

Output tokens / second

Benchmark results

Compare 17 models available on AI/ML API across 5 independent benchmarks.

Humanity's Last Exam

Expert-written questions across academic subjects.

GPT-4.1 API pricing

GPT-4.1 pricing in US dollars
UsagePriceUnit
Input$21M tokens
Output$81M tokens
Cached input$0.51M tokens

Prices from the AI/ML API price list, checked on Nov 4, 2026.

GPT-4.1 vs other models: token prices

AI/ML API input and output rates for 5 models, per million tokens.

AI/ML API model prices in USD per million tokens
ModelInputOutput
GPT-4.1$2$8
GPT-6 Luna$0.1$0.5
GPT-6.1 Terra$1$5
GPT-6.1 Sol$2$10
GPT-6.1 Terra Pro$2.12$10.58

How to use the GPT-4.1 API

View docs

Build with your agent

Give your agent the model details, code and documentation.

1Get your API key

Create API key
export AIMLAPI_KEY="8f2b4c7d9a1e6b3f…"

2Make your first request

curl 'https://api.aimlapi.com/v1/chat/completions' \
  -H "Authorization: Bearer $AIMLAPI_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "openai/gpt-4.1-2025-04-14",
  "messages": [
    {
      "role": "user",
      "content": "Write a haiku about the ocean."
    }
  ]
}'

Related articles

All posts

GPT-4.1 FAQ

What is the context window of GPT-4.1?

GPT-4.1 has a 1,047,576 tokens context window and can return up to 32,768 tokens.

What inputs and outputs does GPT-4.1 support?

GPT-4.1 takes image, text as input and returns text.

What is the model ID for GPT-4.1?

Use openai/gpt-4.1-2025-04-14 as the model id. Requests go to https://api.aimlapi.com/v1/chat/completions.

When was GPT-4.1 released?

GPT-4.1 became available on August 7, 2025.

How much does GPT-4.1 cost?

GPT-4.1 costs $2 input and $8 output per 1M tokens on AI/ML API, billed as you go with no subscription.

Does GPT-4.1 support streaming?

Yes, GPT-4.1 can stream responses as they are generated.

Can GPT-4.1 read images?

Yes, GPT-4.1 accepts image input alongside text.

Who created GPT-4.1?

GPT-4.1 was built by OpenAI.

Start building with GPT-4.1

GPT-4.1 API

openai/gpt-4.1-2025-04-14

Build with your agent

Give your agent the model details, code and documentation.

1Get your API key

Create API key
export AIMLAPI_KEY="8f2b4c7d9a1e6b3f…"

2Make your first request

curl 'https://api.aimlapi.com/v1/chat/completions' \
  -H "Authorization: Bearer $AIMLAPI_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "openai/gpt-4.1-2025-04-14",
  "messages": [
    {
      "role": "user",
      "content": "Write a haiku about the ocean."
    }
  ]
}'