Programmatic access
Fireworks.ai offers a REST API that is OpenAPI-compatible for /completion
and /chat/completion
. There are several ways to interact with it:
- Recommended: Use the Fireworks Python client library
- Using LangChain
- Directly invoke the REST API using your favorite tools or language
- Use the OpenAI Python client
Fireworks Python client library
The Fireworks Python client library provides a convenient API for accessing Fireworks supported LLMs. See the API reference for a full description of the library.
Installation
Install with Pip:
pip install --upgrade fireworks-ai
Authentication
Generate an API key following the Quickstart instructions and set it in Python
import fireworks.client
fireworks.client.api_key = "<API_KEY>"
or provide as an environment variable
export FIREWORKS_API_KEY=<API_KEY>
Usage
Completion
completion = fireworks.client.Completion.create(
model="accounts/fireworks/models/llama-v2-7b-w8a16",
prompt="Say this is a test",
)
print(completion)
Async completion
import asyncio
async def main():
response = await fireworks.client.Completion.acreate(
model="accounts/fireworks/models/llama-v2-13b",
prompt="Once upon a time in an iterative fashion")
print(response.choices[0].text)
asyncio.run(main())
REST
The base URL for the REST endpoint is https://api.fireworks.ai/inference/v1
. You can view all available REST APIs and their options on the API reference page.
curl https://api.fireworks.ai/inference/v1/completions \
-H 'Authorization: Bearer <YOUR_API_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"model": "accounts/fireworks/models/llama-v2-7b-chat",
"prompt": "Hello there!"
}'
Updated about 1 month ago