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
Gooilpriceapi-gogo get github.com/OilpriceAPI/oilpriceapi-go
PHPoilpriceapi/oilpriceapicomposer require oilpriceapi/oilpriceapi

Python SDK

import os
from datetime import date, timedelta

from oilpriceapi import OilPriceAPI

end_date = date.today()

with OilPriceAPI(api_key=os.environ["OILPRICEAPI_KEY"]) as client:
    # Get latest WTI price
    price = client.prices.get("WTI_USD")
    print(f"WTI: {price.value} {price.currency}")

    # Get daily Brent history for the past 30 days
    history = client.historical.get(
        commodity="BRENT_CRUDE_USD",
        start_date=end_date - timedelta(days=30),
        end_date=end_date,
        interval="daily",
    )

Full Python Guide

Node.js SDK

import { OilPriceAPI } from "oilpriceapi";

const client = new OilPriceAPI({
  apiKey: process.env.OILPRICEAPI_KEY,
});

// Get latest WTI price
const [wti] = await client.getLatestPrices({ commodity: "WTI_USD" });
console.log(`${wti.code}: ${wti.price} ${wti.currency}`);

// Get daily Brent history for the past month
const history = await client.getHistoricalPrices({
  commodity: "BRENT_CRUDE_USD",
  period: "past_month",
  interval: "daily",
});

Full JavaScript Guide

Go SDK

Official Go SDK. Add the current compatible module release with:

go get github.com/OilpriceAPI/oilpriceapi-go

Go package reference · Full Go 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

Direct REST integration guides are available for languages without an official SDK, including Ruby and C#. The Go and PHP guides also cover direct HTTP clients alongside their official packages.

LanguageGuideFeatures
JavaJava GuideHttpClient, Spring Boot, async
RustRust Guidereqwest, tokio, Actix-web
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.

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: 8/23/26, 10:45 PM
Next
SDK Examples for Pagination and Error Handling