API Documentation

Comprehensive guide to integrating with the SpaceAI. Learn how to authenticate, make requests, and handle responses.

Authentication

Permalink

All API requests require authentication using your API key. Include it in the Authorization header.

POST /v1/chat/completions
curl https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Important: Never expose your API keys in client-side code. Always keep them secure on your server.

Available Models

Permalink

Our API provides access to several state-of-the-art AI models. Each has different capabilities and pricing.

GET /v1/models
curl https://api.example.com/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"
{
  "object": "list",
  "data": [
    {
      "id": "gpt-4o",
      "object": "model",
      "created": 1677858242,
      "owned_by": "openai-internal",
      "capabilities": ["chat", "completions"],
      "pricing": {
        "input": 0.00003,
        "output": 0.00006
      }
    },
    {
      "id": "claude-3.5-sonnet",
      "object": "model",
      "created": 1677858242,
      "owned_by": "anthropic",
      "capabilities": ["chat"],
      "pricing": {
        "input": 0.00002,
        "output": 0.00005
      }
    }
  ]
}
{
  "type": "object",
  "properties": {
    "object": { "type": "string", "enum": ["list"] },
    "data": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string", "enum": ["model"] },
          "created": { "type": "integer" },
          "owned_by": { "type": "string" },
          "capabilities": {
            "type": "array",
            "items": { "type": "string" }
          },
          "pricing": {
            "type": "object",
            "properties": {
              "input": { "type": "number" },
              "output": { "type": "number" }
            }
          }
        }
      }
    }
  }
}

Model Comparison

Model Provider Capabilities Input ($/1K tokens) Output ($/1K tokens)
GPT-4o OpenAI Chat, Completions $0.03 $0.06
Claude 3.5 Sonnet Anthropic Chat $0.02 $0.05
Claude 3.7 Sonnet Anthropic Chat $0.05 $0.10

Chat Completions

Permalink

The chat completions endpoint powers conversational applications. It takes a series of messages and returns a model-generated message.

POST /v1/chat/completions
curl https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ],
    "temperature": 0.7,
    "max_tokens": 150
  }'
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 7,
    "total_tokens": 32
  }
}
{
  "type": "object",
  "properties": {
    "id": { "type": "string" },
    "object": { "type": "string", "enum": ["chat.completion"] },
    "created": { "type": "integer" },
    "model": { "type": "string" },
    "choices": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "index": { "type": "integer" },
          "message": {
            "type": "object",
            "properties": {
              "role": { "type": "string", "enum": ["assistant"] },
              "content": { "type": "string" }
            }
          },
          "finish_reason": { "type": "string" }
        }
      }
    },
    "usage": {
      "type": "object",
      "properties": {
        "prompt_tokens": { "type": "integer" },
        "completion_tokens": { "type": "integer" },
        "total_tokens": { "type": "integer" }
      }
    }
  }
}

Parameters

Parameter Type Required Description
model string Yes ID of the model to use
messages array Yes Array of message objects with role and content
temperature number No Controls randomness (0-2, default 0.7)
max_tokens integer No Maximum number of tokens to generate
stream boolean No Whether to stream partial results (default false)

API Playground

Permalink
POST /v1/chat/completions

Response

{{ playgroundResponse }}

Response will appear here after you send a request.

{{ playgroundError }}