Quick Start
Get started with Nextbit AI Platform in minutes. This guide will walk you through installation, authentication, and making your first API request.
Installation
First, install the OpenAI SDK for your preferred language. Our API is fully compatible with OpenAI's client libraries.
Python
Install OpenAI SDK
pip install openai
TypeScript/JavaScript
Install OpenAI SDK
npm install openai
# or
yarn add openai
# or
pnpm add openai
Authentication
To authenticate with the Nextbit API, you'll need an API key. Generate one from your API Keys dashboard.
Keep your API keys secure. Never expose them in client-side code or commit them to version control.
Setting Your API Key
Set API Key
export NEXTBIT_API_KEY="your-api-key-here"
First Request
Now let's make your first API request. We'll create a simple chat completion.
The following example shows how to create a basic chat completion using the OpenAI SDK configured to use Nextbit's API endpoint.
Key Configuration
- base_url: Set to
https://api.nextbit256.com/v1 - api_key: Your Nextbit API key
- model: Choose from available models (e.g.,
llama3.3:70b)
Chat Completion
from openai import OpenAI
import os
# Initialize client with Nextbit endpoint
client = OpenAI(
base_url="https://api.nextbit256.com/v1",
api_key=os.environ.get("NEXTBIT_API_KEY")
)
# Create chat completion
response = client.chat.completions.create(
model="llama3.3:70b",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."}
]
)
print(response.choices[0].message.content)
Streaming
For better user experience, you can stream responses token by token as they're generated.
Set stream=true to enable streaming. The response will be sent as server-sent events (SSE), with each chunk containing a portion of the completion.
Streaming Request
stream = client.chat.completions.create(
model="llama3.3:70b",
messages=[
{"role": "user", "content": "Write a haiku about AI"}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Error Handling
Always handle potential errors in your API requests:
Error Handling
from openai import OpenAI, APIError, RateLimitError
import os
client = OpenAI(
base_url="https://api.nextbit256.com/v1",
api_key=os.environ.get("NEXTBIT_API_KEY")
)
try:
response = client.chat.completions.create(
model="llama3.3:70b",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
except RateLimitError:
print("Rate limit exceeded. Please try again later.")
except APIError as e:
print(f"API error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Next Steps
Now that you've made your first request, explore more features:
- Chat Completions - Detailed API reference for chat completions
- Models - Explore available models and their capabilities
- Dashboard - Monitor your usage and manage billing
- API Keys - Create and manage API keys