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 |
| PHP | oilpriceapi/oilpriceapi | composer 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)
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"]);
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
Complete integration guides, including full client implementations for languages without an official SDK:
| Language | Guide | Features |
|---|---|---|
| Java | Java Guide | HttpClient, Spring Boot, async |
| Go | Go Guide | Standard library, concurrency |
| Rust | Rust Guide | reqwest, tokio, Actix-web |
| PHP | PHP Guide | Official SDK (composer require oilpriceapi/oilpriceapi), Laravel, WordPress |
| 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.
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:
| 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