Quick Start Guide
Get started with ObjectWeaver's API in minutes. This guide covers the basics and points you to detailed examples for advanced features.
Overview
ObjectWeaver provides a REST API for generating structured JSON objects with AI. Define your schema, and get back exactly the data you need.
Your First Request
Here's a simple example to get you started:
- cURL
- Python
- JavaScript/Node.js
- Go
curl -X POST http://localhost:2008/api/objectGen \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"prompt": "Create a technological landscape for a fantasy world",
"definition": {
"type": "object",
"instruction": "Defines the technological landscape of the world, including its level of advancement and notable innovations.",
"properties": {
"Level": {
"type": "string",
"instruction": "Categorize the overall technological sophistication of the world, such as medieval, industrial, or advanced futuristic."
},
"Inventions": {
"type": "string",
"instruction": "Describe the most significant technological discoveries and their transformative impact on the society, economy, and daily life."
}
}
}
}'
import requests
import json
url = "http://localhost:2008/api/objectGen"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
data = {
"prompt": "Create a technological landscape for a fantasy world",
"definition": {
"type": "object",
"instruction": "Defines the technological landscape of the world, including its level of advancement and notable innovations.",
"properties": {
"Level": {
"type": "string",
"instruction": "Categorize the overall technological sophistication of the world, such as medieval, industrial, or advanced futuristic."
},
"Inventions": {
"type": "string",
"instruction": "Describe the most significant technological discoveries and their transformative impact on the society, economy, and daily life."
}
}
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const fetch = require('node-fetch');
const url = 'http://localhost:2008/api/objectGen';
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
};
const data = {
prompt: 'Create a technological landscape for a fantasy world',
definition: {
type: 'object',
instruction: 'Defines the technological landscape of the world, including its level of advancement and notable innovations.',
properties: {
Level: {
type: 'string',
instruction: 'Categorize the overall technological sophistication of the world, such as medieval, industrial, or advanced futuristic.'
},
Inventions: {
type: 'string',
instruction: 'Describe the most significant technological discoveries and their transformative impact on the society, economy, and daily life.'
}
}
}
};
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Definition struct {
Type string `json:"type"`
Instruction string `json:"instruction"`
Properties map[string]interface{} `json:"properties"`
}
type RequestBody struct {
Prompt string `json:"prompt"`
Definition *Definition `json:"definition"`
}
func main() {
url := "http://localhost:2008/objectGen"
requestBody := RequestBody{
Prompt: "Create a technological landscape for a fantasy world",
Definition: &Definition{
Type: "object",
Instruction: "Defines the technological landscape of the world, including its level of advancement and notable innovations.",
Properties: map[string]interface{}{
"Level": map[string]string{
"type": "string",
"instruction": "Categorize the overall technological sophistication of the world, such as medieval, industrial, or advanced futuristic.",
},
"Inventions": map[string]string{
"type": "string",
"instruction": "Describe the most significant technological discoveries and their transformative impact on the society, economy, and daily life.",
},
},
},
}
jsonData, err := json.Marshal(requestBody)
if err != nil {
fmt.Printf("Error marshalling request: %v\n", err)
return
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
fmt.Printf("Error creating request: %v\n", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error sending request: %v\n", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response: %v\n", err)
return
}
fmt.Println(string(body))
}
Key Components
- Endpoint:
http://localhost:2008/objectGen - Method: POST
- Headers:
Content-Type: application/jsonAuthorization: Bearer YOUR_API_KEY
- Body: JSON definition with prompt and schema
tip
Replace YOUR_API_KEY with your actual API key before making the request.
Authentication
Include your API key in the Authorization header:
-H "Authorization: Bearer YOUR_API_KEY"
info
You can configure authentication in your ObjectWeaver instance. See the Docker Setup Guide for details.
Error Handling
ObjectWeaver returns standard HTTP status codes:
| Code | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad Request - Invalid schema or request |
| 401 | Unauthorized - Invalid or missing API key |
| 429 | Rate Limit Exceeded |
| 500 | Internal Server Error |
Getting Help
- Documentation: Explore detailed examples in the sidebar
- GitHub: github.com/ObjectWeaver/objectweaver
- Issues: Report bugs or request features on GitHub