Back to Home

API Documentation

Learn how to integrate Pham 89 AI into your applications

Getting Started

The Pham 89 AI API allows you to access 100+ AI models through a simple REST API. To get started, you'll need your API secret key which you can find in your dashboard.

Base URL: https://api.pham89ai.com

Authentication

All API requests require authentication using your secret key in the request headers:

Headers
Authorization: Bearer YOUR_SECRET_KEY
Content-Type: application/json
⚠️ Security Warning: Never expose your secret key in client-side code or public repositories. Always keep it secure on your server.

Completion Endpoint

Send a prompt to any of our 100+ AI models and receive a completion response.

Request

HTTP
POST https://api.pham89ai.com/v1/completions

Request Parameters

Parameter Type Required Description
model string Yes The AI model to use (e.g., "llama3.1", "deepseek-v3", "qwen3")
prompt string Yes The prompt text to send to the model
max_tokens integer No Maximum number of tokens to generate (default: 1000)
temperature float No Controls randomness (0.0 to 2.0, default: 0.7)
stream boolean No Enable streaming responses (default: false)

Response Format

JSON
{
  "id": "cmpl-7x8y9z",
  "model": "llama3.1",
  "created": 1702847123,
  "choices": [
    {
      "text": "The generated response text...",
      "index": 0,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 50,
    "total_tokens": 60
  }
}

Code Examples

Below are examples in various programming languages showing how to make API requests.

cURL

bash
curl -X POST https://api.pham89ai.com/v1/completions \
  -H "Authorization: Bearer YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama3.1",
    "prompt": "Explain quantum computing in simple terms",
    "max_tokens": 500,
    "temperature": 0.7
  }'

Python

python
import requests
import json

url = "https://api.pham89ai.com/v1/completions"
headers = {
    "Authorization": "Bearer YOUR_SECRET_KEY",
    "Content-Type": "application/json"
}

payload = {
    "model": "llama3.1",
    "prompt": "Explain quantum computing in simple terms",
    "max_tokens": 500,
    "temperature": 0.7
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

print(result["choices"][0]["text"])

JavaScript (Node.js)

javascript
const axios = require('axios');

const url = 'https://api.pham89ai.com/v1/completions';
const headers = {
  'Authorization': 'Bearer YOUR_SECRET_KEY',
  'Content-Type': 'application/json'
};

const payload = {
  model: 'llama3.1',
  prompt: 'Explain quantum computing in simple terms',
  max_tokens: 500,
  temperature: 0.7
};

axios.post(url, payload, { headers })
  .then(response => {
    console.log(response.data.choices[0].text);
  })
  .catch(error => {
    console.error('Error:', error.response.data);
  });

JavaScript (Fetch API)

javascript
const url = 'https://api.pham89ai.com/v1/completions';

fetch(url, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_SECRET_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    model: 'llama3.1',
    prompt: 'Explain quantum computing in simple terms',
    max_tokens: 500,
    temperature: 0.7
  })
})
  .then(response => response.json())
  .then(data => {
    console.log(data.choices[0].text);
  })
  .catch(error => {
    console.error('Error:', error);
  });

PHP

php
<?php

$url = 'https://api.pham89ai.com/v1/completions';
$headers = [
    'Authorization: Bearer YOUR_SECRET_KEY',
    'Content-Type: application/json'
];

$payload = json_encode([
    'model' => 'llama3.1',
    'prompt' => 'Explain quantum computing in simple terms',
    'max_tokens' => 500,
    'temperature' => 0.7
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

$result = json_decode($response, true);
echo $result['choices'][0]['text'];

?>

Go

go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

type CompletionRequest struct {
    Model       string  `json:"model"`
    Prompt      string  `json:"prompt"`
    MaxTokens   int     `json:"max_tokens"`
    Temperature float64 `json:"temperature"`
}

func main() {
    url := "https://api.pham89ai.com/v1/completions"
    
    payload := CompletionRequest{
        Model:       "llama3.1",
        Prompt:      "Explain quantum computing in simple terms",
        MaxTokens:   500,
        Temperature: 0.7,
    }
    
    jsonData, _ := json.Marshal(payload)
    
    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Authorization", "Bearer YOUR_SECRET_KEY")
    req.Header.Set("Content-Type", "application/json")
    
    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()
    
    var result map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&result)
    
    choices := result["choices"].([]interface{})
    choice := choices[0].(map[string]interface{})
    fmt.Println(choice["text"])
}

Ruby

ruby
require 'net/http'
require 'json'

url = URI('https://api.pham89ai.com/v1/completions')

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request['Authorization'] = 'Bearer YOUR_SECRET_KEY'
request['Content-Type'] = 'application/json'

request.body = {
  model: 'llama3.1',
  prompt: 'Explain quantum computing in simple terms',
  max_tokens: 500,
  temperature: 0.7
}.to_json

response = http.request(request)
result = JSON.parse(response.body)

puts result['choices'][0]['text']

Available Models

Pham 89 AI supports 100+ AI models. Here are some popular options:

  • llama3.1 - Meta's latest Llama model, great for general tasks
  • deepseek-v3 - Powerful reasoning and coding capabilities
  • qwen3 - Excellent for multilingual tasks
  • mistral - Fast and efficient for most use cases
  • gemma3 - Google's open model with strong performance
  • phi4 - Microsoft's compact but capable model
  • codellama - Specialized for code generation
  • mixtral - Mixture-of-experts model for complex tasks

For a complete list of available models, visit the All Models page.

Error Handling

The API uses standard HTTP response codes to indicate success or failure:

Status Code Description
200 Success - Request completed successfully
401 Unauthorized - Invalid or missing API key
400 Bad Request - Invalid request parameters
429 Rate Limit - Too many requests
500 Server Error - Something went wrong on our end

Error Response Format

JSON
{
  "error": {
    "message": "Invalid API key provided",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}

Best Practices

Security

  • Store your API key securely using environment variables
  • Never commit API keys to version control
  • Use server-side API calls, not client-side JavaScript
  • Rotate your API keys regularly

Performance

  • Implement retry logic with exponential backoff for failed requests
  • Cache responses when appropriate to reduce API calls
  • Use streaming for long-form content generation
  • Choose the most appropriate model for your use case
✓ Pro Tip: Start with a lower temperature (0.3-0.5) for more deterministic outputs, and increase it (0.7-1.0) for more creative responses.

Need Help?

If you have questions or need assistance with the API, our support team is here to help: