Assistants API
The Assistants API is OpenAI's stateful API, where an assistant has instructions and tools, a thread holds a conversation, and runs execute the assistant on a thread. The gateway proxies the assistants, threads, messages and runs endpoints so that applications built on it authenticate with virtual keys, and every run is logged and costed. OpenAI and Azure OpenAI serve this API, and the gateway routes to the provider account configured in assistant_settings.
Scenario
A help desk application was built on the Assistants API with a file search tool over the product manuals. The company moves it behind the gateway so support agents use virtual keys with budgets instead of the shared provider key, and so every run appears in the Logs page. The application only changes its base URL.
Steps
-
Configure the provider account for assistants in
config.yamland restart the gateway.assistant_settings:custom_llm_provider: openaispanway_params:api_key: os.environ/OPENAI_API_KEYFor Azure OpenAI set
custom_llm_provider: azurewithapi_base,api_keyandapi_version. -
Create a key in Virtual Keys (
/ui/api-keys) with + Create New Key. -
Create an assistant, a thread, a message and a run.
curl -X POST http://localhost:4000/v1/assistants \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"model": "gpt-6.1-sol", "name": "Support helper", "instructions": "Answer support questions briefly.", "tools": [{"type": "file_search"}]}'curl -X POST http://localhost:4000/v1/threads \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"messages": [{"role": "user", "content": "How do I reset my password?"}]}'curl -X POST http://localhost:4000/v1/threads/thread_9e0f1a2b/messages \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"role": "user", "content": "How do I reset my password?"}'curl -X POST http://localhost:4000/v1/threads/thread_9e0f1a2b/runs \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"assistant_id": "asst_7c2d4e1f"}' -
Read the reply. Without
"stream": truethe run call waits until the run finishes and returns it with its finalstatus, so read the reply next withGET /v1/threads/{thread_id}/messages. To see the reply while it is produced, send"stream": truein the run call and read the server-sent events instead. The gateway has no route that reads a single run by id, so there is nothing to poll. -
Check the log. Open Logs (
/ui/logs). Each run is a row with its tokens and cost.
Expected result
The assistant call returns {"id": "asst_7c2d4e1f", "object": "assistant", "model": "gpt-6.1-sol", "name": "Support helper", ...}, the thread call returns {"id": "thread_9e0f1a2b", "object": "thread", ...}, the message call returns a thread.message object and the run call returns {"id": "run_5f6a7b8c", "object": "thread.run", "status": "completed", ...} once the run has finished. The thread's messages then contain the assistant's reply.
Endpoints
| Method | Path | Summary |
|---|---|---|
| GET | /v1/assistants | List assistants |
| POST | /v1/assistants | Create an assistant |
| DELETE | /v1/assistants/{assistant_id} | Delete an assistant |
| POST | /v1/threads | Create a thread |
| GET | /v1/threads/{thread_id} | Get a thread |
| GET | /v1/threads/{thread_id}/messages | List the messages of a thread |
| POST | /v1/threads/{thread_id}/messages | Add a message to a thread |
| POST | /v1/threads/{thread_id}/runs | Run an assistant on a thread |
Streaming runs return events when stream: true is set on the run.
Choosing between Assistants and Responses
The Responses API is the newer stateful API and works across many more providers on the gateway. Use the Assistants API for existing applications that depend on it, and the Responses API for new work.
Errors
| Status | What it means | Fix |
|---|---|---|
400 BadRequestError | model is missing on an assistant or assistant_id is missing on a run. | Send the field. |
400 Assistants are not configured on this gateway. Add an assistant_settings block with custom_llm_provider to config.yaml, ... | The gateway has no assistant_settings, so it does not know which provider account holds the assistants. | Add assistant_settings to config.yaml as in step 1 and restart. |
400 Spanway doesn't support <provider> for '<operation>'. Only 'openai' and 'azure' are supported. | assistant_settings.custom_llm_provider names a provider without the Assistants API. | Use openai or azure. |
400 This assistants request goes to the provider directly without a configured deployment, so the data policy (...) cannot be verified. ... | The key, team or organization has a data policy, and assistant calls go to the account in assistant_settings, which declares no data terms. | Use a key without a data policy for assistants, or use the Responses API with a deployment that declares its data terms. |
401 AuthenticationError | The virtual key is wrong, or the provider credential in assistant_settings is invalid. | Use a live key and check the credential. |
403 PermissionDeniedError | The key may not call assistant routes. | Use a key of type AI APIs or Full Access. |
404 NotFoundError | The assistant, thread or run id is unknown to the provider account. | Use ids returned through the same gateway. |
429 RateLimitError | Budget or rate limit reached, or the provider is throttling. | Raise the limit. |
Logs
Assistant calls write the same request lines as other inference routes, and a failure is logged as spanway.proxy.proxy_server.<route>(): Exception occured - <error> at ERROR, for example for create_assistant or run_thread. None for a 4xx the caller expected, check assistant_settings and the provider for anything else. Creating and deleting an assistant is written to the audit log as an assistant:<id> row. Threads, messages and runs are conversation data and appear only in the request logs.
Related
- Responses API for new stateful applications.
- Managed files for the files assistants search.
- Vector store files for file search indexes.
Providers
The gateway's endpoint support matrix marks 3 provider integrations as supporting this endpoint: