OilPriceAPI Docs
GitHub
GitHub
  • SDKs & Languages

    • SDKs & Language Guides
    • SDK Examples for Pagination and Error Handling
    • TypeScript Response Types
  • Language Guides

    • Java Oil Price API Integration
    • Go Oil Price API Integration
    • Rust Oil Price API Integration
    • PHP Oil Price API Integration
    • Ruby Oil Price API Integration
    • C# .NET Oil Price API Integration
    • R Language Oil Price API Integration

SDKs & Language Guides

Integrate OilPriceAPI into your application using your preferred programming language. All guides include complete client implementations, error handling, and production best practices.

Official SDKs

Install our maintained SDKs for the fastest integration:

LanguagePackageInstall
Pythonoilpriceapipip install oilpriceapi
Node.jsoilpriceapinpm install oilpriceapi
PHPoilpriceapi/oilpriceapicomposer require oilpriceapi/oilpriceapi

Python SDK

from oilpriceapi import OilPriceAPI

client = OilPriceAPI("YOUR_API_KEY")

# Get latest WTI price
price = client.prices.get("WTI_USD")
print(f"WTI: {price.formatted}")

# Get historical data
history = client.prices.historical("BRENT_CRUDE_USD", days=30)

Full Python Guide

Node.js SDK

import OilPriceAPI from "oilpriceapi";

const client = new OilPriceAPI("YOUR_API_KEY");

// Get latest prices
const wti = await client.prices.latest("WTI_USD");
console.log(`WTI: ${wti.formatted}`);

// Get multiple prices
const prices = await client.prices.latest(["WTI_USD", "BRENT_CRUDE_USD"]);

Full JavaScript Guide

PHP SDK

Zero dependencies (PHP 8.1+, ext-curl, ext-json) — works on shared hosting and inside WordPress.

use OilPriceAPI\Client;

$client = new Client('YOUR_API_KEY');

// Get latest Brent price
$brent = $client->latest('BRENT_CRUDE_USD');
echo $brent->price;

// Historical data
$month = $client->pastMonth('BRENT_CRUDE_USD');

Full PHP Guide


Language Guides

Complete integration guides, including full client implementations for languages without an official SDK:

LanguageGuideFeatures
JavaJava GuideHttpClient, Spring Boot, async
GoGo GuideStandard library, concurrency
RustRust Guidereqwest, tokio, Actix-web
PHPPHP GuideOfficial SDK (composer require oilpriceapi/oilpriceapi), Laravel, WordPress
RubyRuby GuideNet::HTTP, Faraday
C#C# GuideHttpClient, .NET Core
RR Guidehttr, statistical analysis

Quick Comparison

Simple Request (All Languages)

Every guide shows you how to make this basic request:

GET https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD
Authorization: Token YOUR_API_KEY

Response:

{
  "status": "success",
  "data": {
    "code": "WTI_USD",
    "price": 73.25,
    "formatted": "$73.25",
    "currency": "USD",
    "unit": "barrel"
  }
}

TypeScript Support

For TypeScript projects, we provide complete type definitions:

import type { Price, HistoricalPrice, FuturesContract } from "./oilpriceapi";

const price: Price = await fetchPrice("WTI_USD");

View TypeScript Types


Authentication

All API requests require authentication via the Authorization header:

Authorization: Token YOUR_API_KEY

Get your API key from the Dashboard.

Telemetry Headers (10% Bonus)

Include these headers to get 10% more requests per month:

X-Client-Name: your-app-name
X-Client-Version: 1.0.0

Common Patterns

Error Handling

All guides implement proper error handling for:

StatusErrorAction
401Invalid API keyCheck key format
404Commodity not foundVerify code
429Rate limitedImplement backoff
500Server errorRetry with backoff

Caching

Cache responses to reduce API calls:

  • Latest prices: 5 minutes
  • Historical data: 1 hour
  • Commodity list: 24 hours

Retry Logic

All guides include exponential backoff for rate limits:

Delay = 2^attempt * 1000ms

For complete pagination and multi-language retry examples, see SDK Examples for Pagination and Error Handling.


Need Help?

  • API Reference - Full endpoint documentation
  • Error Codes - All error codes explained
  • Rate Limits - Usage limits by plan
  • Support - Contact our team
Last Updated: 7/16/26, 3:41 PM
Next
SDK Examples for Pagination and Error Handling