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:
| Language | Package | Install |
|---|---|---|
| Python | oilpriceapi | pip install oilpriceapi |
| Node.js | oilpriceapi | npm install oilpriceapi |
| Go | oilpriceapi-go | go get github.com/OilpriceAPI/oilpriceapi-go |
| PHP | oilpriceapi/oilpriceapi | composer 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",
)
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",
});
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');
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.
| Language | Guide | Features |
|---|---|---|
| Java | Java Guide | HttpClient, Spring Boot, async |
| Rust | Rust Guide | reqwest, tokio, Actix-web |
| Ruby | Ruby Guide | Net::HTTP, Faraday |
| C# | C# Guide | HttpClient, .NET Core |
| R | R Guide | httr, 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");
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:
| Status | Error | Action |
|---|---|---|
| 401 | Invalid API key | Check key format |
| 404 | Commodity not found | Verify code |
| 429 | Rate limited | Implement backoff |
| 500 | Server error | Retry 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